From 708fd692aec6546faed6ac752eea49eca907af36 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 19 Aug 2021 11:46:07 -0600 Subject: [PATCH] Add actual label to match data description --- src/spectator/matchers/all_matcher.cr | 2 +- src/spectator/matchers/array_matcher.cr | 8 ++++---- src/spectator/matchers/attributes_matcher.cr | 8 ++++---- .../matchers/change_exact_matcher.cr | 14 ++++++------- src/spectator/matchers/change_from_matcher.cr | 12 +++++------ src/spectator/matchers/change_matcher.cr | 8 ++++---- .../matchers/change_relative_matcher.cr | 6 +++--- src/spectator/matchers/change_to_matcher.cr | 6 +++--- src/spectator/matchers/contain_matcher.cr | 8 ++++---- src/spectator/matchers/end_with_matcher.cr | 16 +++++++-------- src/spectator/matchers/exception_matcher.cr | 20 +++++++++---------- src/spectator/matchers/have_matcher.cr | 16 +++++++-------- src/spectator/matchers/matcher.cr | 12 +++++++++++ src/spectator/matchers/predicate_matcher.cr | 8 ++++---- src/spectator/matchers/respond_matcher.cr | 8 ++++---- src/spectator/matchers/standard_matcher.cr | 8 ++++---- src/spectator/matchers/start_with_matcher.cr | 16 +++++++-------- .../matchers/unordered_array_matcher.cr | 8 ++++---- 18 files changed, 98 insertions(+), 86 deletions(-) diff --git a/src/spectator/matchers/all_matcher.cr b/src/spectator/matchers/all_matcher.cr index becefad..404b66d 100644 --- a/src/spectator/matchers/all_matcher.cr +++ b/src/spectator/matchers/all_matcher.cr @@ -26,7 +26,7 @@ module Spectator::Matchers match_data = matcher.match(element) break match_data unless match_data.matched? end - found || SuccessfulMatchData.new(description) + found || SuccessfulMatchData.new(match_data_description(actual)) end # Negated matching for this matcher is not supported. diff --git a/src/spectator/matchers/array_matcher.cr b/src/spectator/matchers/array_matcher.cr index bb355a3..6adf442 100644 --- a/src/spectator/matchers/array_matcher.cr +++ b/src/spectator/matchers/array_matcher.cr @@ -32,10 +32,10 @@ module Spectator::Matchers if missing.empty? && extra.empty? # Contents are identical. - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) else # 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, actual: actual_elements.inspect, missing: missing.empty? ? "None" : missing.inspect, @@ -56,13 +56,13 @@ module Spectator::Matchers if missing.empty? && extra.empty? # 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}", actual: actual_elements.inspect ) else # Content differs. - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end diff --git a/src/spectator/matchers/attributes_matcher.cr b/src/spectator/matchers/attributes_matcher.cr index 86349b4..30ddb38 100644 --- a/src/spectator/matchers/attributes_matcher.cr +++ b/src/spectator/matchers/attributes_matcher.cr @@ -28,9 +28,9 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if match?(snapshot) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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 @@ -39,9 +39,9 @@ module Spectator::Matchers def negated_match(actual : Expression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) 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 - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end diff --git a/src/spectator/matchers/change_exact_matcher.cr b/src/spectator/matchers/change_exact_matcher.cr index 94c391a..2f0880e 100644 --- a/src/spectator/matchers/change_exact_matcher.cr +++ b/src/spectator/matchers/change_exact_matcher.cr @@ -30,21 +30,21 @@ module Spectator::Matchers before, after = change(actual) if expected_before == before 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, after: after.inspect ) elsif expected_after == after - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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, after: after.inspect, expected: expected_after.inspect ) end 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, actual: before.inspect, ) @@ -57,15 +57,15 @@ module Spectator::Matchers before, after = change(actual) if expected_before == before 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, after: after.inspect ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end 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, actual: before.inspect, ) diff --git a/src/spectator/matchers/change_from_matcher.cr b/src/spectator/matchers/change_from_matcher.cr index cfbea50..e684e00 100644 --- a/src/spectator/matchers/change_from_matcher.cr +++ b/src/spectator/matchers/change_from_matcher.cr @@ -27,18 +27,18 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T before, after = change(actual) 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, actual: before.inspect, ) 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, after: after.inspect, expected: "Not #{expected.inspect}" ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end @@ -47,14 +47,14 @@ module Spectator::Matchers def negated_match(actual : Expression(T)) : MatchData forall T before, after = change(actual) 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, actual: before.inspect ) elsif before == after - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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, after: after.inspect, expected: expected.inspect diff --git a/src/spectator/matchers/change_matcher.cr b/src/spectator/matchers/change_matcher.cr index 1f60ac5..3be8111 100644 --- a/src/spectator/matchers/change_matcher.cr +++ b/src/spectator/matchers/change_matcher.cr @@ -25,12 +25,12 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T before, after = change(actual) 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, after: after.inspect ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end @@ -39,9 +39,9 @@ module Spectator::Matchers def negated_match(actual : Expression(T)) : MatchData forall T before, after = change(actual) if before == after - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) else - FailedMatchData.new(description, "#{actual.label} changed #{expression.label}", + FailedMatchData.new(match_data_description(actual), "#{actual.label} changed #{expression.label}", before: before.inspect, after: after.inspect ) diff --git a/src/spectator/matchers/change_relative_matcher.cr b/src/spectator/matchers/change_relative_matcher.cr index 539c971..8511dd4 100644 --- a/src/spectator/matchers/change_relative_matcher.cr +++ b/src/spectator/matchers/change_relative_matcher.cr @@ -25,14 +25,14 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T before, after = change(actual) 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, after: after.inspect ) elsif @evaluator.call(before, after) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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, after: after.inspect ) diff --git a/src/spectator/matchers/change_to_matcher.cr b/src/spectator/matchers/change_to_matcher.cr index 51504ec..57deff5 100644 --- a/src/spectator/matchers/change_to_matcher.cr +++ b/src/spectator/matchers/change_to_matcher.cr @@ -27,15 +27,15 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T before, after = change(actual) 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, after: after.inspect, expected: expected.inspect ) elsif expected == after - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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, after: after.inspect, expected: expected.inspect diff --git a/src/spectator/matchers/contain_matcher.cr b/src/spectator/matchers/contain_matcher.cr index fe21182..7ebe221 100644 --- a/src/spectator/matchers/contain_matcher.cr +++ b/src/spectator/matchers/contain_matcher.cr @@ -29,10 +29,10 @@ module Spectator::Matchers if missing.empty? # Contents are present. - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) else # 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, actual: actual_value.inspect, missing: missing.inspect, @@ -52,13 +52,13 @@ module Spectator::Matchers if satisfied # 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}", actual: actual_value.inspect ) else # Content is missing. - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end diff --git a/src/spectator/matchers/end_with_matcher.cr b/src/spectator/matchers/end_with_matcher.cr index 7ff3cd8..039d182 100644 --- a/src/spectator/matchers/end_with_matcher.cr +++ b/src/spectator/matchers/end_with_matcher.cr @@ -46,9 +46,9 @@ module Spectator::Matchers # This method expects (and uses) the `#ends_with?` method on the value. private def match_ends_with(actual_value, actual_label) if actual_value.ends_with?(expected.value) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) 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, actual: actual_value.inspect ) @@ -62,9 +62,9 @@ module Spectator::Matchers last = list.last if expected.value === last - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) 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, actual: last.inspect, list: list.inspect @@ -76,12 +76,12 @@ module Spectator::Matchers # This method expects (and uses) the `#ends_with?` method on the value. private def negated_match_ends_with(actual_value, actual_label) 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}", actual: actual_value.inspect ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) end end @@ -92,13 +92,13 @@ module Spectator::Matchers last = list.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}", actual: last.inspect, list: list.inspect ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) end end end diff --git a/src/spectator/matchers/exception_matcher.cr b/src/spectator/matchers/exception_matcher.cr index a27412b..adec663 100644 --- a/src/spectator/matchers/exception_matcher.cr +++ b/src/spectator/matchers/exception_matcher.cr @@ -33,16 +33,16 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T exception = capture_exception { actual.value } 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 if exception.is_a?(ExceptionType) if (value = expected.value).nil? - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) else if value === exception.message - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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, "actual type": exception.class.inspect, "expected message": value.inspect, @@ -51,7 +51,7 @@ module Spectator::Matchers end end 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, actual: exception.class.inspect ) @@ -64,28 +64,28 @@ module Spectator::Matchers def negated_match(actual : Expression(T)) : MatchData forall T exception = capture_exception { actual.value } if exception.nil? - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) else if exception.is_a?(ExceptionType) 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}", actual: exception.class.inspect ) else 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, "actual type": exception.class.inspect, "expected message": value.inspect, "actual message": exception.message.to_s ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end end diff --git a/src/spectator/matchers/have_matcher.cr b/src/spectator/matchers/have_matcher.cr index 46cd446..9c16c9f 100644 --- a/src/spectator/matchers/have_matcher.cr +++ b/src/spectator/matchers/have_matcher.cr @@ -39,10 +39,10 @@ module Spectator::Matchers if missing.empty? # Contents are present. - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) else # 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, actual: actual_value.inspect, missing: missing.inspect, @@ -58,9 +58,9 @@ module Spectator::Matchers end if missing.empty? - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) 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, actual: actual_value.inspect, missing: missing.inspect, @@ -89,13 +89,13 @@ module Spectator::Matchers if satisfied # 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}", actual: actual_value.inspect ) else # Content is missing. - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) end end @@ -107,9 +107,9 @@ module Spectator::Matchers end if satisfied - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) 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, actual: actual_value.inspect, missing: missing.inspect, diff --git a/src/spectator/matchers/matcher.cr b/src/spectator/matchers/matcher.cr index 898d319..e54e55e 100644 --- a/src/spectator/matchers/matcher.cr +++ b/src/spectator/matchers/matcher.cr @@ -21,5 +21,17 @@ module Spectator::Matchers # 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. 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 diff --git a/src/spectator/matchers/predicate_matcher.cr b/src/spectator/matchers/predicate_matcher.cr index da77dc8..ebf1d87 100644 --- a/src/spectator/matchers/predicate_matcher.cr +++ b/src/spectator/matchers/predicate_matcher.cr @@ -24,9 +24,9 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if match?(snapshot) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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 @@ -35,9 +35,9 @@ module Spectator::Matchers def negated_match(actual : Expression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) 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 - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end diff --git a/src/spectator/matchers/respond_matcher.cr b/src/spectator/matchers/respond_matcher.cr index 1f73f57..9712da5 100644 --- a/src/spectator/matchers/respond_matcher.cr +++ b/src/spectator/matchers/respond_matcher.cr @@ -17,9 +17,9 @@ module Spectator::Matchers def match(actual : Expression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if snapshot.values.all? - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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 @@ -29,9 +29,9 @@ module Spectator::Matchers snapshot = snapshot_values(actual.value) # Intentionally check truthiness of each value. 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 - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end diff --git a/src/spectator/matchers/standard_matcher.cr b/src/spectator/matchers/standard_matcher.cr index 5b9f026..43992ec 100644 --- a/src/spectator/matchers/standard_matcher.cr +++ b/src/spectator/matchers/standard_matcher.cr @@ -25,9 +25,9 @@ module Spectator::Matchers # Additionally, `#failure_message` and `#values` are called for a failed match. def match(actual : Expression(T)) : MatchData forall T if match?(actual) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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 @@ -41,9 +41,9 @@ module Spectator::Matchers def negated_match(actual : Expression(T)) : MatchData forall T # TODO: Invert description. if does_not_match?(actual) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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 diff --git a/src/spectator/matchers/start_with_matcher.cr b/src/spectator/matchers/start_with_matcher.cr index e8d0059..4bfc6c8 100644 --- a/src/spectator/matchers/start_with_matcher.cr +++ b/src/spectator/matchers/start_with_matcher.cr @@ -45,9 +45,9 @@ module Spectator::Matchers # This method expects (and uses) the `#starts_with?` method on the value. private def match_starts_with(actual_value, actual_label) if actual_value.starts_with?(expected.value) - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) 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, actual: actual_value.inspect ) @@ -61,9 +61,9 @@ module Spectator::Matchers first = list.first if expected.value === first - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) 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, actual: first.inspect, list: list.inspect @@ -75,12 +75,12 @@ module Spectator::Matchers # This method expects (and uses) the `#starts_with?` method on the value. private def negated_match_starts_with(actual_value, actual_label) 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}", actual: actual_value.inspect ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) end end @@ -91,13 +91,13 @@ module Spectator::Matchers first = list.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}", actual: first.inspect, list: list.inspect ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual_label)) end end end diff --git a/src/spectator/matchers/unordered_array_matcher.cr b/src/spectator/matchers/unordered_array_matcher.cr index aeb8b2b..510465f 100644 --- a/src/spectator/matchers/unordered_array_matcher.cr +++ b/src/spectator/matchers/unordered_array_matcher.cr @@ -28,9 +28,9 @@ module Spectator::Matchers missing, extra = array_diff(expected_elements, actual_elements) if missing.empty? && extra.empty? - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) 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, actual: actual_elements.inspect, missing: missing.inspect, @@ -50,12 +50,12 @@ module Spectator::Matchers missing, extra = array_diff(expected_elements, actual_elements) 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}", actual: actual_elements.inspect, ) else - SuccessfulMatchData.new(description) + SuccessfulMatchData.new(match_data_description(actual)) end end