0
0

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のstubで副作用を生み出したいとき

Posted at
allow(dbl).to receive(:foo) { do_something }
allow(dbl).to receive(:foo).with("args") { do_something }
allow(dbl).to receive(:foo).once { do_something }
allow(dbl).to receive(:foo).ordered { do_something }

do_somethingで何かをすればいい。
block の戻り値がそのstubの戻り値になるので、同時にand_returnは使えない。

参考: https://relishapp.com/rspec/rspec-mocks/v/3-8/docs/configuring-responses/block-implementation

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?