2
1

Rspecでanythingを使うとエラーになってしまう

Posted at

はじめに

Rspecでモックを使おうとしたところ時間がかかってしまった箇所があるので書いておきます

問題

テストの引数のチェックでanytingを利用しました

    Api.should_receive(:update_new_document).with(shortname, anything())

すると以下のエラーが発生します

Failures:
       (Api).update_new_document("A-00001", #<RSpec::Mocks::ArgumentMatchers::AnyArgMatcher:0x007faba8fb9658>)
           expected: 1 time
           received: 0 times
     # ./spec/jobs/update_all_worker_spec.rb:19:in `block (5 levels) in <top (required)>'

Finished in 2.68 seconds
1 example, 1 failure

解決方法

anything()にして解決しました

Api.should_receive(:update_new_document).with(shortname, anything())

おわりに

久しぶりにRspecをかいてますが昔を思い出します。楽しい

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