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

James Hughes hughes.james at gmail.com
Wed Feb 14 15:08:37 EST 2007


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.

Here's the respective stack traces for the example above:

    response.should have_tag("a[href*=users/edit/user?]", /\d/, {:text
=> "Edit"})
'Given a list with three users the users/list view should list some
users and provide an edit link for each' FAILED
textEdit
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations.rb:98:in
`fail_with'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/handler.rb:8:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/extensions/object.rb:18:in
`should'
./spec/views/users/list_view_spec.rb:49:
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/specification.rb:55:in
`execute_spec'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/specification.rb:30:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context.rb:58:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context.rb:55:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context_runner.rb:23:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context_runner.rb:22:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:27:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/bin/spec:4:
/usr/bin/spec:18:

and

    response.should have_tag("a[href*=users/edit/?]", /user\d/)
gives:
'Given a list with three users the users/list view should list some
users and provide an edit link for each' FAILED
Expected at least 1 <a[href*=users/edit/user?]> tag, found 0
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations.rb:98:in
`fail_with'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/handler.rb:8:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/extensions/object.rb:18:in
`should'
./spec/views/users/list_view_spec.rb:50:
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/specification.rb:55:in
`execute_spec'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/specification.rb:30:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context.rb:58:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context.rb:55:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context_runner.rb:23:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/context_runner.rb:22:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:27:in
`run'
/usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/bin/spec:4:
/usr/bin/spec:18:


More information about the rspec-devel mailing list