[rspec-users] AssertSelect for strings?

David Chelimsky dchelimsky at gmail.com
Fri Mar 9 11:10:39 EST 2007

That's a great idea, but AFAIK it is not supported by assert_select directly.

Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb.
This is a copy of the assert_select_test from the
assert_select_plugin, modified to fit into rspec.

It sets up a controller that you can use to render whatever text you
like, and set up specs like this:

  render_html %Q{ <p>foo</p> }
  response.should have_tag('p','foo')

There's no reason you shouldn't be able to do this:

  response.should have_tag('p','foo')

It's a bit sneaky, and perhaps too much work when you could just do:

  some_helper_method.should == "<p>foo</p>"

Check it out and let me know if you have any questions.


On 3/9/07, Tilmann Singer <tils-rspec at tils.net> wrote:
> Hi,
> Is there a way to use the have_tag matcher on a string instead of the
> response body from a view? I have a helper in a method rails project
> that returns an html fragment which I would like to test.
> Like this:
> module SomeHelper
>   def some_helper_method
>     "<p>foo</p>"
>   end
> end
> context "The SomeHelper"
>   helper_name :some
>   specify do
>     some_helper_method.should have_tag("p", "foo")
>   end
> end
> Til
> ps: the new have_tag / with_tag stuff for testing views and rspec
> 0.8.2 in general rocks, thanks to all involved!
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list