From e9f7e65ac956a7600d8f22989e6c1faf6200feb8 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 9 Nov 2019 10:49:29 -0700 Subject: [PATCH] Add mock registry prep --- src/spectator/mocks.cr | 6 ++++++ src/spectator/mocks/registry.cr | 4 ++++ src/spectator/runnable_example.cr | 9 +++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/spectator/mocks.cr b/src/spectator/mocks.cr index f50bf9e..d36eeff 100644 --- a/src/spectator/mocks.cr +++ b/src/spectator/mocks.cr @@ -3,5 +3,11 @@ require "./mocks/*" module Spectator # Functionality for mocking existing types. module Mocks + def self.run(context : TestContext) + Registry.prepare(context) + yield + ensure + Registry.reset + end end end diff --git a/src/spectator/mocks/registry.cr b/src/spectator/mocks/registry.cr index b6ca7f8..a655eee 100644 --- a/src/spectator/mocks/registry.cr +++ b/src/spectator/mocks/registry.cr @@ -11,6 +11,10 @@ module Spectator::Mocks @@entries = {} of Key => Entry + def prepare(context : TestContext) : Nil + # TODO + end + def reset : Nil @@entries.clear end diff --git a/src/spectator/runnable_example.cr b/src/spectator/runnable_example.cr index 507279a..c5c0b5b 100644 --- a/src/spectator/runnable_example.cr +++ b/src/spectator/runnable_example.cr @@ -7,10 +7,11 @@ module Spectator # Runs the example, hooks, and captures the result # and translates to a usable result. def run_impl : Result - result = capture_result - expectations = Harness.current.expectations - Mocks::Registry.reset - translate_result(result, expectations) + Mocks.run(group.context) do + result = capture_result + expectations = Harness.current.expectations + translate_result(result, expectations) + end end # Runs all hooks and the example code.