rspec-expectations icon indicating copy to clipboard operation
rspec-expectations copied to clipboard

Compound comparison matcher

Open SharkBeard opened this issue 6 years ago • 2 comments

Subject of the issue

There is no way to do compound comparisons in an expectation.

Steps to reproduce

expect(rand(5) + 1).to be(> 0).and be <= 6

Expected behavior

Test Pass

Actual behavior

unexpected '>'

SharkBeard avatar May 23 '20 19:05 SharkBeard

    expect(rand(5) + 1).to be.>(0).and be <= 6

worked quite fine:

  is expected to be > 0 and be <= 6

pirj avatar May 23 '20 20:05 pirj

Operators in Ruby are methods, so as @pirj points out there is a way to make this work, but you have the brackets in the wrong place to delegate operators, this also works (note the after to):

expect(rand(5) + 1).to (be > 0).and be <= 6

JonRowe avatar May 23 '20 21:05 JonRowe