tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 195 forks source link

assert that string starts with a given string #119

Closed fredr closed 11 years ago

fredr commented 11 years ago

Added startWith() for asserting that a string starts with a given string.

travisjeffery commented 11 years ago

what's the use-case? when are you doing this often enough that it makes sense to not use '"foobar".should.match(/^foo/)

btd commented 11 years ago

Agreed @travisjeffery , i think we can close this.

fredr commented 11 years ago

Well, should.js is an expressive library for asserting, and imo 'http://www.example.com/something/something'.should.startWith('http://www.example.com') is more readable than doing a regexp.

But yes, it is possible to regexp matches that does the same thing. This PR is just a suggestion

gabrielf commented 11 years ago

I agree that startsWith('...') is more readable than using a regexp in many cases. Especially when looking for characters that must be escaped in a regexp such as:

someUrl.should.startWith('http://') compared to someUrl.should.match(/^http:\/\//)

btd commented 11 years ago

someUrl.should.startWith('http://') compared to someUrl.should.match(/^http:\/\//)

this definitely makes sense

travisjeffery commented 11 years ago

@gabrielf yeah that's a good use-case/example

fredr commented 11 years ago

@btd hmm, did I do something strange while merging here? or does the PR look ok?

btd commented 11 years ago

@travisjeffery looks ok for me, what do you think?

travisjeffery commented 11 years ago

Good, just wanted to squash those commits.

travisjeffery commented 11 years ago

Ayee, that boinked attribution. One sec.

fredr commented 11 years ago

:beers:

gabrielf commented 11 years ago

Nice!