Remove internal double class

Stub handling method should be called from nested methods.
This commit is contained in:
Michael Miller 2019-10-12 21:08:49 -06:00
parent c80a28d616
commit 211050650e
2 changed files with 11 additions and 19 deletions

View file

@ -29,18 +29,17 @@ 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 %}
@ -48,7 +47,6 @@ module Spectator
{% end %} {% end %}
end end
end end
end
protected def spectator_define_stub(stub : MethodStub) : Nil protected def spectator_define_stub(stub : MethodStub) : Nil
@stubs << stub @stubs << stub

View file

@ -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 end
forward_missing_to @test forward_missing_to @spectator_test
end
def initialize(test : {{@type.id}})
@internal = Internal.new(test)
end
{{block.body}} {{block.body}}
end end