🖥
What is Rspec | should_receive doing?
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
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-04-16
Discussion