Add #by modifier methods

This commit is contained in:
Michael Miller 2019-08-11 13:52:22 -06:00
parent 848f80ddf8
commit c19f442e6c
2 changed files with 10 additions and 0 deletions

View File

@ -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.

View File

@ -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.