Record call to stub

This commit is contained in:
Michael Miller 2019-10-13 18:50:19 -06:00
parent 76fa7e294f
commit 3dd691a990

View file

@ -33,6 +33,7 @@ module Spectator
{% if name.ends_with?('=') && name.id != "[]=" %} {% if name.ends_with?('=') && name.id != "[]=" %}
def {{name}}(arg) def {{name}}(arg)
call = ::Spectator::GenericMethodCall.new({{name.symbolize}}, {arg}, NamedTuple.new) call = ::Spectator::GenericMethodCall.new({{name.symbolize}}, {arg}, NamedTuple.new)
@spectator_stub_calls << call
stub = @spectator_stubs.find(&.callable?(call)) stub = @spectator_stubs.find(&.callable?(call))
if stub if stub
stub.as(::Spectator::GenericMethodStub(typeof(%method(arg)))).call(call) stub.as(::Spectator::GenericMethodStub(typeof(%method(arg)))).call(call)
@ -43,6 +44,7 @@ module Spectator
{% else %} {% else %}
def {{name}}(*args, **options){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %} def {{name}}(*args, **options){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
call = ::Spectator::GenericMethodCall.new({{name.symbolize}}, args, options) call = ::Spectator::GenericMethodCall.new({{name.symbolize}}, args, options)
@spectator_stub_calls << call
stub = @spectator_stubs.find(&.callable?(call)) stub = @spectator_stubs.find(&.callable?(call))
if stub if stub
stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options)))).call(call) stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options)))).call(call)
@ -54,6 +56,7 @@ module Spectator
{% if name != "[]=" %} {% if name != "[]=" %}
def {{name}}(*args, **options){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %} def {{name}}(*args, **options){% if definition.is_a?(TypeDeclaration) %} : {{definition.type}}{% end %}
call = ::Spectator::GenericMethodCall.new({{name.symbolize}}, args, options) call = ::Spectator::GenericMethodCall.new({{name.symbolize}}, args, options)
@spectator_stub_calls << call
stub = @spectator_stubs.find(&.callable?(call)) stub = @spectator_stubs.find(&.callable?(call))
if stub if stub
stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options) { |*yield_args| yield *yield_args }))).call(call) stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options) { |*yield_args| yield *yield_args }))).call(call)