# Problem with unexpected nil in assert\_select

**URL:** <https://www.ruby-forum.com/t/problem-with-unexpected-nil-in-assert-select/194738>\
**Category:** Rails\
**Created:** [September 9, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/problem-with-unexpected-nil-in-assert-select/194738 "2010-09-09T18:35:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 9, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/problem-with-unexpected-nil-in-assert-select/194738/1 "2010-09-09T18:35:21Z")

</div>

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:

## To Proceed Please Authenticate Your Identity

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

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 10, 2010, 6:34pm UTC](https://www.ruby-forum.com/t/problem-with-unexpected-nil-in-assert-select/194738/2 "2010-09-10T18:34:09Z")

</div>

James B. 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:
> 
> ## To Proceed Please Authenticate Your Identity
> 
> 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.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 10, 2010, 8:12pm UTC](https://www.ruby-forum.com/t/problem-with-unexpected-nil-in-assert-select/194738/3 "2010-09-10T20:12:29Z")

</div>

James B. wrote:

> > The response.body inside the step definition contains exactly what I  
> > expect:
> > 
> > ## To Proceed Please Authenticate Your Identity
> > 
> > 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:

## To Proceed Please Authenticate Your Identity

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.  
 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?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 10, 2010, 8:55pm UTC](https://www.ruby-forum.com/t/problem-with-unexpected-nil-in-assert-select/194738/4 "2010-09-10T20:55:06Z")

</div>

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.
