mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add ability to define default stub for mocks
This commit is contained in:
parent
eb1a99b3ab
commit
4fea5ea435
1 changed files with 10 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
module Spectator::Mocks
|
||||
module Stubs
|
||||
private macro stub(definition, &block)
|
||||
private macro stub(definition, _file = __FILE__, _line = __LINE__, &block)
|
||||
{%
|
||||
name = nil
|
||||
params = nil
|
||||
|
@ -33,6 +33,15 @@ module Spectator::Mocks
|
|||
end.id
|
||||
%}
|
||||
|
||||
{% if body && !body.is_a?(Nop) %}
|
||||
%source = ::Spectator::Source.new({{_file}}, {{_line}})
|
||||
%proc = ->{
|
||||
{{body.body}}
|
||||
}
|
||||
%ds = ::Spectator::Mocks::ProcMethodStub.new({{name.symbolize}}, %source, %proc)
|
||||
::Spectator::SpecBuilder.add_default_stub({{@type.name}}, %ds)
|
||||
{% 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}})
|
||||
|
|
Loading…
Reference in a new issue