From 8fb051d61e17f9e3c80deb41f6e463425014aa95 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 24 Sep 2018 22:56:48 -0600 Subject: [PATCH] Add custom messages for matchers This gives users natural, easier to understand text for expectations. --- src/spectator/matchers/equality_matcher.cr | 8 ++++++++ src/spectator/matchers/matcher.cr | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/spectator/matchers/equality_matcher.cr b/src/spectator/matchers/equality_matcher.cr index 1c3b00b..6a57cb5 100644 --- a/src/spectator/matchers/equality_matcher.cr +++ b/src/spectator/matchers/equality_matcher.cr @@ -10,6 +10,14 @@ module Spectator def match?(expectation : Expectation) expectation.actual == @expected end + + def message(expectation : Expectation) : String + "Expected #{expectation.actual} to equal #{@expected} (using ==)" + end + + def negated_message(expectation : Expectation) : String + "Expected #{expectation.actual} to not equal #{@expected} (using ==)" + end end end end diff --git a/src/spectator/matchers/matcher.cr b/src/spectator/matchers/matcher.cr index 3b847b2..414e62d 100644 --- a/src/spectator/matchers/matcher.cr +++ b/src/spectator/matchers/matcher.cr @@ -7,6 +7,8 @@ module Spectator end abstract def match?(expectation : Expectation) + abstract def message(expectation : Expectation) : String + abstract def negated_message(expectation : Expectation) : String end end end