LoginSignup
0
0

More than 1 year has passed since last update.

What is Rspec | should_receive doing?

Last updated at Posted at 2019-04-16

should_receive verifies that a method of a certain class is called.

success

I expect SomeModel.create to be called.

 it do SomeModel.should_receive(:create) SomeModel.create end 

As an example, we call SomeModel.create right after here.

For example, in other methods. In the processing of the controller etc. It will succeed if SomeModel.create is called from anywhere or once.

Failure

It does not make sense to execute a method before should_receive.

 it do SomeModel.create SomeModel.should_receive(:create) end 

.with

.with verifies that the method is called with specific arguments.

Successful example

 it do SomeModel.should_receive(:create).with)(title: 'Bible') SomeModel.create(title: 'Bible') end 

Failure

 it do SomeModel.should_receive(:create).with)(title: 'Bible') SomeModel.create(title: 'Gone with the wind') end 

Supplement

Since should is old, newer versions should use expect. http://qiita.com/shuhei/items/58452ad1572b7e40c150

Original by

Rspec | should_receive は何をしている?

About

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
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
0
0