October 21, 2009

RSpec have_text vs include_text

The tutorial docs I’ve looked at don’t mention this, but there is a handy new test utility for your response objects.

response.should include_text("blah blah")

which tests to see if “blah blah” is anywhere on the page.

This compares favorably to

response.should have_text("blah blah")

which tests if the entire text of the page == “blah blah”

2 Comments »

  1. If you’re not using them yet, I’d strongly recommend looking at the webrat matchers for rspec. There is a contain matcher (response.should contain(“blah blah”)) that works like have_text, and the have_selector and have_xpath matchers are really expressive and powerful. That, and the rspec equivalents will likely be deprecated and removed when we release a rails-3 compatible version.

    Comment by David Chelimsky — October 23, 2009 @ 10:59 am

  2. Good to know, thanks!

    Comment by jb — October 30, 2009 @ 1:56 pm

RSS feed for comments on this post. | TrackBack URI
You can also bookmark this on del.icio.us or check the cosmos

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .