mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add receive_messages macro to stub multiple methods
This commit is contained in:
parent
9c161a07ff
commit
20f68e956d
3 changed files with 21 additions and 0 deletions
|
@ -49,4 +49,13 @@ module Spectator::DSL
|
||||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||||
::Spectator::Mocks::NilMethodStub.new({{method_name.id.symbolize}}, %source)
|
::Spectator::Mocks::NilMethodStub.new({{method_name.id.symbolize}}, %source)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro receive_messages(_source_file = __FILE__, _source_line = __LINE__, **stubs)
|
||||||
|
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||||
|
%stubs = [] of ::Spectator::Mocks::MethodStub
|
||||||
|
{% for name, value in stubs %}
|
||||||
|
%stubs << ::Spectator::Mocks::ValueMethodStub.new({{name.id.symbolize}}, %source, {{value}})
|
||||||
|
{% end %}
|
||||||
|
%stubs
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,5 +8,11 @@ module Spectator::Mocks
|
||||||
def to(stub : MethodStub) : Nil
|
def to(stub : MethodStub) : Nil
|
||||||
Harness.current.mocks.add_stub(@mock, stub)
|
Harness.current.mocks.add_stub(@mock, stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to(stubs : Enumerable(MethodStub)) : Nil
|
||||||
|
stubs.each do |stub|
|
||||||
|
Harness.current.mocks.add_stub(@mock, stub)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,5 +5,11 @@ module Spectator::Mocks
|
||||||
def to(stub : MethodStub) : Nil
|
def to(stub : MethodStub) : Nil
|
||||||
Harness.current.mocks.add_type_stub(T, stub)
|
Harness.current.mocks.add_type_stub(T, stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to(stubs : Enumerable(MethodStub)) : Nil
|
||||||
|
stubs.each do |stub|
|
||||||
|
Harness.current.mocks.add_type_stub(T, stub)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue