这是一个没有测试的被采用的 Rails 应用程序。我正在尝试在集成测试中测试omniauth,但出现错误(我基于此进行编辑: https ://github.com/intridea/omniauth/wiki/Integration-Testing )。这反映了我对Rspec缺乏了解。看起来请求对象默认是可用的。
我在我的 spec/spec_helper.rb 中有:
config.include IntegrationSpecHelper, :type => :request
Capybara.default_host = 'http://localhost:3000'
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {
:uid => '12345'
})
在我的规范/集成/登录规范中:
require 'spec_helper'
describe ServicesController, "OmniAuth" do
before do
puts OmniAuth.config.mock_auth[:facebook]
puts request # comes back blank
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
end
it "sets a session variable to the OmniAuth auth hash" do
request.env["omniauth.auth"][:uid].should == '12345'
end
end
我收到以下错误:
{"provider"=>"facebook", "uid"=>"12345", "user_info"=>{"name"=>"Bob 示例"}}
F
失败:
1) ServicesController OmniAuth 将会话变量设置为 OmniAuth 身份验证哈希失败/错误:request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook] NoMethodError: undefined method
env' for nil:NilClass # ./login_spec.rb:8:in
block (2 levels) in '在 22.06 秒内完成 1 个示例,1 个失败
失败的例子:
rspec ./login_spec.rb:11 # ServicesController OmniAuth 将会话变量设置为 OmniAuth 身份验证哈希
默认情况下,请求对象是否应该在此处可用?这个错误可能意味着别的吗?
谢谢