1
1

More than 3 years have passed since last update.

[備忘録] expectの後ろは()か{}か。 (Module: RSpec::Matchers)

Last updated at Posted at 2020-08-12

本編

RSpecのマッチャの書式についての個人的な小メモです。

RSpecのバージョン

RSpec 3.9
  - rspec-core 3.9.2
  - rspec-expectations 3.9.2
  - rspec-mocks 3.9.1
  - rspec-rails 4.0.0.beta3
  - rspec-support 3.9.3

expectの後ろは(){}か?

結論

下記のgem(rspec-expectations (3.9.2))のドキュメントでMathersのページに各マッチャの記法が列挙されています。用例も多く掲載されています。(#changeなど)

Module: RSpec::Matchers — Documentation for rspec-expectations (3.9.2)

expect(..).to be_xxx{..}を誤用した例

実際にシステムスペックのファイル内で(..){..}と書いてテストを実行した場合のエラーメッセージです。
be successfulのマッチャを使用するには、ブロックではなく引数を渡さなければならないということは教えてくれています。

エラーメッセージ例
You must pass an argument rather than a block to `expect` to use the provided matcher (be successful), or the matcher must implement `supports_block_expectations?`.

# ./spec/system/doing_edit_spec.rb:11:in `block (2 levels) in <top (required)>'
1
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
1
1