mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add as_null_object method
This commit is contained in:
parent
5d21e4bb71
commit
99aa8afdce
2 changed files with 156 additions and 4 deletions
|
@ -11,14 +11,23 @@ module Spectator::DSL
|
|||
private macro def_double(name, **value_methods, &block)
|
||||
{% # Construct a unique type name for the double by using the number of defined doubles.
|
||||
index = ::Spectator::DSL::Mocks::DOUBLES.size
|
||||
double_type_name = "Double#{index}".id.symbolize
|
||||
double_type_name = "Double#{index}".id
|
||||
null_double_type_name = "NullDouble#{index}".id
|
||||
|
||||
# Store information about how the double is defined and its context.
|
||||
# This is important for constructing an instance of the double later.
|
||||
::Spectator::DSL::Mocks::DOUBLES << {name.id.symbolize, @type.name(generic_args: false).symbolize, double_type_name} %}
|
||||
|
||||
::Spectator::DSL::Mocks::DOUBLES << {name.id.symbolize, @type.name(generic_args: false).symbolize, double_type_name.symbolize} %}
|
||||
|
||||
::Spectator::Double.define({{double_type_name}}, {{name}}, {{**value_methods}}) do
|
||||
def as_null_object
|
||||
{{null_double_type_name}}.new(@stubs)
|
||||
end
|
||||
|
||||
{% if block %}{{block.body}}{% end %}
|
||||
end
|
||||
|
||||
{% begin %}
|
||||
::Spectator::Double.define({{double_type_name}}, {{name}}, {{**value_methods}}){% if block %} do
|
||||
::Spectator::NullDouble.define({{null_double_type_name}}, {{name}}, {{**value_methods}}){% if block %} do
|
||||
{{block.body}}
|
||||
end{% end %}
|
||||
{% end %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue