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

View file

@ -14,8 +14,7 @@ module Spectator::Matchers
end end
def match?(actual : TestExpression(T)) : Bool forall T def match?(actual : TestExpression(T)) : Bool forall T
double = actual.value.as(Mocks::Double) calls = Mocks::Registry.calls_for(actual.value, @expected.value)
calls = double.spectator_stub_calls(@expected.value)
if (range = @range) if (range = @range)
range.includes?(calls.size) range.includes?(calls.size)
else else
@ -29,8 +28,7 @@ module Spectator::Matchers
end end
def values(actual : TestExpression(T)) forall T def values(actual : TestExpression(T)) forall T
double = actual.value.as(Mocks::Double) calls = Mocks::Registry.calls_for(actual.value, @expected.value)
calls = double.spectator_stub_calls(@expected.value)
range = @range range = @range
{ {
expected: "#{range ? "#{humanize_range(range)} time(s)" : "At least once"} with any arguments", 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 fetch(object).calls << call
end end
def calls_for(object, method_name : Symbol)
fetch(object).calls.select { |call| call.name == method_name }
end
private def fetch(object) private def fetch(object)
key = unique_key(object) key = unique_key(object)
if @@entries.has_key?(key) if @@entries.has_key?(key)