Use tap to modify new mock

Without this, mocked structs were not getting their stubs applied.
An unintended side-effect is the tap shows up in recorded calls.
This seems to be harmless, but might need to be revisited.
This commit is contained in:
Michael Miller 2022-07-12 21:19:51 -06:00
parent 0e556c3d55
commit df5a4fa77c
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -294,14 +294,12 @@ module Spectator::DSL
found_tuple = found_tuples.last %}
{% if found_tuple %}
begin
%mock = {{found_tuple[2].id}}.new
{{found_tuple[2].id}}.new.tap do |%mock|
{% for key, value in value_methods %}
%stub{key} = ::Spectator::ValueStub.new({{key.id.symbolize}}, {{value}})
%mock._spectator_define_stub(%stub{key})
{% end %}
::Spectator::Harness.current?.try(&.cleanup { %mock._spectator_reset })
%mock
end
{% else %}
{% raise "Type `#{type.id}` must be previously mocked before attempting to instantiate." %}