mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add stub support to class methods on mocks
This commit is contained in:
parent
c76ead4065
commit
f7147299ab
2 changed files with 221 additions and 0 deletions
|
@ -3,6 +3,7 @@ require "./mocked"
|
|||
require "./reference_mock_registry"
|
||||
require "./stub"
|
||||
require "./stubbed_name"
|
||||
require "./stubbed_type"
|
||||
require "./value_mock_registry"
|
||||
require "./value_stub"
|
||||
|
||||
|
@ -37,6 +38,7 @@ module Spectator
|
|||
{% if name %}@[::Spectator::StubbedName({{name}})]{% end %}
|
||||
{{base.id}} {{type_name.id}} < {{mocked_type.id}}
|
||||
include ::Spectator::Mocked
|
||||
extend ::Spectator::StubbedType
|
||||
|
||||
{% begin %}
|
||||
private getter(_spectator_stubs) do
|
||||
|
@ -52,6 +54,10 @@ module Spectator
|
|||
@_spectator_stubs = nil
|
||||
end
|
||||
|
||||
private class_getter _spectator_stubs : Array(::Spectator::Stub) = [] of ::Spectator::Stub
|
||||
|
||||
class_getter _spectator_calls : Array(::Spectator::MethodCall) = [] of ::Spectator::MethodCall
|
||||
|
||||
getter _spectator_calls = [] of ::Spectator::MethodCall
|
||||
|
||||
# Returns the mock's name formatted for user output.
|
||||
|
@ -111,6 +117,7 @@ module Spectator
|
|||
{% if name %}@[::Spectator::StubbedName({{name}})]{% end %}
|
||||
{{base.id}} {{type_name.id}}
|
||||
include ::Spectator::Mocked
|
||||
extend ::Spectator::StubbedType
|
||||
|
||||
{% if base == :class %}
|
||||
@@_spectator_mock_registry = ::Spectator::ReferenceMockRegistry.new
|
||||
|
@ -120,6 +127,10 @@ module Spectator
|
|||
{% raise "Unsupported base type #{base} for injecting mock" %}
|
||||
{% end %}
|
||||
|
||||
private class_getter _spectator_stubs : Array(::Spectator::Stub) = [] of ::Spectator::Stub
|
||||
|
||||
class_getter _spectator_calls : Array(::Spectator::MethodCall) = [] of ::Spectator::MethodCall
|
||||
|
||||
private def _spectator_stubs
|
||||
entry = @@_spectator_mock_registry.fetch(self) do
|
||||
_spectator_default_stubs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue