Problem with unexpected nil in assert_select

I am running cucumber features against a Rails 3 branch and I have this step definition (which works fine in Rails-2.3.8):

When /should see (?:an|the) authentication request message/ do

  puts("This is the response: #{response.body}")

  selector = "#authentication_request"   expected = true   message = 'Missing authentication_request selector'

  assert_select(selector, expected, message)

end

Running the cucumber feature that invokes this step generates the following error:

      undefined method `content_type' for nil:NilClass (NoMethodError)       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-3.0.0/ lib/active_support/whiny_nil.rb:48:in `method_missing'       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/actionpack-3.0.0/ lib/action_dispatch/testing/assertions/selector.rb:605:in `response_from_page_or_rjs'       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/actionpack-3.0.0/ lib/action_dispatch/testing/assertions/selector.rb:213:in `assert_select'       /home/byrnejb/Software/Development/Projects/proforma.git/ features/app/models/users/step_definitions/ user_authentication_steps.rb:56

The response.body inside the step definition contains exactly what I expect:

  <h2 class="notice" id="authentication_request">      To Proceed Please Authenticate Your Identity   </h2>

What do I need to change to get this test to work in Rails-3.0.0?

James Byrne wrote:

Running the cucumber feature that invokes this step generates the following error:

      undefined method `content_type' for nil:NilClass (NoMethodError)       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-3.0.0/ lib/active_support/whiny_nil.rb:48:in `method_missing'       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/actionpack-3.0.0/ lib/action_dispatch/testing/assertions/selector.rb:605:in `response_from_page_or_rjs'       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/actionpack-3.0.0/ lib/action_dispatch/testing/assertions/selector.rb:213:in `assert_select'       /home/byrnejb/Software/Development/Projects/proforma.git/ features/app/models/users/step_definitions/ user_authentication_steps.rb:56

The response.body inside the step definition contains exactly what I expect:

  <h2 class="notice" id="authentication_request">      To Proceed Please Authenticate Your Identity   </h2>

What do I need to change to get this test to work in Rails-3.0.0?

Is there some place that lists the valid syntax for a css selector as used by ActionDispatch? I can only surmise that the argument value is invalid for some reason.

James Byrne wrote:

The response.body inside the step definition contains exactly what I expect:

  <h2 class="notice" id="authentication_request">      To Proceed Please Authenticate Your Identity   </h2>

What do I need to change to get this test to work in Rails-3.0.0?

Is there some place that lists the valid syntax for a css selector as used by ActionDispatch? I can only surmise that the argument value is invalid for some reason.

I removed webrat-0.7.2-beta and tried again. This eliminated the nil object error, so I infer that webrat caused this issue. However, the test still fails. Given this html:

<h2 class="notice" id="authentication_request"> To Proceed Please Authenticate Your Identity</h2>

and this assert_selector statement:

  expected = "#authorization_request"   message = 'Missing authentication_request selector'

  assert_select(expected, message)

I receive this error:

Expected at least 1 element matching "#authorization_request", found 0.    <false> is not true. (Test::Unit::AssertionFailedError)       /home/byrnejb/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/test/unit/assertions.rb:48:in `assert_block'

As far as I can tell from my references, #authorization_request is a valid css selector. So, why is this test failing in Rails-3?

I have determined that this is indeed a webrat problem. Evidently, webrat overrides assert_select in such a way as to break the Rails-3.0.0 implementation.