From 1c865d1f4b37c79f9dbb2539deb8157e2d3fe406 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 2 Jul 2021 21:45:16 -0600 Subject: [PATCH] Fix methods not being stubbed with `expect().to receive` syntax --- src/spectator/mocks/registry.cr | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/spectator/mocks/registry.cr b/src/spectator/mocks/registry.cr index 37af7ca..a89712c 100644 --- a/src/spectator/mocks/registry.cr +++ b/src/spectator/mocks/registry.cr @@ -71,11 +71,15 @@ module Spectator::Mocks end def expect(object, stub : MethodStub) : Nil - fetch_instance(object).expected.add(stub) + entry = fetch_instance(object) + entry.expected.add(stub) + entry.stubs.unshift(stub) end def expect(type : T.class, stub : MethodStub) : Nil forall T - fetch_type(type).expected.add(stub) + entry = fetch_type(type) + entry.expected.add(stub) + entry.stubs.unshift(stub) end private def fetch_instance(object)