Add receive_messages macro to stub multiple methods

This commit is contained in:
Michael Miller 2019-11-11 22:27:53 -07:00
parent 9c161a07ff
commit 20f68e956d
3 changed files with 21 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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