[rspec-devel] have_text not doing a contains?

Corey Haines coreyhaines at gmail.com
Sat Mar 15 19:11:55 EDT 2008


I've created a ticket with my patch for include_text
http://rspec.lighthouseapp.com/projects/5645/tickets/343-include_text-matcher-and-updated-rdoc-for-have_text

I wasn't able to get the pre_commit tests passing, due to what I think is
the fact that I'm running on windows. I wrote specs for the matcher
(actually, changed the have_text specs), so I'm not 100% sure whether
everything is good.

Thanks.
-Corey

On Fri, Mar 14, 2008 at 11:25 AM, 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.
>
>
> -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
>



-- 
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/20080315/c845bcc0/attachment.html 


More information about the rspec-devel mailing list