Merge branch 'fix-macro-syntax-error-in-be-between' into 'master'

Fix macro syntax error in be between

See merge request arctic-fox/spectator!26
This commit is contained in:
Mike Miller 2020-02-21 16:55:18 +00:00
commit 2ec9ab2e09
3 changed files with 21 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

@ -342,10 +342,10 @@ module Spectator
# expect(100).to be_between(97, 101).exclusive # 97, 98, 99, or 100 (not 101) # expect(100).to be_between(97, 101).exclusive # 97, 98, 99, or 100 (not 101)
# ``` # ```
macro be_between(min, max) macro be_between(min, max)
%range = Range.new({{min}}, {{max}})) %range = Range.new({{min}}, {{max}})
%label = [{{min.stringify}}, {{max.stringify}}].join(" to ") %label = [{{min.stringify}}, {{max.stringify}}].join(" to ")
%test_value = ::Spectator::TestValue.new(%range, %label) %test_value = ::Spectator::TestValue.new(%range, %label)
:Spectator::Matchers::RangeMatcher.new(%test_value) ::Spectator::Matchers::RangeMatcher.new(%test_value)
end end
# Indicates that some value should be within a delta of an expected value. # Indicates that some value should be within a delta of an expected value.

View file

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