[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)
end

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
        end

Per the documentation,
Use this instead of response.should
have_tag<http://rspec.info/rdoc-rails/classes/Spec/Rails/Matchers.html#M000044>
() when you either don't know or don't care where on the page this text
appears.

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
?(expected)

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


Thoughts?
-Corey

-- 
http://www.coreyhaines.com
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