mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
TruthyMatcher doesn't need to store a label
Extend from Matcher instead of ValueMatcher to bypass storing the label. The "expected" value is still used, but is renamed to "truthy" and used for the label.
This commit is contained in:
parent
226708cb82
commit
f3e50c6432
1 changed files with 8 additions and 4 deletions
|
@ -8,19 +8,23 @@ module Spectator::Matchers
|
|||
#
|
||||
# Additionally, different matchers can be created
|
||||
# by using the `#<`, `#<=`, `#>`, `#>=`, `#==`, and `#!=` operators.
|
||||
struct TruthyMatcher < ValueMatcher(Bool)
|
||||
struct TruthyMatcher < Matcher
|
||||
# Creates the truthy matcher.
|
||||
# The *truthy* argument should be true to match "truthy" values,
|
||||
# and false to match "falsey" values.
|
||||
def initialize(truthy : Bool)
|
||||
super(truthy ? "truthy" : "falsey", truthy)
|
||||
def initialize(@truthy : Bool)
|
||||
end
|
||||
|
||||
# Textual representation of what the matcher expects.
|
||||
def label
|
||||
@truthy ? "truthy" : "falsey"
|
||||
end
|
||||
|
||||
# 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)
|
||||
# Cast value to truthy value and compare.
|
||||
@expected == !!partial.actual
|
||||
@truthy == !!partial.actual
|
||||
end
|
||||
|
||||
# Determines whether the matcher is satisfied with the partial given to it.
|
||||
|
|
Loading…
Reference in a new issue