[rspec-devel] have_text not doing a contains?

Corey Haines coreyhaines at gmail.com
Fri Mar 14 11:30:38 EDT 2008


Sounds good.

On Fri, Mar 14, 2008 at 11:27 AM, David Chelimsky <dchelimsky at gmail.com>
wrote:

> On Fri, Mar 14, 2008 at 3:25 PM, Corey Haines <coreyhaines at gmail.com>
> wrote:
> > We wrote a contain_text that does what I would like. I'd like to submit
> this
> > as a patch, then fix the documentation for have_text.
>
> Looking forward to it.
>
> Seeing as it's using #include under the hood, why don't you call it
> include text? That also aligns better w/ other bits in rspec.
>
> Cheers,
> David
>
> >
> >
> > -Corey
> >
> >
> >
> > On Fri, Mar 14, 2008 at 10:22 AM, David Chelimsky <dchelimsky at gmail.com>
> > wrote:
> >
> > >
> > >
> > >
> > > On Fri, Mar 14, 2008 at 11:28 AM, Corey Haines <coreyhaines at gmail.com>
> > wrote:
> > > > 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() 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.
> > >
> > > What you request makes great sense. But ....
> > >
> > > The only problem with adding this is that existing examples that use a
> > > String and expect an exact match (intentionally) would then give false
> > > positives if the string changed to something that included that
> > > String.
> > >
> > > My instinct is say "no go" here and improve the docs. Thoughts?
> > >
> > >
> > > >
> > > >
> > > > Thoughts?
> > > > -Corey
> > > >
> > > > --
> > > > http://www.coreyhaines.com
> > > > The Internet's Premiere source of information about Corey Haines
> > > > _______________________________________________
> > > >  rspec-devel mailing list
> > > >  rspec-devel at rubyforge.org
> > > >  http://rubyforge.org/mailman/listinfo/rspec-devel
> > > >
> > > _______________________________________________
> > > rspec-devel mailing list
> > > rspec-devel at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > >
> >
> >
> >
> > --
> >
> > http://www.coreyhaines.com
> > The Internet's Premiere source of information about Corey Haines
> > _______________________________________________
> >  rspec-devel mailing list
> >  rspec-devel at rubyforge.org
> >  http://rubyforge.org/mailman/listinfo/rspec-devel
> >
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>



-- 
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/a4c17bfe/attachment-0001.html 


More information about the rspec-devel mailing list