[Ruby] [Memorandum] Is () or {} after expect? (Module: RSpec::Matchers)

less than 1 minute read

Main story

A small personal note about the RSpec matcher format.

RSpec version

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

Is () or {} after expect?


The documentation for gem(rspec-expectations (3.9.2)) below lists the notations for each matcher on the Mathers page. Many examples are also posted. (#changeetc.)

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

misusing {..}'' forexpect(..).to be_xxx’’

This is the error message when (..) is written as {..} in the system spec file and the test is executed. It tells me that to use the be successful matcher, you have to pass an argument, not a block.

~~~rb: Error message example 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)>’