我在stackoverflow上的第一篇文章......是的!无论如何,我正在尝试在Ruby 192和Rails 3.0上进行简单的控制器测试。我在网上经历了很多东西但是我被卡住了。请帮帮我。 这是代码段
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
这是错误>>
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/rspec/rails/adapters.rb:11:in `block (2 levels) in setup'
我把@ request.env作为最后的手段。仍然没有工作:(