Support for canned responses in double creation

This commit is contained in:
Michael Miller 2019-11-11 22:17:37 -07:00
parent 73e3f8fd66
commit 9c161a07ff

View file

@ -1,9 +1,13 @@
require "../mocks" require "../mocks"
module Spectator::DSL module Spectator::DSL
macro double(name, &block) macro double(name, **stubs, &block)
{% if block.is_a?(Nop) %} {% if block.is_a?(Nop) %}
Double{{name.id}}.new Double{{name.id}}.new.tap do |%double|
{% for name, value in stubs %}
allow(%double).to receive({{name.id}}).and_return({{value}})
{% end %}
end
{% else %} {% else %}
class Double{{name.id}} < ::Spectator::Mocks::Double class Double{{name.id}} < ::Spectator::Mocks::Double
def initialize def initialize