mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Rename ContextDefinitions to GroupDefinitions
This commit is contained in:
parent
7968c5a394
commit
010b47ca1f
3 changed files with 22 additions and 21 deletions
|
@ -10,21 +10,21 @@ module Spectator
|
||||||
macro context(what, type = "Context", &block)
|
macro context(what, type = "Context", &block)
|
||||||
{%
|
{%
|
||||||
parent_module = @type
|
parent_module = @type
|
||||||
safe_name = what.id.stringify.chars.map { |c| ::Spectator::ContextDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
safe_name = what.id.stringify.chars.map { |c| ::Spectator::GroupDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
||||||
module_name = (type.id + safe_name.camelcase).id
|
module_name = (type.id + safe_name.camelcase).id
|
||||||
absolute_module_name = [parent_module, module_name].join("::").id
|
absolute_module_name = [parent_module, module_name].join("::").id
|
||||||
what_arg = what.is_a?(StringLiteral) ? what : what.stringify
|
what_arg = what.is_a?(StringLiteral) ? what : what.stringify
|
||||||
parent_given = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given]
|
parent_given = ::Spectator::GroupDefinitions::ALL[parent_module.id][:given]
|
||||||
|
|
||||||
::Spectator::ContextDefinitions::ALL[absolute_module_name] = {
|
::Spectator::GroupDefinitions::ALL[absolute_module_name] = {
|
||||||
name: module_name,
|
name: module_name,
|
||||||
parent: parent_module,
|
parent: parent_module,
|
||||||
given: parent_given.map { |e| e } # Duplicate elements without dup method.
|
given: parent_given.map { |e| e } # Duplicate elements without dup method.
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{absolute_module_name.stringify}}] =
|
::Spectator::GroupDefinitions::MAPPING[{{absolute_module_name.stringify}}] =
|
||||||
ExampleGroup.new({{what_arg}}, ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}])
|
ExampleGroup.new({{what_arg}}, ::Spectator::GroupDefinitions::MAPPING[{{parent_module.stringify}}])
|
||||||
|
|
||||||
module {{module_name.id}}
|
module {{module_name.id}}
|
||||||
include {{parent_module}}
|
include {{parent_module}}
|
||||||
|
@ -51,7 +51,7 @@ module Spectator
|
||||||
context({{collection}}, "Given") do
|
context({{collection}}, "Given") do
|
||||||
{%
|
{%
|
||||||
var_name = block.args.empty? ? "value".id : block.args.first
|
var_name = block.args.empty? ? "value".id : block.args.first
|
||||||
given_vars = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given]
|
given_vars = ::Spectator::GroupDefinitions::ALL[parent_module.id][:given]
|
||||||
if given_vars.find { |v| v[:name] == var_name.id }
|
if given_vars.find { |v| v[:name] == var_name.id }
|
||||||
raise "Duplicate given variable name \"#{var_name.id}\""
|
raise "Duplicate given variable name \"#{var_name.id}\""
|
||||||
end
|
end
|
||||||
|
@ -65,7 +65,7 @@ module Spectator
|
||||||
%collection.first
|
%collection.first
|
||||||
end
|
end
|
||||||
|
|
||||||
\{% ::Spectator::ContextDefinitions::ALL[@type.id][:given] << {name: "{{var_name}}".id, collection: "{{collection}}".id, type_def: (@type.id + ".{{var_name}}").id} %}
|
\{% ::Spectator::GroupDefinitions::ALL[@type.id][:given] << {name: "{{var_name}}".id, collection: "{{collection}}".id, type_def: (@type.id + ".{{var_name}}").id} %}
|
||||||
|
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
|
@ -98,23 +98,23 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
macro before_all(&block)
|
macro before_all(&block)
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].before_all_hooks << -> {{block}}
|
::Spectator::GroupDefinitions::MAPPING[{{@type.stringify}}].before_all_hooks << -> {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro before_each(&block)
|
macro before_each(&block)
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].before_each_hooks << -> {{block}}
|
::Spectator::GroupDefinitions::MAPPING[{{@type.stringify}}].before_each_hooks << -> {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro after_all(&block)
|
macro after_all(&block)
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].after_all_hooks << -> {{block}}
|
::Spectator::GroupDefinitions::MAPPING[{{@type.stringify}}].after_all_hooks << -> {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro after_each(&block)
|
macro after_each(&block)
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].after_each_hooks << -> {{block}}
|
::Spectator::GroupDefinitions::MAPPING[{{@type.stringify}}].after_each_hooks << -> {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro around_each(&block)
|
macro around_each(&block)
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].around_each_hooks << Proc(Proc(Nil), Nil).new {{block}}
|
::Spectator::GroupDefinitions::MAPPING[{{@type.stringify}}].around_each_hooks << Proc(Proc(Nil), Nil).new {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_examples
|
def include_examples
|
||||||
|
@ -124,9 +124,9 @@ module Spectator
|
||||||
macro it(description, &block)
|
macro it(description, &block)
|
||||||
{%
|
{%
|
||||||
parent_module = @type
|
parent_module = @type
|
||||||
safe_name = description.id.stringify.chars.map { |c| ::Spectator::ContextDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
safe_name = description.id.stringify.chars.map { |c| ::Spectator::GroupDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
||||||
class_name = (safe_name.camelcase + "Example").id
|
class_name = (safe_name.camelcase + "Example").id
|
||||||
given_vars = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given]
|
given_vars = ::Spectator::GroupDefinitions::ALL[parent_module.id][:given]
|
||||||
var_names = given_vars.map { |v| v[:name] }
|
var_names = given_vars.map { |v| v[:name] }
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%current_context = ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}]
|
%current_context = ::Spectator::GroupDefinitions::MAPPING[{{parent_module.stringify}}]
|
||||||
{% for given_var, i in given_vars %}
|
{% for given_var, i in given_vars %}
|
||||||
{%
|
{%
|
||||||
var_name = given_var[:name]
|
var_name = given_var[:name]
|
||||||
|
@ -185,9 +185,9 @@ module Spectator
|
||||||
macro pending(description, &block)
|
macro pending(description, &block)
|
||||||
{%
|
{%
|
||||||
parent_module = @type
|
parent_module = @type
|
||||||
safe_name = description.id.stringify.chars.map { |c| ::Spectator::ContextDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
safe_name = description.id.stringify.chars.map { |c| ::Spectator::GroupDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
||||||
class_name = (safe_name.camelcase + "Example").id
|
class_name = (safe_name.camelcase + "Example").id
|
||||||
given_vars = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given]
|
given_vars = ::Spectator::GroupDefinitions::ALL[parent_module.id][:given]
|
||||||
var_names = given_vars.map { |v| v[:name] }
|
var_names = given_vars.map { |v| v[:name] }
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%current_context = ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}]
|
%current_context = ::Spectator::GroupDefinitions::MAPPING[{{parent_module.stringify}}]
|
||||||
{% for given_var, i in given_vars %}
|
{% for given_var, i in given_vars %}
|
||||||
{%
|
{%
|
||||||
var_name = given_var[:name]
|
var_name = given_var[:name]
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
require "./dsl"
|
require "./dsl"
|
||||||
|
require "./group_definitions"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
module Examples
|
module Examples
|
||||||
include ::Spectator::DSL
|
include ::Spectator::DSL
|
||||||
|
|
||||||
{% ::Spectator::ContextDefinitions::ALL[@type.id] = {
|
{% ::Spectator::GroupDefinitions::ALL[@type.id] = {
|
||||||
name: "ROOT",
|
name: "ROOT",
|
||||||
parent: nil,
|
parent: nil,
|
||||||
given: [] of Object
|
given: [] of Object
|
||||||
} %}
|
} %}
|
||||||
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}] = ::Spectator::ExampleGroup::ROOT
|
::Spectator::GroupDefinitions::MAPPING[{{@type.stringify}}] = ::Spectator::ExampleGroup::ROOT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Spectator
|
module Spectator
|
||||||
module ContextDefinitions
|
module GroupDefinitions
|
||||||
ALL = {} of Path => Object
|
ALL = {} of Path => Object
|
||||||
MAPPING = {} of String => ExampleGroup
|
MAPPING = {} of String => ExampleGroup
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue