Add actual label to match data description

This commit is contained in:
Michael Miller 2021-08-19 11:46:07 -06:00
parent babc7ebc3a
commit 708fd692ae
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
18 changed files with 98 additions and 86 deletions

View file

@ -26,7 +26,7 @@ module Spectator::Matchers
match_data = matcher.match(element) match_data = matcher.match(element)
break match_data unless match_data.matched? break match_data unless match_data.matched?
end end
found || SuccessfulMatchData.new(description) found || SuccessfulMatchData.new(match_data_description(actual))
end end
# Negated matching for this matcher is not supported. # Negated matching for this matcher is not supported.

View file

@ -32,10 +32,10 @@ module Spectator::Matchers
if missing.empty? && extra.empty? if missing.empty? && extra.empty?
# Contents are identical. # Contents are identical.
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
# Content differs. # Content differs.
FailedMatchData.new(description, "#{actual.label} does not contain exactly #{expected.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} does not contain exactly #{expected.label}",
expected: expected_elements.inspect, expected: expected_elements.inspect,
actual: actual_elements.inspect, actual: actual_elements.inspect,
missing: missing.empty? ? "None" : missing.inspect, missing: missing.empty? ? "None" : missing.inspect,
@ -56,13 +56,13 @@ module Spectator::Matchers
if missing.empty? && extra.empty? if missing.empty? && extra.empty?
# Contents are identical. # Contents are identical.
FailedMatchData.new(description, "#{actual.label} contains exactly #{expected.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} contains exactly #{expected.label}",
expected: "Not #{expected_elements.inspect}", expected: "Not #{expected_elements.inspect}",
actual: actual_elements.inspect actual: actual_elements.inspect
) )
else else
# Content differs. # Content differs.
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end

View file

@ -28,9 +28,9 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value) snapshot = snapshot_values(actual.value)
if match?(snapshot) if match?(snapshot)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} does not have attributes #{expected.label}", values(snapshot).to_a) FailedMatchData.new(match_data_description(actual), "#{actual.label} does not have attributes #{expected.label}", values(snapshot).to_a)
end end
end end
@ -39,9 +39,9 @@ module Spectator::Matchers
def negated_match(actual : Expression(T)) : MatchData forall T def negated_match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value) snapshot = snapshot_values(actual.value)
if match?(snapshot) if match?(snapshot)
FailedMatchData.new(description, "#{actual.label} has attributes #{expected.label}", negated_values(snapshot).to_a) FailedMatchData.new(match_data_description(actual), "#{actual.label} has attributes #{expected.label}", negated_values(snapshot).to_a)
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end

View file

@ -30,21 +30,21 @@ module Spectator::Matchers
before, after = change(actual) before, after = change(actual)
if expected_before == before if expected_before == before
if before == after if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label}",
before: before.inspect, before: before.inspect,
after: after.inspect after: after.inspect
) )
elsif expected_after == after elsif expected_after == after
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label} to #{expected_after.inspect}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label} to #{expected_after.inspect}",
before: before.inspect, before: before.inspect,
after: after.inspect, after: after.inspect,
expected: expected_after.inspect expected: expected_after.inspect
) )
end end
else else
FailedMatchData.new(description, "#{expression.label} was not initially #{expected_before.inspect}", FailedMatchData.new(match_data_description(actual), "#{expression.label} was not initially #{expected_before.inspect}",
expected: expected_before.inspect, expected: expected_before.inspect,
actual: before.inspect, actual: before.inspect,
) )
@ -57,15 +57,15 @@ module Spectator::Matchers
before, after = change(actual) before, after = change(actual)
if expected_before == before if expected_before == before
if expected_after == after if expected_after == after
FailedMatchData.new(description, "#{actual.label} changed #{expression.label} from #{expected_before.inspect} to #{expected_after.inspect}", FailedMatchData.new(match_data_description(actual), "#{actual.label} changed #{expression.label} from #{expected_before.inspect} to #{expected_after.inspect}",
before: before.inspect, before: before.inspect,
after: after.inspect after: after.inspect
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
else else
FailedMatchData.new(description, "#{expression.label} was not initially #{expected_before.inspect}", FailedMatchData.new(match_data_description(actual), "#{expression.label} was not initially #{expected_before.inspect}",
expected: expected_before.inspect, expected: expected_before.inspect,
actual: before.inspect, actual: before.inspect,
) )

View file

@ -27,18 +27,18 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual) before, after = change(actual)
if expected != before if expected != before
FailedMatchData.new(description, "#{expression.label} was not initially #{expected}", FailedMatchData.new(match_data_description(actual), "#{expression.label} was not initially #{expected}",
expected: expected.inspect, expected: expected.inspect,
actual: before.inspect, actual: before.inspect,
) )
elsif before == after elsif before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label} from #{expected}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label} from #{expected}",
before: before.inspect, before: before.inspect,
after: after.inspect, after: after.inspect,
expected: "Not #{expected.inspect}" expected: "Not #{expected.inspect}"
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end
@ -47,14 +47,14 @@ module Spectator::Matchers
def negated_match(actual : Expression(T)) : MatchData forall T def negated_match(actual : Expression(T)) : MatchData forall T
before, after = change(actual) before, after = change(actual)
if expected != before if expected != before
FailedMatchData.new(description, "#{expression.label} was not initially #{expected}", FailedMatchData.new(match_data_description(actual), "#{expression.label} was not initially #{expected}",
expected: expected.inspect, expected: expected.inspect,
actual: before.inspect actual: before.inspect
) )
elsif before == after elsif before == after
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} changed #{expression.label} from #{expected}", FailedMatchData.new(match_data_description(actual), "#{actual.label} changed #{expression.label} from #{expected}",
before: before.inspect, before: before.inspect,
after: after.inspect, after: after.inspect,
expected: expected.inspect expected: expected.inspect

View file

@ -25,12 +25,12 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual) before, after = change(actual)
if before == after if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label}",
before: before.inspect, before: before.inspect,
after: after.inspect after: after.inspect
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end
@ -39,9 +39,9 @@ module Spectator::Matchers
def negated_match(actual : Expression(T)) : MatchData forall T def negated_match(actual : Expression(T)) : MatchData forall T
before, after = change(actual) before, after = change(actual)
if before == after if before == after
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} changed #{expression.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} changed #{expression.label}",
before: before.inspect, before: before.inspect,
after: after.inspect after: after.inspect
) )

View file

@ -25,14 +25,14 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual) before, after = change(actual)
if before == after if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label}",
before: before.inspect, before: before.inspect,
after: after.inspect after: after.inspect
) )
elsif @evaluator.call(before, after) elsif @evaluator.call(before, after)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label} #{@relativity}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label} #{@relativity}",
before: before.inspect, before: before.inspect,
after: after.inspect after: after.inspect
) )

View file

@ -27,15 +27,15 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual) before, after = change(actual)
if before == after if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label}",
before: before.inspect, before: before.inspect,
after: after.inspect, after: after.inspect,
expected: expected.inspect expected: expected.inspect
) )
elsif expected == after elsif expected == after
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label} to #{expected}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not change #{expression.label} to #{expected}",
before: before.inspect, before: before.inspect,
after: after.inspect, after: after.inspect,
expected: expected.inspect expected: expected.inspect

View file

@ -29,10 +29,10 @@ module Spectator::Matchers
if missing.empty? if missing.empty?
# Contents are present. # Contents are present.
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
# Content is missing. # Content is missing.
FailedMatchData.new(description, "#{actual.label} does not contain #{expected.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} does not contain #{expected.label}",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: actual_value.inspect, actual: actual_value.inspect,
missing: missing.inspect, missing: missing.inspect,
@ -52,13 +52,13 @@ module Spectator::Matchers
if satisfied if satisfied
# Contents are present. # Contents are present.
FailedMatchData.new(description, "#{actual.label} contains #{expected.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} contains #{expected.label}",
expected: "Not #{expected.value.inspect}", expected: "Not #{expected.value.inspect}",
actual: actual_value.inspect actual: actual_value.inspect
) )
else else
# Content is missing. # Content is missing.
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end

View file

@ -46,9 +46,9 @@ module Spectator::Matchers
# This method expects (and uses) the `#ends_with?` method on the value. # This method expects (and uses) the `#ends_with?` method on the value.
private def match_ends_with(actual_value, actual_label) private def match_ends_with(actual_value, actual_label)
if actual_value.ends_with?(expected.value) if actual_value.ends_with?(expected.value)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
FailedMatchData.new(description, "#{actual_label} does not end with #{expected.label} (using #ends_with?)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not end with #{expected.label} (using #ends_with?)",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: actual_value.inspect actual: actual_value.inspect
) )
@ -62,9 +62,9 @@ module Spectator::Matchers
last = list.last last = list.last
if expected.value === last if expected.value === last
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
FailedMatchData.new(description, "#{actual_label} does not end with #{expected.label} (using expected === last)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not end with #{expected.label} (using expected === last)",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: last.inspect, actual: last.inspect,
list: list.inspect list: list.inspect
@ -76,12 +76,12 @@ module Spectator::Matchers
# This method expects (and uses) the `#ends_with?` method on the value. # This method expects (and uses) the `#ends_with?` method on the value.
private def negated_match_ends_with(actual_value, actual_label) private def negated_match_ends_with(actual_value, actual_label)
if actual_value.ends_with?(expected.value) if actual_value.ends_with?(expected.value)
FailedMatchData.new(description, "#{actual_label} ends with #{expected.label} (using #ends_with?)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} ends with #{expected.label} (using #ends_with?)",
expected: "Not #{expected.value.inspect}", expected: "Not #{expected.value.inspect}",
actual: actual_value.inspect actual: actual_value.inspect
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
end end
end end
@ -92,13 +92,13 @@ module Spectator::Matchers
last = list.last last = list.last
if expected.value === last if expected.value === last
FailedMatchData.new(description, "#{actual_label} ends with #{expected.label} (using expected === last)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} ends with #{expected.label} (using expected === last)",
expected: "Not #{expected.value.inspect}", expected: "Not #{expected.value.inspect}",
actual: last.inspect, actual: last.inspect,
list: list.inspect list: list.inspect
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
end end
end end
end end

View file

@ -33,16 +33,16 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
exception = capture_exception { actual.value } exception = capture_exception { actual.value }
if exception.nil? if exception.nil?
FailedMatchData.new(description, "#{actual.label} did not raise", expected: ExceptionType.inspect) FailedMatchData.new(match_data_description(actual), "#{actual.label} did not raise", expected: ExceptionType.inspect)
else else
if exception.is_a?(ExceptionType) if exception.is_a?(ExceptionType)
if (value = expected.value).nil? if (value = expected.value).nil?
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
if value === exception.message if value === exception.message
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} raised #{exception.class}, but the message is not #{expected.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} raised #{exception.class}, but the message is not #{expected.label}",
"expected type": ExceptionType.inspect, "expected type": ExceptionType.inspect,
"actual type": exception.class.inspect, "actual type": exception.class.inspect,
"expected message": value.inspect, "expected message": value.inspect,
@ -51,7 +51,7 @@ module Spectator::Matchers
end end
end end
else else
FailedMatchData.new(description, "#{actual.label} did not raise #{ExceptionType}", FailedMatchData.new(match_data_description(actual), "#{actual.label} did not raise #{ExceptionType}",
expected: ExceptionType.inspect, expected: ExceptionType.inspect,
actual: exception.class.inspect actual: exception.class.inspect
) )
@ -64,28 +64,28 @@ module Spectator::Matchers
def negated_match(actual : Expression(T)) : MatchData forall T def negated_match(actual : Expression(T)) : MatchData forall T
exception = capture_exception { actual.value } exception = capture_exception { actual.value }
if exception.nil? if exception.nil?
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
if exception.is_a?(ExceptionType) if exception.is_a?(ExceptionType)
if (value = expected.value).nil? if (value = expected.value).nil?
FailedMatchData.new(description, "#{actual.label} raised #{exception.class}", FailedMatchData.new(match_data_description(actual), "#{actual.label} raised #{exception.class}",
expected: "Not #{ExceptionType}", expected: "Not #{ExceptionType}",
actual: exception.class.inspect actual: exception.class.inspect
) )
else else
if value === exception.message if value === exception.message
FailedMatchData.new(description, "#{actual.label} raised #{exception.class} with message matching #{expected.label}", FailedMatchData.new(match_data_description(actual), "#{actual.label} raised #{exception.class} with message matching #{expected.label}",
"expected type": ExceptionType.inspect, "expected type": ExceptionType.inspect,
"actual type": exception.class.inspect, "actual type": exception.class.inspect,
"expected message": value.inspect, "expected message": value.inspect,
"actual message": exception.message.to_s "actual message": exception.message.to_s
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end
end end

View file

@ -39,10 +39,10 @@ module Spectator::Matchers
if missing.empty? if missing.empty?
# Contents are present. # Contents are present.
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
# Content is missing. # Content is missing.
FailedMatchData.new(description, "#{actual_label} does not have #{expected.label}", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not have #{expected.label}",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: actual_value.inspect, actual: actual_value.inspect,
missing: missing.inspect, missing: missing.inspect,
@ -58,9 +58,9 @@ module Spectator::Matchers
end end
if missing.empty? if missing.empty?
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
FailedMatchData.new(description, "#{actual_label} does not have #{expected.label}", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not have #{expected.label}",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: actual_value.inspect, actual: actual_value.inspect,
missing: missing.inspect, missing: missing.inspect,
@ -89,13 +89,13 @@ module Spectator::Matchers
if satisfied if satisfied
# Contents are present. # Contents are present.
FailedMatchData.new(description, "#{actual_label} has #{expected.label}", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} has #{expected.label}",
expected: "Not #{expected.value.inspect}", expected: "Not #{expected.value.inspect}",
actual: actual_value.inspect actual: actual_value.inspect
) )
else else
# Content is missing. # Content is missing.
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
end end
end end
@ -107,9 +107,9 @@ module Spectator::Matchers
end end
if satisfied if satisfied
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
FailedMatchData.new(description, "#{actual_label} does not have #{expected.label}", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not have #{expected.label}",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: actual_value.inspect, actual: actual_value.inspect,
missing: missing.inspect, missing: missing.inspect,

View file

@ -21,5 +21,17 @@ module Spectator::Matchers
# Performs the test against the expression (value or block), but inverted. # Performs the test against the expression (value or block), but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa. # A successful match with `#match` should normally fail for this method, and vice-versa.
abstract def negated_match(actual : Expression(T)) : MatchData forall T abstract def negated_match(actual : Expression(T)) : MatchData forall T
private def match_data_description(actual : Expression(T)) : String forall T
match_data_description(actual.label)
end
private def match_data_description(actual_label : String | Symbol) : String
"#{actual_label} #{description}"
end
private def match_data_description(actual_label : Nil) : String
description
end
end end
end end

View file

@ -24,9 +24,9 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value) snapshot = snapshot_values(actual.value)
if match?(snapshot) if match?(snapshot)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} is not #{expected.label}", values(snapshot).to_a) FailedMatchData.new(match_data_description(actual), "#{actual.label} is not #{expected.label}", values(snapshot).to_a)
end end
end end
@ -35,9 +35,9 @@ module Spectator::Matchers
def negated_match(actual : Expression(T)) : MatchData forall T def negated_match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value) snapshot = snapshot_values(actual.value)
if match?(snapshot) if match?(snapshot)
FailedMatchData.new(description, "#{actual.label} is #{expected.label}", values(snapshot).to_a) FailedMatchData.new(match_data_description(actual), "#{actual.label} is #{expected.label}", values(snapshot).to_a)
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end

View file

@ -17,9 +17,9 @@ module Spectator::Matchers
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value) snapshot = snapshot_values(actual.value)
if snapshot.values.all? if snapshot.values.all?
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} does not respond to #{label}", values(snapshot).to_a) FailedMatchData.new(match_data_description(actual), "#{actual.label} does not respond to #{label}", values(snapshot).to_a)
end end
end end
@ -29,9 +29,9 @@ module Spectator::Matchers
snapshot = snapshot_values(actual.value) snapshot = snapshot_values(actual.value)
# Intentionally check truthiness of each value. # Intentionally check truthiness of each value.
if snapshot.values.any? # ameba:disable Performance/AnyInsteadOfEmpty if snapshot.values.any? # ameba:disable Performance/AnyInsteadOfEmpty
FailedMatchData.new(description, "#{actual.label} responds to #{label}", values(snapshot).to_a) FailedMatchData.new(match_data_description(actual), "#{actual.label} responds to #{label}", values(snapshot).to_a)
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end

View file

@ -25,9 +25,9 @@ module Spectator::Matchers
# Additionally, `#failure_message` and `#values` are called for a failed match. # Additionally, `#failure_message` and `#values` are called for a failed match.
def match(actual : Expression(T)) : MatchData forall T def match(actual : Expression(T)) : MatchData forall T
if match?(actual) if match?(actual)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, failure_message(actual), values(actual).to_a) FailedMatchData.new(match_data_description(actual), failure_message(actual), values(actual).to_a)
end end
end end
@ -41,9 +41,9 @@ module Spectator::Matchers
def negated_match(actual : Expression(T)) : MatchData forall T def negated_match(actual : Expression(T)) : MatchData forall T
# TODO: Invert description. # TODO: Invert description.
if does_not_match?(actual) if does_not_match?(actual)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, failure_message_when_negated(actual), negated_values(actual).to_a) FailedMatchData.new(match_data_description(actual), failure_message_when_negated(actual), negated_values(actual).to_a)
end end
end end

View file

@ -45,9 +45,9 @@ module Spectator::Matchers
# This method expects (and uses) the `#starts_with?` method on the value. # This method expects (and uses) the `#starts_with?` method on the value.
private def match_starts_with(actual_value, actual_label) private def match_starts_with(actual_value, actual_label)
if actual_value.starts_with?(expected.value) if actual_value.starts_with?(expected.value)
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
FailedMatchData.new(description, "#{actual_label} does not start with #{expected.label} (using #starts_with?)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not start with #{expected.label} (using #starts_with?)",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: actual_value.inspect actual: actual_value.inspect
) )
@ -61,9 +61,9 @@ module Spectator::Matchers
first = list.first first = list.first
if expected.value === first if expected.value === first
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
else else
FailedMatchData.new(description, "#{actual_label} does not start with #{expected.label} (using expected === first)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} does not start with #{expected.label} (using expected === first)",
expected: expected.value.inspect, expected: expected.value.inspect,
actual: first.inspect, actual: first.inspect,
list: list.inspect list: list.inspect
@ -75,12 +75,12 @@ module Spectator::Matchers
# This method expects (and uses) the `#starts_with?` method on the value. # This method expects (and uses) the `#starts_with?` method on the value.
private def negated_match_starts_with(actual_value, actual_label) private def negated_match_starts_with(actual_value, actual_label)
if actual_value.starts_with?(expected.value) if actual_value.starts_with?(expected.value)
FailedMatchData.new(description, "#{actual_label} starts with #{expected.label} (using #starts_with?)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} starts with #{expected.label} (using #starts_with?)",
expected: "Not #{expected.value.inspect}", expected: "Not #{expected.value.inspect}",
actual: actual_value.inspect actual: actual_value.inspect
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
end end
end end
@ -91,13 +91,13 @@ module Spectator::Matchers
first = list.first first = list.first
if expected.value === first if expected.value === first
FailedMatchData.new(description, "#{actual_label} starts with #{expected.label} (using expected === first)", FailedMatchData.new(match_data_description(actual_label), "#{actual_label} starts with #{expected.label} (using expected === first)",
expected: "Not #{expected.value.inspect}", expected: "Not #{expected.value.inspect}",
actual: first.inspect, actual: first.inspect,
list: list.inspect list: list.inspect
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual_label))
end end
end end
end end

View file

@ -28,9 +28,9 @@ module Spectator::Matchers
missing, extra = array_diff(expected_elements, actual_elements) missing, extra = array_diff(expected_elements, actual_elements)
if missing.empty? && extra.empty? if missing.empty? && extra.empty?
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
else else
FailedMatchData.new(description, "#{actual.label} does not contain #{expected.label} (unordered)", FailedMatchData.new(match_data_description(actual), "#{actual.label} does not contain #{expected.label} (unordered)",
expected: expected_elements.inspect, expected: expected_elements.inspect,
actual: actual_elements.inspect, actual: actual_elements.inspect,
missing: missing.inspect, missing: missing.inspect,
@ -50,12 +50,12 @@ module Spectator::Matchers
missing, extra = array_diff(expected_elements, actual_elements) missing, extra = array_diff(expected_elements, actual_elements)
if missing.empty? && extra.empty? if missing.empty? && extra.empty?
FailedMatchData.new(description, "#{actual.label} contains #{expected.label} (unordered)", FailedMatchData.new(match_data_description(actual), "#{actual.label} contains #{expected.label} (unordered)",
expected: "Not #{expected_elements.inspect}", expected: "Not #{expected_elements.inspect}",
actual: actual_elements.inspect, actual: actual_elements.inspect,
) )
else else
SuccessfulMatchData.new(description) SuccessfulMatchData.new(match_data_description(actual))
end end
end end