Starting to use rspec assertions with cucumber and I’ve got the doubt about which way to make string comparisons. I’ve tried the following 4 methods and all of them seem to produce the same result, so I was wondering if one of the methods is better over the others?
And, is it easy to explain the difference between the 4 methods? Maybe with an example?
page.first('div#navigation a').text.should == 'Radio')
page.first('div#navigation a').text.should eq('Radio')
page.first('div#navigation a').text.should match('Radio')
page.first('div#navigation a').text.should (be 'Radio')
Many thanks!!
For the string comparison you are doing,
==,eqand(be .)are basically the same.The
matchis pattern matching and will match partials, so would match bRadiosity which would not be true for the other methods if that was the whole text in theaanchor tage.g.
and
Note:
Personally I like
==the best for string comparison. Other folks prefer.eqlbecause it differs more from=(stands out more, less confusion). I may like==more as it sems a bit more portable across languages.