mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Pass context to examples
This commit is contained in:
parent
2ff8ebb3cb
commit
a725c0d5be
3 changed files with 23 additions and 6 deletions
|
@ -2,6 +2,7 @@ require "./example"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
class Context
|
class Context
|
||||||
|
getter parent : Context?
|
||||||
getter examples = [] of Example
|
getter examples = [] of Example
|
||||||
getter contexts = [] of Context
|
getter contexts = [] of Context
|
||||||
getter before_all_hooks = [] of ->
|
getter before_all_hooks = [] of ->
|
||||||
|
@ -10,6 +11,12 @@ module Spectator
|
||||||
getter after_each_hooks = [] of ->
|
getter after_each_hooks = [] of ->
|
||||||
getter around_each_hooks = [] of Example ->
|
getter around_each_hooks = [] of Example ->
|
||||||
|
|
||||||
|
def initialize(@parent = nil)
|
||||||
|
if (parent = @parent)
|
||||||
|
parent.contexts << self
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def all_examples
|
def all_examples
|
||||||
add_examples
|
add_examples
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,8 +14,8 @@ module Spectator
|
||||||
module {{module_name.id}}
|
module {{module_name.id}}
|
||||||
include ::Spectator::DSL
|
include ::Spectator::DSL
|
||||||
|
|
||||||
CURRENT_CONTEXT = ::Spectator::Context.new
|
PARENT_CONTEXT = {{context_module.id}}::CURRENT_CONTEXT
|
||||||
{{context_module.id}}::CURRENT_CONTEXT.contexts << CURRENT_CONTEXT
|
CURRENT_CONTEXT = ::Spectator::Context.new(PARENT_CONTEXT)
|
||||||
|
|
||||||
CONTEXT_MODULE = {{context_module.id}}::{{module_name.id}}
|
CONTEXT_MODULE = {{context_module.id}}::{{module_name.id}}
|
||||||
GIVEN_VARIABLES = [
|
GIVEN_VARIABLES = [
|
||||||
|
@ -44,8 +44,13 @@ module Spectator
|
||||||
class {{class_name.id}} < ::Spectator::Example
|
class {{class_name.id}} < ::Spectator::Example
|
||||||
include Locals
|
include Locals
|
||||||
|
|
||||||
{% unless given_vars.empty? %}
|
{% if given_vars.empty? %}
|
||||||
def initialize({{ var_names.join(", ").id }})
|
def initialize(context)
|
||||||
|
super(context)
|
||||||
|
end
|
||||||
|
{% else %}
|
||||||
|
def initialize(context, {{ var_names.join(", ").id }})
|
||||||
|
super(context)
|
||||||
{% for var_name in var_names %}
|
{% for var_name in var_names %}
|
||||||
self.{{var_name}} = {{var_name}}
|
self.{{var_name}} = {{var_name}}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
@ -58,14 +63,14 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
{% if given_vars.empty? %}
|
{% if given_vars.empty? %}
|
||||||
CURRENT_CONTEXT.examples << {{class_name.id}}.new
|
CURRENT_CONTEXT.examples << {{class_name.id}}.new(CURRENT_CONTEXT)
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for given_var in given_vars %}
|
{% for given_var in given_vars %}
|
||||||
{% var_name = given_var[0] %}
|
{% var_name = given_var[0] %}
|
||||||
{% collection = given_var[1] %}
|
{% collection = given_var[1] %}
|
||||||
{{collection}}.each do |{{var_name}}|
|
{{collection}}.each do |{{var_name}}|
|
||||||
{% end %}
|
{% end %}
|
||||||
CURRENT_CONTEXT.examples << {{class_name.id}}.new({{var_names.join(", ").id}})
|
CURRENT_CONTEXT.examples << {{class_name.id}}.new(CURRENT_CONTEXT, {{var_names.join(", ").id}})
|
||||||
{% for given_var in given_vars %}
|
{% for given_var in given_vars %}
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
|
@ -2,6 +2,11 @@ require "./source"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
abstract class Example
|
abstract class Example
|
||||||
|
getter context : Context
|
||||||
|
|
||||||
|
def initialize(@context)
|
||||||
|
end
|
||||||
|
|
||||||
macro is_expected
|
macro is_expected
|
||||||
expect(subject)
|
expect(subject)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue