Add mock registry prep

This commit is contained in:
Michael Miller 2019-11-09 10:49:29 -07:00
parent 74eb4fc11a
commit e9f7e65ac9
3 changed files with 15 additions and 4 deletions

View file

@ -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

View file

@ -11,6 +11,10 @@ module Spectator::Mocks
@@entries = {} of Key => Entry
def prepare(context : TestContext) : Nil
# TODO
end
def reset : Nil
@@entries.clear
end

View file

@ -7,11 +7,12 @@ module Spectator
# Runs the example, hooks, and captures the result
# and translates to a usable result.
def run_impl : Result
Mocks.run(group.context) do
result = capture_result
expectations = Harness.current.expectations
Mocks::Registry.reset
translate_result(result, expectations)
end
end
# Runs all hooks and the example code.
# A captured result is returned.