mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add default stubs from parent contexts
This commit is contained in:
parent
d2e27d1e6e
commit
6c0693f2a4
2 changed files with 20 additions and 9 deletions
|
@ -11,11 +11,20 @@ module Spectator::Mocks
|
||||||
@entries = {} of Key => Entry
|
@entries = {} of Key => Entry
|
||||||
|
|
||||||
def initialize(context : TestContext)
|
def initialize(context : TestContext)
|
||||||
@all_instances = context.stubs.map do |k, v|
|
current_context = context
|
||||||
entry = Entry.new
|
while current_context
|
||||||
entry.stubs.concat(v)
|
current_context.stubs.each do |k, v|
|
||||||
{k, entry}
|
stubs = if @all_instances.has_key?(k)
|
||||||
end.to_h
|
@all_instances[k].stubs
|
||||||
|
else
|
||||||
|
entry = Entry.new
|
||||||
|
@all_instances[k] = entry
|
||||||
|
entry.stubs
|
||||||
|
end
|
||||||
|
stubs.concat(v)
|
||||||
|
end
|
||||||
|
current_context = current_context.parent?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset : Nil
|
def reset : Nil
|
||||||
|
|
|
@ -3,15 +3,17 @@ require "./test_values"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
class TestContext
|
class TestContext
|
||||||
|
getter! parent
|
||||||
|
|
||||||
getter values
|
getter values
|
||||||
|
|
||||||
getter stubs : Hash(String, Deque(Mocks::MethodStub))
|
getter stubs : Hash(String, Deque(Mocks::MethodStub))
|
||||||
|
|
||||||
def initialize(@parent : TestContext?,
|
def initialize(@parent : TestContext?,
|
||||||
@hooks : ExampleHooks,
|
@hooks : ExampleHooks,
|
||||||
@conditions : ExampleConditions,
|
@conditions : ExampleConditions,
|
||||||
@values : TestValues,
|
@values : TestValues,
|
||||||
@stubs : Hash(String, Deque(Mocks::MethodStub)))
|
@stubs : Hash(String, Deque(Mocks::MethodStub)))
|
||||||
@before_all_hooks_run = false
|
@before_all_hooks_run = false
|
||||||
@after_all_hooks_run = false
|
@after_all_hooks_run = false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue