我正在尝试使用OmniAuth和Devise编写一个使用twitter进行登录的集成测试。我无法获取要设置的请求变量。它在控制器测试中工作,但不是集成测试,这导致我认为我没有正确配置规范助手。我环顾四周,但我似乎无法找到一个可行的解决方案。以下是我迄今为止:Devise和OmniAuth twitter集成测试rspec
# spec/integrations/session_spec.rb
require 'spec_helper'
describe "signing in" do
before do
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]
visit new_user_session_path
click_link "Sign in with twitter"
end
it "should sign in the user with the authentication" do
(1+1).should == 3
end
end
该规范raies一个错误,才可以得到测试,我不太肯定要初始化的变量request
需求。错误是:
Failure/Error: request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]
NoMethodError:
undefined method `env' for nil:NilClass
现在我用的是request
变量在我的控制器规范和测试通过,但它没有被用于集成测试初始化。
# spec/spec_helper.rb
Dir[Rails.root.join("spec/support/*.rb")].each {|f| require f}
...
# spec/support/devise.rb
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
感谢您的帮助!