使用 Devise 进行控制器测试的问题
我在 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 => "[email protected]",: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 作为最后的手段。仍然无法工作:(
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 => "[email protected]",: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/rspec/rails/adapters.rb:11:in `block (2 levels) in setup'
I put the @request.env as a last resort. Still not working :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论