[rspec-users] [newbie] CSS navigation in controller response?

Fearless Fool lists at ruby-forum.com
Mon Jan 24 16:19:56 EST 2011

I'm hooked on RSpec after my first taste (thanks to
http://railstutorial.org/book/ruby-on-rails-tutorial).  And of course I
have a newbish question.

Assume a contrived doc structure like:

<table class="navbar">
     <td class="status">moribund</td>

Now lets say I want to write an RSpec controller test that will pass if
the status is "moribund" or "Moribund" or "MORIBUND".

I know I can write:

it "should be moribund" do
  get :show
  response.should have_selector("td", :class => "status", :content =>

... which captures the fact that the status string is inside a
"td.status" element, but is case sensitive.  Alternatively I could

it "should be moribund" do
  get :show
  response.body.should =~ /moribund/i

... which is case insensitive but doesn't discriminate where the string
appears in the document.

What's the right idiom to navigate to a specific place in a document
(preferably using CSS navigation syntax) AND perform a case-insensitive


- ff

P.S.: I fully appreciate that you shouldn't normally hardwire the
document structure into the test itself -- that's not what this question
is about! :)

P.P.S: I know that response is an ActionController::TestResponse object,
but haven't been able to find docs or sources for that -- where should I

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list