Update receive matchers to use registry

This commit is contained in:
Michael Miller 2019-11-09 09:23:01 -07:00
parent 9e8286f892
commit 48363951c2
3 changed files with 8 additions and 8 deletions

View file

@ -14,8 +14,7 @@ module Spectator::Matchers
end
def match?(actual : TestExpression(T)) : Bool forall T
double = actual.value.as(Mocks::Double)
calls = double.spectator_stub_calls(@expected.value).select { |call| @args === call.args }
calls = Mocks::Registry.calls_for(actual.value, @expected.value).select { |call| @args === call.args }
if (range = @range)
range.includes?(calls.size)
else
@ -29,8 +28,7 @@ module Spectator::Matchers
end
def values(actual : TestExpression(T)) forall T
double = actual.value.as(Mocks::Double)
calls = double.spectator_stub_calls(@expected.value)
calls = Mocks::Registry.calls_for(actual.value, @expected.value).select { |call| @args === call.args }
range = @range
{
expected: "#{range ? "#{humanize_range(range)} time(s)" : "At least once"} with #{@args}",

View file

@ -14,8 +14,7 @@ module Spectator::Matchers
end
def match?(actual : TestExpression(T)) : Bool forall T
double = actual.value.as(Mocks::Double)
calls = double.spectator_stub_calls(@expected.value)
calls = Mocks::Registry.calls_for(actual.value, @expected.value)
if (range = @range)
range.includes?(calls.size)
else
@ -29,8 +28,7 @@ module Spectator::Matchers
end
def values(actual : TestExpression(T)) forall T
double = actual.value.as(Mocks::Double)
calls = double.spectator_stub_calls(@expected.value)
calls = Mocks::Registry.calls_for(actual.value, @expected.value)
range = @range
{
expected: "#{range ? "#{humanize_range(range)} time(s)" : "At least once"} with any arguments",

View file

@ -27,6 +27,10 @@ module Spectator::Mocks
fetch(object).calls << call
end
def calls_for(object, method_name : Symbol)
fetch(object).calls.select { |call| call.name == method_name }
end
private def fetch(object)
key = unique_key(object)
if @@entries.has_key?(key)