[rspec-users] Controller Testing + Devise = boom (undefined @controller, request)
Rich Price
rich at gandalf.ws
Sun Feb 6 10:59:48 EST 2011
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
On 02/06/2011 12:18 AM, Peter Ehrlich wrote:
> 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
>
More information about the rspec-users
mailing list