mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add inequality matcher
This commit is contained in:
parent
93801553b6
commit
d02e5d33b4
2 changed files with 27 additions and 2 deletions
|
@ -55,8 +55,8 @@ module Spectator::Matchers
|
|||
# ```
|
||||
# expect(0).to be != 1
|
||||
# ```
|
||||
def !=(other : ExpectedType) forall ExpectedType
|
||||
raise NotImplementedError.new("be !=")
|
||||
def !=(expected : ExpectedType) forall ExpectedType
|
||||
InequalityMatcher.new(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
25
src/spectator/matchers/inequality_matcher.cr
Normal file
25
src/spectator/matchers/inequality_matcher.cr
Normal file
|
@ -0,0 +1,25 @@
|
|||
require "./value_matcher"
|
||||
|
||||
module Spectator::Matchers
|
||||
# Matcher that tests whether two values do not equal each other.
|
||||
# The values are compared with the `!=` operator.
|
||||
struct InequalityMatcher(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 not equal #{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 equal #{label} (using !=)"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue