mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove internal double class
Stub handling method should be called from nested methods.
This commit is contained in:
parent
c80a28d616
commit
211050650e
2 changed files with 11 additions and 19 deletions
|
@ -29,24 +29,22 @@ module Spectator
|
||||||
call = ::Spectator::MethodCall.new({{name.symbolize}}, args, options)
|
call = ::Spectator::MethodCall.new({{name.symbolize}}, args, options)
|
||||||
stub = @stubs.find(&.callable?(call))
|
stub = @stubs.find(&.callable?(call))
|
||||||
if stub
|
if stub
|
||||||
stub.as(::Spectator::GenericMethodStub(typeof(@internal.{{name}}(*args, **options)))).call(call)
|
stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options)))).call(call)
|
||||||
else
|
else
|
||||||
@internal.{{name}}(*args, **options)
|
%method(*args, **options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{name}}(*args, **options, &block){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def {{name}}(*args, **options, &block){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
@internal.{{name}}(*args, **options, &block)
|
%method(*args, **options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
private class Internal
|
def %method({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
def {{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
{% if body && !body.is_a?(Nop) %}
|
||||||
{% if body && !body.is_a?(Nop) %}
|
{{body.body}}
|
||||||
{{body.body}}
|
{% else %}
|
||||||
{% else %}
|
raise "Stubbed method called without being allowed"
|
||||||
raise "Stubbed method called without being allowed"
|
{% end %}
|
||||||
{% end %}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,10 @@ module Spectator::DSL
|
||||||
Double{{name.id}}.new(self)
|
Double{{name.id}}.new(self)
|
||||||
{% else %}
|
{% else %}
|
||||||
class Double{{name.id}} < ::Spectator::Double
|
class Double{{name.id}} < ::Spectator::Double
|
||||||
private class Internal
|
def initialize(@spectator_test : {{@type.id}})
|
||||||
def initialize(@test : {{@type.id}})
|
|
||||||
end
|
|
||||||
|
|
||||||
forward_missing_to @test
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(test : {{@type.id}})
|
forward_missing_to @spectator_test
|
||||||
@internal = Internal.new(test)
|
|
||||||
end
|
|
||||||
|
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue