mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Pass arguments to original/fallback for stubbed top-level methods
Addresses https://github.com/icy-arctic-fox/spectator/issues/36
This commit is contained in:
parent
a95c5bcab7
commit
36354082c7
2 changed files with 12 additions and 6 deletions
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
- Fix usage of `be ===` and `be =~` [#34](https://github.com/icy-arctic-fox/spectator/issues/34)
|
||||
- Better handling of the `be(nil)` when used with value types. [#37](https://github.com/icy-arctic-fox/spectator/issues/37)
|
||||
- Fix missing arguments for stubbed top-level methods (`system`, `exit`, etc.). [#36](https://github.com/icy-arctic-fox/spectator/issues/36)
|
||||
|
||||
### Changed
|
||||
- Elegantly handle missing/undefined methods with `have_attributes` matcher.
|
||||
|
|
|
@ -64,6 +64,11 @@ module Spectator::Mocks
|
|||
else
|
||||
name
|
||||
end.id
|
||||
fallback = if original == :super.id || original == :previous_def.id
|
||||
original
|
||||
else
|
||||
"::#{original}(#{args.splat})".id
|
||||
end
|
||||
%}
|
||||
|
||||
{% if body && !body.is_a?(Nop) %}
|
||||
|
@ -82,16 +87,16 @@ module Spectator::Mocks
|
|||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||
%harness.mocks.record_call(self, %call)
|
||||
if (%stub = %harness.mocks.find_stub(self, %call))
|
||||
return %stub.call!(%args) { {{original}} }
|
||||
return %stub.call!(%args) { {{fallback}} }
|
||||
end
|
||||
|
||||
{% if body && !body.is_a?(Nop) || return_type.is_a?(ArrayLiteral) %}
|
||||
%method({{args.splat}})
|
||||
{% else %}
|
||||
{{original}}
|
||||
{{fallback}}
|
||||
{% end %}
|
||||
else
|
||||
{{original}}
|
||||
{{fallback}}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -101,18 +106,18 @@ module Spectator::Mocks
|
|||
%call = ::Spectator::Mocks::MethodCall.new({{name.symbolize}}, %args)
|
||||
%harness.mocks.record_call(self, %call)
|
||||
if (%stub = %harness.mocks.find_stub(self, %call))
|
||||
return %stub.call!(%args) { {{original}} { |*%ya| yield *%ya } }
|
||||
return %stub.call!(%args) { {{fallback}} { |*%ya| yield *%ya } }
|
||||
end
|
||||
|
||||
{% if body && !body.is_a?(Nop) || return_type.is_a?(ArrayLiteral) %}
|
||||
%method({{args.splat}}) { |*%ya| yield *%ya }
|
||||
{% else %}
|
||||
{{original}} do |*%yield_args|
|
||||
{{fallback}} do |*%yield_args|
|
||||
yield *%yield_args
|
||||
end
|
||||
{% end %}
|
||||
else
|
||||
{{original}} do |*%yield_args|
|
||||
{{fallback}} do |*%yield_args|
|
||||
yield *%yield_args
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue