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

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:ininitialize’
#
/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:inwarden’
# /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

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

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… :-/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs