Add greater-than matcher
This commit is contained in:
parent
52d0e6d55e
commit
ea6d7eac2a
|
@ -28,8 +28,8 @@ module Spectator::Matchers
|
||||||
# ```
|
# ```
|
||||||
# expect(2).to be > 1
|
# expect(2).to be > 1
|
||||||
# ```
|
# ```
|
||||||
def >(other : ExpectedType) forall ExpectedType
|
def >(expected : ExpectedType) forall ExpectedType
|
||||||
raise NotImplementedError.new("be >")
|
GreaterThanMatcher.new(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a matcher that checks if a value is greater than or equal to an expected value.
|
# Creates a matcher that checks if a value is greater than or equal to an expected value.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
require "./value_matcher"
|
||||||
|
|
||||||
|
module Spectator::Matchers
|
||||||
|
# Matcher that tests whether one value is greater than another.
|
||||||
|
# The values are compared with the `>` operator.
|
||||||
|
struct GreaterThanMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||||
|
# Determines whether the matcher is satisfied with the value given to it.
|
||||||
|
# True is returned if the match was successful, false otherwise.
|
||||||
|
def match?(partial : Expectations::ValueExpectationPartial(ActualType)) : Bool forall ActualType
|
||||||
|
partial.actual > expected
|
||||||
|
end
|
||||||
|
|
||||||
|
# Describes the condition that satisfies the matcher.
|
||||||
|
# This is informational and displayed to the end-user.
|
||||||
|
def message(partial : Expectations::ValueExpectationPartial(ActualType)) : String forall ActualType
|
||||||
|
"Expected #{partial.label} to be greater than #{label} (using >)"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Describes the condition that won't satsify the matcher.
|
||||||
|
# This is informational and displayed to the end-user.
|
||||||
|
def negated_message(partial : Expectations::ValueExpectationPartial(ActualType)) : String forall ActualType
|
||||||
|
"Expected #{partial.label} to not be greater than #{label} (using >)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue