14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rspecでメソッドが呼ばれた/呼ばれてない事の検証

Last updated at Posted at 2018-10-29

rspec 3.7

allow receiveで監視対象をしっかり指定出来ていなかったり、地味にハマったので基本的な形を忘れないように。。。


describe 'Authenticate' do
  context 'twitter user' do
    let!(:user) { TwitterUser.new }
    before do
      allow(FacebookLoginService).to receive(:login)
      allow(TwitterLoginService).to receive(:login)
      AuthenticateService.execute(user)
    end
    it 'twitter login called once' do
      expect(TwitterLoginService).to have_received(:login).once # 1回呼ばれること
    end
    it 'facebook login is not called' do
      expect(FacebookLoginService).not_to have_received(:login) # 呼ばれないこと 
    end
  end
end

参考

14
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?