【发布时间】:2014-08-12 17:10:26
【问题描述】:
我将 rspec 从版本 2 升级到了 3。之后我遇到了这个问题:
Failures:
1) AlbumsController GET #edit
Failure/Error: sign_in_and_switch_schema @user
NoMethodError:
undefined method `env' for nil:NilClass
# ./spec/support/auth_helpers.rb:10:in `sign_in_and_switch_schema'
# ./spec/controllers/albums_controller_spec.rb:12:in `block (2 levels) in <top (required)>'
spec_helper.rb 包含:
RSpec.configure do |config|
# most omitted
config.include Warden::Test::Helpers
config.include Devise::TestHelpers, type: :controller
end
albums_controller_spec.rb:
describe AlbumsController do
let(:album) { create(:album) }
before(:all) do
@user = create :user
end
before(:each) do
sign_in_and_switch_schema @user
end
after(:all) do
destroy_users_schema @user
destroy_user @user
end
# describe's part omitted
end
auth_helpers.rb 发生错误的部分:
def sign_in_and_switch_schema(user)
# binding.pry
@request.env["devise.mapping"] = Devise.mappings[:user] # <- error line
sign_in :user, user
Apartment::Tenant.switch(user.username)
end
我一直在寻找另一个类似的问答,但没有发现任何帮助。让我知道是否应该包含更多内容。提前致谢。
【问题讨论】:
-
错误出现在spec/support/auth_helpers.rb的第10行的sign_in_and_switch_schema方法中你能显示那个文件的内容吗?
-
抱歉,我错过了 - Q 已更新
-
@mlainez:我在 auth_helpers.rb 中添加了
binding.pry。它清楚地表明@request是nil。我不知道我还能用它做什么,但我可以看看你是否告诉我。
标签: ruby-on-rails rspec devise rspec3