From 4b59dcf1428a3421efdf7459807eb17e61c0337a Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 1 Aug 2019 16:02:28 -0600 Subject: [PATCH] Pass actual value to failure message methods and values --- src/spectator/matchers/matcher.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/spectator/matchers/matcher.cr b/src/spectator/matchers/matcher.cr index 798c525..c022d52 100644 --- a/src/spectator/matchers/matcher.cr +++ b/src/spectator/matchers/matcher.cr @@ -18,7 +18,7 @@ module Spectator::Matchers # Message displayed when the matcher isn't satisifed. # This is only called when `#matches?` returns false. - abstract def failure_message : String + abstract def failure_message(actual) : String # Message displayed when the matcher isn't satisifed and is negated. # This is only called when `#does_not_match?` returns false. @@ -26,7 +26,7 @@ module Spectator::Matchers # A default implementation of this method is provided, # which causes compilation to fail. # If the matcher supports negation, it must override this method. - def failure_message_when_negated : String + def failure_message_when_negated(actual) : String {% raise "Negation with #{@type.name} is not supported." %} end @@ -54,7 +54,7 @@ module Spectator::Matchers if match?(actual) SuccessfulMatchData.new else - FailedMatchData.new(failure_message, values) + FailedMatchData.new(failure_message(actual), values(actual)) end end @@ -62,7 +62,7 @@ module Spectator::Matchers if does_not_match?(actual) SuccessfulMatchData.new else - FailedMatchData.new(failure_message_when_negated, negated_values) + FailedMatchData.new(failure_message_when_negated(actual), negated_values(actual)) end end end