diff --git a/src/spectator/double.cr b/src/spectator/double.cr index 4301370..210ea98 100644 --- a/src/spectator/double.cr +++ b/src/spectator/double.cr @@ -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 diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 532b058..fdd4ed2 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -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