mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow receive block syntax
This commit is contained in:
parent
b062472d98
commit
27acf7bced
2 changed files with 10 additions and 2 deletions
|
@ -126,9 +126,13 @@ module Spectator::DSL
|
|||
::Spectator::Mocks::ExpectAnyInstance({{type}}).new(%source)
|
||||
end
|
||||
|
||||
macro receive(method_name, _source_file = __FILE__, _source_line = __LINE__)
|
||||
macro receive(method_name, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||
::Spectator::Mocks::NilMethodStub.new({{method_name.id.symbolize}}, %source)
|
||||
{% if block.is_a?(Nop) %}
|
||||
::Spectator::Mocks::NilMethodStub.new({{method_name.id.symbolize}}, %source)
|
||||
{% else %}
|
||||
::Spectator::Mocks::ProcMethodStub.create({{method_name.id.symbolize}}, %source) { {{block.body}} }
|
||||
{% end %}
|
||||
end
|
||||
|
||||
macro receive_messages(_source_file = __FILE__, _source_line = __LINE__, **stubs)
|
||||
|
|
|
@ -7,6 +7,10 @@ module Spectator::Mocks
|
|||
super(name, source, args)
|
||||
end
|
||||
|
||||
def self.create(name, source, args = nil, &block : -> T) forall T
|
||||
ProcMethodStub.new(name, source, block, args)
|
||||
end
|
||||
|
||||
def call(_args : GenericArguments(T2, NT2), rt : RT.class) forall T2, NT2, RT
|
||||
@proc.call
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue