From c19f442e6cc6f455e310778408ac2699152bb177 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 11 Aug 2019 13:52:22 -0600 Subject: [PATCH] Add #by modifier methods --- src/spectator/matchers/change_from_matcher.cr | 5 +++++ src/spectator/matchers/change_to_matcher.cr | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/spectator/matchers/change_from_matcher.cr b/src/spectator/matchers/change_from_matcher.cr index 75e81db..82a9267 100644 --- a/src/spectator/matchers/change_from_matcher.cr +++ b/src/spectator/matchers/change_from_matcher.cr @@ -67,6 +67,11 @@ module Spectator::Matchers ChangeExactMatcher.new(@expression, @expected, value) end + # Specifies what the resulting value of the expression should change by. + def by(amount : T) forall T + ChangeExactMatcher.new(@expression, @expected, @expected + value) + end + # Performs the change and reports the before and after values. private def change(actual) before = expression.value # Retrieve the expression's initial value. diff --git a/src/spectator/matchers/change_to_matcher.cr b/src/spectator/matchers/change_to_matcher.cr index e95c1d9..65f1ce5 100644 --- a/src/spectator/matchers/change_to_matcher.cr +++ b/src/spectator/matchers/change_to_matcher.cr @@ -61,6 +61,11 @@ module Spectator::Matchers ChangeExactMatcher.new(@expression, value, @expected) end + # Specifies how much the initial value should change by. + def by(amount : T) forall T + ChangeExactMatcher.new(@expression, @expected - amount, @expected) + end + # Performs the change and reports the before and after values. private def change(actual) before = expression.value # Retrieve the expression's initial value.