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,24 +29,22 @@ module Spectator
call = ::Spectator::MethodCall.new({{name.symbolize}}, args, options)
stub = @stubs.find(&.callable?(call))
if stub
stub.as(::Spectator::GenericMethodStub(typeof(@internal.{{name}}(*args, **options)))).call(call)
stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options)))).call(call)
else
@internal.{{name}}(*args, **options)
%method(*args, **options)
end
end
def {{name}}(*args, **options, &block){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
@internal.{{name}}(*args, **options, &block)
%method(*args, **options, &block)
end
private class Internal
def {{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
{% if body && !body.is_a?(Nop) %}
{{body.body}}
{% else %}
raise "Stubbed method called without being allowed"
{% end %}
end
def %method({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
{% if body && !body.is_a?(Nop) %}
{{body.body}}
{% else %}
raise "Stubbed method called without being allowed"
{% end %}
end
end

View file

@ -8,16 +8,10 @@ module Spectator::DSL
Double{{name.id}}.new(self)
{% else %}
class Double{{name.id}} < ::Spectator::Double
private class Internal
def initialize(@test : {{@type.id}})
end
forward_missing_to @test
def initialize(@spectator_test : {{@type.id}})
end
def initialize(test : {{@type.id}})
@internal = Internal.new(test)
end
forward_missing_to @spectator_test
{{block.body}}
end