Add specialized should/should_not methods for procs

This commit is contained in:
Michael Miller 2019-03-23 20:20:15 -06:00
parent 102105911c
commit d04db7bf68
1 changed files with 14 additions and 0 deletions

View File

@ -30,3 +30,17 @@ class Object
::Spectator::Expectations::ValueExpectationPartial.new(self, __FILE__, __LINE__).to_not(matcher)
end
end
struct Proc(*T, R)
# Extension method to create an expectation for a block of code (proc).
# Depending on the matcher, the proc may be executed multiple times.
def should(matcher : ::Spectator::Matchers::Matcher)
::Spectator::Expectations::BlockExpectationPartial.new(self, __FILE__, __LINE__).to(matcher)
end
# Works the same as `#should` except the condition is inverted.
# When `#should` succeeds, this method will fail, and vice-versa.
def should_not(matcher : ::Spectator::Matchers::Matcher)
::Spectator::Expectations::BlockExpectationPartial.new(self, __FILE__, __LINE__).to_not(matcher)
end
end