mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Update EmptyMatcher to use MatchData
This commit is contained in:
parent
be3218bcd8
commit
df663d30d9
2 changed files with 90 additions and 48 deletions
|
@ -1,13 +1,16 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Matchers::EmptyMatcher do
|
||||
describe "#match?" do
|
||||
describe "#match" do
|
||||
context "returned MatchData" do
|
||||
describe "#matched?" do
|
||||
context "with an empty set" do
|
||||
it "is true" do
|
||||
array = [] of Symbol
|
||||
partial = new_partial(array)
|
||||
matcher = Spectator::Matchers::EmptyMatcher.new
|
||||
matcher.match?(partial).should be_true
|
||||
match_data = matcher.match(partial)
|
||||
match_data.matched?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -16,7 +19,30 @@ describe Spectator::Matchers::EmptyMatcher do
|
|||
array = %i[a b c]
|
||||
partial = new_partial(array)
|
||||
matcher = Spectator::Matchers::EmptyMatcher.new
|
||||
matcher.match?(partial).should be_false
|
||||
match_data = matcher.match(partial)
|
||||
match_data.matched?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#values" do
|
||||
context "expected" do
|
||||
it "is an empty set" do
|
||||
array = %i[a b c]
|
||||
partial = new_partial(array)
|
||||
matcher = Spectator::Matchers::EmptyMatcher.new
|
||||
match_data = matcher.match(partial)
|
||||
match_data.values[:expected].size.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "actual" do
|
||||
it "is the actual set" do
|
||||
array = %i[a b c]
|
||||
partial = new_partial(array)
|
||||
matcher = Spectator::Matchers::EmptyMatcher.new
|
||||
match_data = matcher.match(partial)
|
||||
match_data.values[:actual].should eq(array)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -27,7 +53,8 @@ describe Spectator::Matchers::EmptyMatcher do
|
|||
label = "everything"
|
||||
partial = new_partial(array, label)
|
||||
matcher = Spectator::Matchers::EmptyMatcher.new
|
||||
matcher.message(partial).should contain(label)
|
||||
match_data = matcher.match(partial)
|
||||
match_data.message.should contain(label)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,7 +64,10 @@ describe Spectator::Matchers::EmptyMatcher do
|
|||
label = "everything"
|
||||
partial = new_partial(array, label)
|
||||
matcher = Spectator::Matchers::EmptyMatcher.new
|
||||
matcher.negated_message(partial).should contain(label)
|
||||
match_data = matcher.match(partial)
|
||||
match_data.negated_message.should contain(label)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,26 +11,38 @@ module Spectator::Matchers
|
|||
|
||||
# Determines whether the matcher is satisfied with the partial given to it.
|
||||
# `MatchData` is returned that contains information about the match.
|
||||
def match(partial) : MatchData
|
||||
raise NotImplementedError.new("#match")
|
||||
def match(partial)
|
||||
actual = partial.actual
|
||||
matched = actual.empty?
|
||||
MatchData.new(matched, actual, partial.label)
|
||||
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)
|
||||
partial.actual.empty?
|
||||
# Match data specific to this matcher.
|
||||
private struct MatchData(T) < MatchData
|
||||
# Creates the match data.
|
||||
def initialize(matched, @actual : T, @actual_label : String)
|
||||
super(matched)
|
||||
end
|
||||
|
||||
# Information about the match.
|
||||
def values
|
||||
{
|
||||
expected: [] of Nil,
|
||||
actual: @actual,
|
||||
}
|
||||
end
|
||||
|
||||
# Describes the condition that satisfies the matcher.
|
||||
# This is informational and displayed to the end-user.
|
||||
def message(partial)
|
||||
"Expected #{partial.label} to be empty"
|
||||
def message
|
||||
"#{@actual_label} is empty"
|
||||
end
|
||||
|
||||
# Describes the condition that won't satsify the matcher.
|
||||
# This is informational and displayed to the end-user.
|
||||
def negated_message(partial)
|
||||
"Expected #{partial.label} to not be empty"
|
||||
def negated_message
|
||||
"#{@actual_label} is not empty"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue