[rspec-devel] have_text not doing a contains?

Corey Haines coreyhaines at gmail.com
Fri Mar 14 07:28:09 EDT 2008

We were struggling with a story yesterday, trying to be able to write
something like

Then user should see message 'Blah blah blah blah'

Then("user should see message '$msg') do |expected_text|
response.should have_text(expected_text)

Our main problem was that the response was just a <p>Blah blah blah
blah</p>. It just would not pass. I decided to look at the matcher for
have_text, and this is what it is:

        def matches?(response_or_text)
          @actual = response_or_text.respond_to?(:body) ?
response_or_text.body : response_or_text
          return actual =~ expected if Regexp === expected
          return actual == expected unless Regexp === expected

Per the documentation,
Use this instead of response.should
() when you either don't know or don't care where on the page this text

So, my expectation was that this would do a String#include? or something
similar, rather than ==. Or, even, creating a regexp with the expected and
run it against actual.

Does this make sense? If so, I'd like to put in a ticket and take this
opportunity to learn how to submit a patch to rspec.

Also, I'd probably switch the code into something like

return (Regexp === expected) ? actual =~ expected : actual.include

But, of course, that's just personal style, as I think the if/unless in the
last two lines is duplicate intention.


The Internet's Premiere source of information about Corey Haines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20080314/62306ede/attachment.html 

More information about the rspec-devel mailing list