mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle deferred stub with type
This commit is contained in:
parent
49764e5873
commit
1bbe5067b6
1 changed files with 21 additions and 9 deletions
|
@ -1,18 +1,30 @@
|
||||||
module Spectator
|
module Spectator
|
||||||
abstract class Double
|
abstract class Double
|
||||||
macro stub(definition, &block)
|
macro stub(definition, &block)
|
||||||
delegate {{definition.name.id}}, to: @internal
|
{%
|
||||||
|
name = nil
|
||||||
|
args = nil
|
||||||
|
body = nil
|
||||||
|
if definition.is_a?(Call) # stub foo { :bar }
|
||||||
|
name = definition.name.id
|
||||||
|
args = definition.args
|
||||||
|
body = definition.block.is_a?(Nop) ? block : definition.block
|
||||||
|
elsif definition.is_a?(TypeDeclaration) # stub foo : Symbol
|
||||||
|
name = definition.var
|
||||||
|
args = [] of MacroId
|
||||||
|
body = block
|
||||||
|
else
|
||||||
|
raise "Unrecognized stub format"
|
||||||
|
end
|
||||||
|
%}
|
||||||
|
delegate {{name}}, to: @internal
|
||||||
|
|
||||||
private class Internal
|
private class Internal
|
||||||
def {{definition.name.id}}({{definition.args.splat}})
|
def {{name}}({{args.splat}})
|
||||||
{% if definition.block.is_a?(Nop) %}
|
{% if body && !body.is_a?(Nop) %}
|
||||||
{% if block.is_a?(Nop) %}
|
{{body.body}}
|
||||||
raise "Stubbed method called without being allowed"
|
|
||||||
{% else %}
|
|
||||||
{{block.body}}
|
|
||||||
{% end %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{definition.block.body}}
|
raise "Stubbed method called without being allowed"
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue