Add test for fix, fix test for range_matcher

This commit is contained in:
Davide Paolo Tua 2020-02-21 13:19:27 +01:00
parent ce9bf918c1
commit 83ac420273
2 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,17 @@
require "../../spec_helper"
Spectator.describe "`be_between` matcher" do
context "basic usage" do
describe 7 do
it { is_expected.to be_between(1, 10) }
it { is_expected.to be_between(0.2, 27.1) }
it { is_expected.not_to be_between(1.5, 4) }
it { is_expected.not_to be_between(8, 9) }
# boundaries check
it { is_expected.to be_between(0, 7) }
it { is_expected.to be_between(7, 10) }
it { is_expected.not_to (be_between(0, 7).exclusive) }
end
end
end

View file

@ -13,13 +13,14 @@ module Spectator::Matchers
# Returns a new matcher, with the same bounds, but uses an inclusive range.
def inclusive
new_range = Range.new(range.begin, range.end, exclusive: false)
expected = TestValue.new(new_range, label)
label = expected.label
new_range = Range.new(range.begin, label)
RangeMatcher.new(expected)
end
# Returns a new matcher, with the same bounds, but uses an exclusive range.
def exclusive
label = expected.label
new_range = Range.new(range.begin, range.end, exclusive: true)
expected = TestValue.new(new_range, label)
RangeMatcher.new(expected)