Resolve issue with harness trying to be used outside of test

This commit is contained in:
Michael Miller 2019-11-10 07:27:59 -07:00
parent 11ea7bf2ce
commit f816a64770

View file

@ -34,23 +34,26 @@ module Spectator::Mocks
%} %}
def {{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %} def {{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
if (%harness = ::Spectator::Harness.current?)
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}}) %args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args) %call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
::Spectator::Harness.current.mocks.record_call(self, %call) %harness.mocks.record_call(self, %call)
if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call)) if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call))
%stub.call!(%args, typeof({{original}}({{args.splat}}))) return %stub.call!(%args, typeof({{original}}({{args.splat}})))
else
{{original}}({{args.splat}})
end end
end end
{{original}}({{args.splat}})
end
def {{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %} def {{name}}({{params.splat}}){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
if (%harness = ::Spectator::Harness.current?)
%args = ::Spectator::Mocks::GenericArguments.create({{args.splat}}) %args = ::Spectator::Mocks::GenericArguments.create({{args.splat}})
%call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args) %call = ::Spectator::Mocks::GenericMethodCall.new({{name.symbolize}}, %args)
::Spectator::Harness.current.mocks.record_call(self, %call) %harness.mocks.record_call(self, %call)
if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call)) if (%stub = ::Spectator::Harness.current.mocks.find_stub(self, %call))
%stub.call!(%args, typeof({{original}}({{args.splat}}) { |*%ya| yield *%ya })) return %stub.call!(%args, typeof({{original}}({{args.splat}}) { |*%ya| yield *%ya }))
else end
end
{{original}}({{args.splat}}) do |*%yield_args| {{original}}({{args.splat}}) do |*%yield_args|
yield *%yield_args yield *%yield_args
end end
@ -58,4 +61,3 @@ module Spectator::Mocks
end end
end end
end end
end