1
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?

Rspec のエラー - expected: 1 time with any arguments / received: 2 times with any arguments

Posted at

エラー例

expected: 1 time with any arguments
received: 2 times with any arguments

原因

1回だけのメソッド呼び出しを期待しているのに、2回呼び出されている

修正の例

- expect(SomeClass).to receive(:foo)
+ expect(SomeClass).to receive(:foo).at_least(:once)

注意

「1回以上呼び出される」という検証にしてしまうと、検証的にはゆるい
適切な回数分だけ呼び出されることを検証した方が確かだ

expect(SomeClass).to receive(:foo).exactly(2).times

参考

1
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
1
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?