mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle case where block is provided with return type
This commit is contained in:
parent
8966c0976b
commit
b91103b40a
2 changed files with 14 additions and 8 deletions
|
@ -64,7 +64,7 @@ module Spectator::Mocks
|
||||||
end
|
end
|
||||||
%}
|
%}
|
||||||
|
|
||||||
def {{name}}({{params.splat}}){% if return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def {{name}}({{params.splat}}){% if return_type.is_a?(ArrayLiteral) %} : {{return_type.type}}{% elsif return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
||||||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||||
::Spectator::Harness.current.mocks.record_call(self, %call)
|
::Spectator::Harness.current.mocks.record_call(self, %call)
|
||||||
|
@ -75,7 +75,7 @@ module Spectator::Mocks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{name}}({{params.splat}}){% if return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def {{name}}({{params.splat}}){% if return_type.is_a?(ArrayLiteral) %} : {{return_type.type}}{% elsif return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
||||||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||||
::Spectator::Harness.current.mocks.record_call(self, %call)
|
::Spectator::Harness.current.mocks.record_call(self, %call)
|
||||||
|
@ -88,9 +88,11 @@ module Spectator::Mocks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def %method({{params.splat}}){% if return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def %method({{params.splat}}){% if return_type.is_a?(ArrayLiteral) %} : {{return_type.type}}{% elsif return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
{% if body && !body.is_a?(Nop) %}
|
{% if body && !body.is_a?(Nop) %}
|
||||||
{{body.body}}
|
{{body.body}}
|
||||||
|
{% elsif return_type.is_a?(ArrayLiteral) %}
|
||||||
|
{{return_type.splat}}
|
||||||
{% else %}
|
{% else %}
|
||||||
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
||||||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||||
|
|
|
@ -65,12 +65,16 @@ module Spectator::Mocks
|
||||||
%}
|
%}
|
||||||
|
|
||||||
{% if body && !body.is_a?(Nop) %}
|
{% if body && !body.is_a?(Nop) %}
|
||||||
def {{receiver}}%method({{params.splat}}){% if return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def {{receiver}}%method({{params.splat}}){% if return_type.is_a?(ArrayLiteral) %} : {{return_type.type}}{% elsif return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
{{body.body}}
|
{{body.body}}
|
||||||
end
|
end
|
||||||
|
{% elsif return_type.is_a?(ArrayLiteral) %}
|
||||||
|
def {{receiver}}%method({{params.splat}}) : {{return_type.type}}
|
||||||
|
{{return_type.splat}}
|
||||||
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
def {{receiver}}{{name}}({{params.splat}}){% if return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def {{receiver}}{{name}}({{params.splat}}){% if return_type.is_a?(ArrayLiteral) %} : {{return_type.type}}{% elsif return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
if (%harness = ::Spectator::Harness.current?)
|
if (%harness = ::Spectator::Harness.current?)
|
||||||
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
||||||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||||
|
@ -79,7 +83,7 @@ module Spectator::Mocks
|
||||||
return %stub.call!(%args) { {{original}} }
|
return %stub.call!(%args) { {{original}} }
|
||||||
end
|
end
|
||||||
|
|
||||||
{% if body && !body.is_a?(Nop) %}
|
{% if body && !body.is_a?(Nop) || return_type.is_a?(ArrayLiteral) %}
|
||||||
%method({{args.splat}})
|
%method({{args.splat}})
|
||||||
{% else %}
|
{% else %}
|
||||||
{{original}}
|
{{original}}
|
||||||
|
@ -89,7 +93,7 @@ module Spectator::Mocks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{receiver}}{{name}}({{params.splat}}){% if return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
def {{receiver}}{{name}}({{params.splat}}){% if return_type.is_a?(ArrayLiteral) %} : {{return_type.type}}{% elsif return_type != :undefined %} : {{return_type.id}}{% elsif definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
|
||||||
if (%harness = ::Spectator::Harness.current?)
|
if (%harness = ::Spectator::Harness.current?)
|
||||||
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
|
||||||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||||
|
@ -98,7 +102,7 @@ module Spectator::Mocks
|
||||||
return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } }
|
return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } }
|
||||||
end
|
end
|
||||||
|
|
||||||
{% if body && !body.is_a?(Nop) %}
|
{% if body && !body.is_a?(Nop) || return_type.is_a?(ArrayLiteral) %}
|
||||||
%method({{args.splat}}) { |*%ya| yield *%ya }
|
%method({{args.splat}}) { |*%ya| yield *%ya }
|
||||||
{% else %}
|
{% else %}
|
||||||
{{original}} do |*%yield_args|
|
{{original}} do |*%yield_args|
|
||||||
|
|
Loading…
Reference in a new issue