Add utility methods for setting count

This commit is contained in:
Michael Miller 2019-11-03 14:00:40 -07:00
parent dabd3a7658
commit 46aff9e11c

View file

@ -44,6 +44,34 @@ module Spectator::Matchers
ReceiveMatcher.new(@expected, (2..2))
end
def exactly(count)
Count.new(@expected, (count..count))
end
def at_least(count)
Count.new(@expected, (count..))
end
def at_most(count)
Count.new(@expected, (..count))
end
def at_least_once
at_least(1).times
end
def at_least_twice
at_least(2).times
end
def at_most_once
at_most(1).times
end
def at_most_twice
at_most(2).times
end
def humanize_range(range : Range)
if (min = range.begin)
if (max = range.end)
@ -63,5 +91,14 @@ module Spectator::Matchers
end
end
end
private struct Count
def initialize(@expected : TestExpression(Symbol), @range : Range)
end
def times
ReceiveMatcher.new(@expected, @range)
end
end
end
end