My Rails 3.2アプリはOmniAuthとDeviseを使ってTwitterでサインインします。認証システムは正常に動作します。 rspecに統合テストを書いて、すべてが正しく動作することを確認したいと思います。 wikiの情報を使って、私は次のように書いていますが、私は物事を逃していることを知っています。設定/環境でのtest.rbの下Rails rspecとomniauth(統合テスト)
、私は次の行を持って
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = {:provider => 'twitter', :uid => '123545'}
私のRSpecのテストでは、次のようになります。
describe "Authentications" do
context "without signing into app" do
it "twitter sign in button should lead to twitter authentication page" do
visit root_path
click_link "Sign in with Twitter"
Authentication.last.uid.should == '123545'
end
end
end
認証は、私のモデルの名前であると.UID呼び出しますin rails consoleは文字列を返します。
私はこのテストを実行すると、私は次のエラーを取得しています:
Failure/Error: Authentication.last.uid.should == '123545'
NoMethodError:
undefined method `uid' for nil:NilClass
誰も私が提供されOmniAuthのモックを使用する方法を見つけ出す手助けすることはできますか? についての理由は、なぜとですか?と同様に動作します。
こんにちは!私はrequest.env ["omniauth.auth"]を試しましたが、 "nilクラス用の未定義メソッドenv"が表示されます – izumeroot
ここに正しい解決策がありますhttps://gist.github.com/kinopyo/1338738 – izumeroot