http://qiita.com/mnishiguchi/items/3d6a4ec36c2237a11660
こちらのような記事を参考にして、omniauthのコントローラのテストを書きました。
Ruby
1require 'rails_helper' 2 3RSpec.describe Users::OmniauthCallbacksController, type: :controller do 4 include OmniauthUtils 5 let(:user) { build(:user) } 6 before { Rails.application.env_config["omniauth.params"] = {'user_type' => 'host'} } 7 8 context 'before signup' do 9 it 'can signup with facebook' do 10 set_omniauth('facebook_email@address.com') 11 visit user_facebook_omniauth_callback_path 12 expect(page).to have_selector 'div.alert', text: I18n.t('devise.omniauth_callbacks.success', kind: 'Facebook') 13 end 14 end 15end
すると
expected to find css "div.alert" with text "Successfully authenticated from Facebook account." but there were no matches. Also found "×Could not authent icate you from Facebook because \"No authorization code\".", which matched the selector but not all filters.
のようなエラーが出てしまいます。
authorization codeをどう設定すればいいのかわからず、
そもそも直接user_facebook_omniauth_callback_pathにアクセスするこのテストが正しいのかも怪しいです。わかる方がいらしたら教えていただきたいです。
追記:
Ruby
1 def set_omniauth(email) 2 OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({ 3 "provider" => "facebook", 4 "uid" => "#{email}", 5 "credentials" => { 6 "token" => "mock_credentials_token", 7 "secret" => "mock_credentials_secret" 8 } 9 }) 10 end 11 12def login(object) 13 @request.env['devise.mapping'] = Devise.mappings[object.class.name.underscore.to_sym] 14 sign_in object 15 end 16 17 def login_user 18 user = create(:user) 19 login(user) 20 user 21 end
あなたの回答
tips
プレビュー