Don't use a proc stub, which doesn't support arguments.
This commit is contained in:
Michael Miller 2020-03-28 11:41:49 -06:00
parent 5c24d606dd
commit 68bac59cab

View file

@ -50,12 +50,9 @@ module Spectator::Mocks
%} %}
{% if body && !body.is_a?(Nop) %} {% if body && !body.is_a?(Nop) %}
%source = ::Spectator::Source.new({{_file}}, {{_line}}) def {{receiver}}%method({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
%proc = ->{
{{body.body}} {{body.body}}
} end
%ds = ::Spectator::Mocks::ProcMethodStub.new({{name.symbolize}}, %source, %proc)
::Spectator::SpecBuilder.add_default_stub({{@type.name}}, %ds)
{% end %} {% end %}
def {{receiver}}{{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %} def {{receiver}}{{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
@ -66,8 +63,15 @@ module Spectator::Mocks
if (%stub = %harness.mocks.find_stub(self, %call)) if (%stub = %harness.mocks.find_stub(self, %call))
return %stub.call!(%args) { {{original}}({{args.splat}}) } return %stub.call!(%args) { {{original}}({{args.splat}}) }
end end
{% if body && !body.is_a?(Nop) %}
%method({{args.splat}})
{% else %}
{{original}}({{args.splat}})
{% end %}
else
{{original}}({{args.splat}})
end end
{{original}}({{args.splat}})
end end
def {{receiver}}{{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %} def {{receiver}}{{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
@ -78,9 +82,18 @@ module Spectator::Mocks
if (%stub = %harness.mocks.find_stub(self, %call)) if (%stub = %harness.mocks.find_stub(self, %call))
return %stub.call!(%args) { {{original}}({{args.splat}}) { |*%ya| yield *%ya } } return %stub.call!(%args) { {{original}}({{args.splat}}) { |*%ya| yield *%ya } }
end end
end
{{original}}({{args.splat}}) do |*%yield_args| {% if body && !body.is_a?(Nop) %}
yield *%yield_args %method({{args.splat}}) { {{original}}({{args.splat}}) { |*%ya| yield *%ya } }
{% else %}
{{original}}({{args.splat}}) do |*%yield_args|
yield *%yield_args
end
{% end %}
else
{{original}}({{args.splat}}) do |*%yield_args|
yield *%yield_args
end
end end
end end
end end