Rspecを用いてテストを書いています。会員登録機能はsorceryというgemを使って実装したのですがテストがうまくかけませんでした。Twitterログインだけです。
ruby
1class OauthsController < ApplicationController 2 skip_before_action :require_login, raise: false 3 def oauth 4 login_at(params[:provider]) 5 end 6 7 def callback 8 provider = params[:provider] 9 if login_from(provider) 10 @user = login_from(provider) 11 redirect_to root_path, notice: "#{provider.titleize}でログインしました" 12 else 13 14 begin 15 @user = create_from(provider) 16 # NOTE: this is the place to add '@user.activate!' if you are using user_activation submodule 17 18 reset_session # protect from session fixation attack 19 auto_login(@user) 20 redirect_to root_path, notice: "#{provider.titleize}でログインしました" 21 rescue 22 redirect_to root_path, status: :unprocessable_entity 23 end 24 end 25 end 26end
request spec
ruby
1 describe 'GET /news' do 2 context 'ログインユーザー' do 3 before do 4 #ここでログインさせたい 5 # sign_in user 6 end 7 it 'status success' do 8 get new_news_path 9 expect(response).to have_http_status(200) 10 end 11 end 12 end 13end
ここでログインさせたく、spec/support以下にsign_inを実装してみたのですがうまくいきませんでした。sorceryのtest helperはTwitter loginに対応していないためダメです。
rspec上で sourceryを使っているアプリケーションで sign_in のテスト?を実装する方法はありませんか?
あなたの回答
tips
プレビュー