本編
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)>'