diff --git a/src/spectator/matchers/receive_arguments_matcher.cr b/src/spectator/matchers/receive_arguments_matcher.cr index 483b836..0110d53 100644 --- a/src/spectator/matchers/receive_arguments_matcher.cr +++ b/src/spectator/matchers/receive_arguments_matcher.cr @@ -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}", diff --git a/src/spectator/matchers/receive_matcher.cr b/src/spectator/matchers/receive_matcher.cr index ae294bb..489f453 100644 --- a/src/spectator/matchers/receive_matcher.cr +++ b/src/spectator/matchers/receive_matcher.cr @@ -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", diff --git a/src/spectator/mocks/registry.cr b/src/spectator/mocks/registry.cr index 3672d30..a662cb5 100644 --- a/src/spectator/mocks/registry.cr +++ b/src/spectator/mocks/registry.cr @@ -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)