Problem with Controller Testing using Devise
My first post on stackoverflow...Yeeh !. Anyways I'm trying to do a simple controller test for devise on Ruby 192 and Rails 3.0. I went through a lot of stuff on the web but I'm stuck. Please help me out. Here is the code snippet
require 'spec_helper'
require 'devise/test_helpers'
describe AttributeFunnel do
include Devise::TestHelpers
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:admin]
end
it "should restrict access" do
@user = Factory.build(:user, :email => "single@user.com",:password =>"abc123",:password_confirmation => "abc123" ,:agree_terms => 1)
@user.save(:validate => false)
@user.confirm!
sign_in(@user)
end
end
This is the error >>
NoMethodError: undefined method `request' for nil:NilClass
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.4/lib/active_support/whiny_nil.rb:48:in `method_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.2.rc/lib/devise/test_helpers.rb:27:in `initialize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.2.rc/lib/devise/test_helpers.rb:67:in `new'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.2.rc/lib/devise/test_helpers.rb:67:in `warden'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-rails-2.5.0/lib/rs开发者_Go百科pec/rails/adapters.rb:11:in `block (2 levels) in setup'
I put the @request.env as a last resort. Still not working :(
精彩评论