mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Make derived double names safer
This commit is contained in:
parent
94e210c306
commit
f50e71606e
1 changed files with 8 additions and 6 deletions
|
@ -2,16 +2,17 @@ require "../mocks"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
macro double(name, **stubs, &block)
|
macro double(name, **stubs, &block)
|
||||||
|
{% safe_name = name.id.symbolize.gsub(/\W/, "_").id %}
|
||||||
{% if block.is_a?(Nop) %}
|
{% if block.is_a?(Nop) %}
|
||||||
Double{{name.id}}.new.tap do |%double|
|
Double{{safe_name}}.new.tap do |%double|
|
||||||
{% for name, value in stubs %}
|
{% for name, value in stubs %}
|
||||||
allow(%double).to receive({{name.id}}).and_return({{value}})
|
allow(%double).to receive({{name.id}}).and_return({{value}})
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
{% else %}
|
{% else %}
|
||||||
class Double{{name.id}} < ::Spectator::Mocks::Double
|
class Double{{safe_name}} < ::Spectator::Mocks::Double
|
||||||
def initialize(null = false)
|
def initialize(null = false)
|
||||||
super({{name.id.symbolize}}, null)
|
super({{name.id.stringify}}, null)
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_null_object
|
def as_null_object
|
||||||
|
@ -24,16 +25,17 @@ module Spectator::DSL
|
||||||
end
|
end
|
||||||
|
|
||||||
macro null_double(name, **stubs, &block)
|
macro null_double(name, **stubs, &block)
|
||||||
|
{% safe_name = name.id.symbolize.gsub(/\W/, "_").id %}
|
||||||
{% if block.is_a?(Nop) %}
|
{% if block.is_a?(Nop) %}
|
||||||
Double{{name.id}}.new(true).tap do |%double|
|
Double{{safe_name}}.new(true).tap do |%double|
|
||||||
{% for name, value in stubs %}
|
{% for name, value in stubs %}
|
||||||
allow(%double).to receive({{name.id}}).and_return({{value}})
|
allow(%double).to receive({{name.id}}).and_return({{value}})
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
{% else %}
|
{% else %}
|
||||||
class Double{{name.id}} < ::Spectator::Mocks::Double
|
class Double{{safe_name}} < ::Spectator::Mocks::Double
|
||||||
def initialize(null = true)
|
def initialize(null = true)
|
||||||
super({{name.id.symbolize}}, null)
|
super({{name.id.stringify}}, null)
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_null_object
|
def as_null_object
|
||||||
|
|
Loading…
Reference in a new issue