Swap label and expected value parameters

This matches the partial initializer parameters.
Also cleaned up some code in the Expectation spec.
This commit is contained in:
Michael Miller 2019-02-28 15:17:12 -07:00
parent f3e50c6432
commit 5ba03a90ff
20 changed files with 74 additions and 110 deletions

View file

@ -47,19 +47,19 @@ module Spectator::Matchers
lower = center - diff
upper = center + diff
range = Range.new(lower, upper)
RangeMatcher.new("#{center} +/- #{label}", range)
RangeMatcher.new(range, "#{center} +/- #{label}")
end
# Returns a new matcher, with the same bounds, but uses an inclusive range.
def inclusive
range = Range.new(@expected.begin, @expected.end, exclusive: false)
RangeMatcher.new(label + " (inclusive)", range)
RangeMatcher.new(range, label + " (inclusive)")
end
# Returns a new matcher, with the same bounds, but uses an exclusive range.
def exclusive
range = Range.new(@expected.begin, @expected.end, exclusive: true)
RangeMatcher.new(label + " (exclusive)", range)
RangeMatcher.new(range, label + " (exclusive)")
end
end
end

View file

@ -17,14 +17,14 @@ module Spectator::Matchers
# Creates the value matcher.
# The label should be a string representation of the expectation.
# The expected value is stored for later use.
def initialize(@label : String, @expected : ExpectedType)
def initialize(@expected : ExpectedType, @label : String)
end
# Creates the value matcher.
# The label is generated by calling `#to_s` on the expected value.
# The expected value is stored for later use.
def initialize(expected : ExpectedType)
initialize(expected.to_s, expected)
initialize(expected, expected.to_s)
end
end
end