[rspec-devel] Will it be "response.should_have" or "response.body.should_have"?

David Chelimsky dchelimsky at gmail.com
Fri Feb 16 11:39:01 EST 2007


On 2/15/07, James Hughes <hughes.james at gmail.com> wrote:
> On 2/15/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> > On 2/14/07, James Hughes <hughes.james at gmail.com> wrote:
> > > On 2/13/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> > > > On 2/13/07, James Hughes <hughes.james at gmail.com> wrote:
> > > > > On 2/9/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> > > > > > The next release (coming soon) will do everything assert_select does
> > > > > > but with rspec syntax. Take a look at this:
> > > > > >
> > > > > > >http://blog.davidchelimsky.net/articles/2007/01/20/view-specs-are-about-to-get-a-whole-lot-easier
> > > > > >
> > > > >
> > > > > Thanks, David. assert_select supports using substitution values in
> > > > > selectors, eg.:
> > > > >
> > > > >   assert_select "ol>li#?", /item-\d+/
> > > > >
> > > > > Is there a way to do this with should have_tag?
> > > >
> > > > response.should have_tag("ol>li#?", /item-\d+/)
> > >
> > > That's what I've been trying, with the difference that I'm providing a
> > > hash as the third parameter:
> > >
> > >     response.should have_tag("a[href*=users/edit/user?]", /\d/, {:text
> > > => "Edit"})
> > >
> > > to test the contents of the tag. I'm just now noticing that the
> > > assert_select docs provide no examples like this so perhaps this isn't
> > > possible. However, I've also tried
> > >
> > >     response.should have_tag("a[href*=users/edit/?]", /user\d/)
> > >
> > > with no luck.
> >
> > James - would you mind adding this:
> >
> > puts response.body
> >
> > to your spec and showing us what actually gets rendered?
> >
>
> The relevant bit follows, but I got this to pass with the following syntax:
>
>     response.should have_tag("a[href=?]", /\/users\/edit\/user\d/)
> whereas
>
> #    response.should have_tag("a[href=/users/edit/user?]", /\d/)
>
> fails.
>
> I think there's  something subtle about the substitution operator (the
> '?') that I'm not understanding. It seems to only work in proximity to
> the "=", "#", and "." characters? I don't think this is really an
> rspec issue.

I think you're right - this is just how assert select works:
http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html

>From what I can tell...

# is for IDs
. is for classes
^, $ and * are for substring matching
? is for regexps

Thanks for following up.

Cheers,
David

>
> <td>example user 0</td>
>       <td>user0 at test.com</td>
>       <td>604-777-8888</td>
>       <td><a href="/users/edit/user0">Edit</a></td>
>     </tr>
>       <tr>
>       <td>example user 1</td>
>       <td>user1 at test.com</td>
>       <td>604-777-8888</td>
>       <td><a href="/users/edit/user1">Edit</a></td>
>     </tr>
>       <tr>
>       <td>example user 2</td>
>       <td>user2 at test.com</td>
>       <td>604-777-8888</td>
>       <td><a href="/users/edit/user2">Edit</a></td>
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list