[rspec-users] Controller Testing + Devise = boom (undefined @controller, request)

Peter Ehrlich lists at ruby-forum.com
Sun Feb 6 01:18:30 EST 2011


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 modified 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

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


More information about the rspec-users mailing list