# Controller Testing + Devise = boom (undefined @controller, request)

**URL:** <https://www.ruby-forum.com/t/controller-testing-devise-boom-undefined-controller-request/202794>\
**Category:** RSpec\
**Created:** [February 6, 2011, 7:18am UTC](https://www.ruby-forum.com/t/controller-testing-devise-boom-undefined-controller-request/202794 "2011-02-06T07:18:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 6, 2011, 7:18am UTC](https://www.ruby-forum.com/t/controller-testing-devise-boom-undefined-controller-request/202794/1 "2011-02-06T07:18:30Z")

</div>

Here I am, trying to learn TDD and BDD. Getting start, most simple  
case, and the world is falling apart:

My test code:

it “should respond with success” do  
puts ‘hi’

# get :new

# response.should be\_success

```
end

```

My stack trace:  
$ rspec spec  
“controller: nil”  
F

Failures:

1. VideosController new exposes request and response before and after  
the action  
Failure/Error: Unable to find matching line from backtrace  
NoMethodError:  
undefined method `request’ for nil:NilClass
# 

/Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active\_support/whiny\_nil.rb:48:in  
`method_missing' # /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:20:in`initialize’  
#  
/Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test\_helpers.rb:60:in  
`new' # /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/lib/devise/test_helpers.rb:60:in`warden’  
# /Users/peter/.rvm/gems/ruby-[/code]

You’ll notice it says controller: nil. I added a debugging line to the  
devise helper, as  
such:

class TestWarden \< Warden::Proxy #:nodoc:  
attr\_reader :controller

```
  def initialize(controller)
    @controller = controller
    manager = Warden::Manager.new(nil) do |config|
      config.merge! Devise.warden_config
    end
    p "controller: #{controller.inspect}"
    super(controller.request.env, manager)
  end

```

Thanks for any help!  
–Peter

---

<div class="post-metadata">

**Author:** ![peterbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc79bd/32.png) [@peterbe](https://www.ruby-forum.com/u/peterbe)\
**Post date:** [February 6, 2011, 5:59pm UTC](https://www.ruby-forum.com/t/controller-testing-devise-boom-undefined-controller-request/202794/2 "2011-02-06T17:59:29Z")

</div>

I am assuming that the get and response lines are not commented  
out in your actual test!

Does your code consist ONLY of the lines below?  
I think you need to proceed the “it” line with a “describe” line.  
for example:

describe “my test” do  
it “…” do  
_put other code here_  
end  
end

---

<div class="post-metadata">

**Author:** ![peterbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc79bd/32.png) [@peterbe](https://www.ruby-forum.com/u/peterbe)\
**Post date:** [February 6, 2011, 6:17pm UTC](https://www.ruby-forum.com/t/controller-testing-devise-boom-undefined-controller-request/202794/3 "2011-02-06T18:17:58Z")

</div>

My apologies! Yes, the describe is there. Here’s the whole file, with  
some other commented code (tests, before block) removed:

require ‘spec\_helper’

describe ‘VideosController’ do

describe ‘new’ do

```
it "should respond with success" do
  puts 'hi'

```

# get :new

# response.should be\_success

```
end

```

end

end

Really without understanding of what is going on under the hood… :-/
