これは、テストなしで採用された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'
})
そして私のspec/Integration / login_specで:
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 Example"}}
F
失敗:
1)ServicesController OmniAuthは、セッション変数をOmniAuth認証ハッシュに設定します失敗/エラー:request.env ["omniauth.auth"] = OmniAuth.config.mock_auth [:facebook] NoMethodError:未定義のメソッド
env' for nil:NilClass # ./login_spec.rb:8:in
ブロック(2レベル)'22.06秒で終了1例、1失敗
失敗した例:
rspec ./login_spec.rb:11#ServicesController OmniAuthは、セッション変数をOmniAuth認証ハッシュに設定します
デフォルトでは、リクエストオブジェクトをここで使用できるようにする必要がありますか?このエラーはおそらく他の何かを意味しますか?
どうも