Define A Custom RSpec Matcher
require 'rspec/expectations'
RSpec::Matchers.define :be_betwen do |lower, upper|
match do |operand|
expect(operand).to be >= lower
expect(operand).to be <= upper
end
end
describe MyThing do
it "has a value between 0 and 10" do
thing = MyThing.new
expect(thing.value).to be_between(0, 10)
end
endLast updated