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.