mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Mostly complete code for #given
This commit is contained in:
parent
3e7f43009f
commit
7c8be54e5c
2 changed files with 43 additions and 1 deletions
|
@ -10,10 +10,14 @@ module Spectator
|
||||||
{% safe_name = what.id.stringify.gsub(/\W+/, "_") %}
|
{% safe_name = what.id.stringify.gsub(/\W+/, "_") %}
|
||||||
{% module_name = (type.id + safe_name.camelcase).id %}
|
{% module_name = (type.id + safe_name.camelcase).id %}
|
||||||
{% context_module = CONTEXT_MODULE %}
|
{% context_module = CONTEXT_MODULE %}
|
||||||
|
{% parent_given_vars = GIVEN_VARIABLES %}
|
||||||
module {{module_name.id}}
|
module {{module_name.id}}
|
||||||
include ::Spectator::DSL
|
include ::Spectator::DSL
|
||||||
|
|
||||||
CONTEXT_MODULE = {{context_module.id}}::{{module_name.id}}
|
CONTEXT_MODULE = {{context_module.id}}::{{module_name.id}}
|
||||||
|
GIVEN_VARIABLES = [
|
||||||
|
{{ parent_given_vars.join(", ").id }}
|
||||||
|
]{% if parent_given_vars.empty? %} of Object{% end %}
|
||||||
|
|
||||||
module Locals
|
module Locals
|
||||||
include {{context_module.id}}::Locals
|
include {{context_module.id}}::Locals
|
||||||
|
@ -32,19 +36,42 @@ module Spectator
|
||||||
macro it(description, source_file = __FILE__, source_line = __LINE__, &block)
|
macro it(description, source_file = __FILE__, source_line = __LINE__, &block)
|
||||||
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %}
|
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %}
|
||||||
{% class_name = (safe_name.camelcase + "Example").id %}
|
{% class_name = (safe_name.camelcase + "Example").id %}
|
||||||
|
{% given_vars = GIVEN_VARIABLES %}
|
||||||
|
{% var_names = given_vars.map { |v| v[0] } %}
|
||||||
class {{class_name.id}} < ::Spectator::Example
|
class {{class_name.id}} < ::Spectator::Example
|
||||||
include Locals
|
include Locals
|
||||||
|
|
||||||
|
{% unless given_vars.empty? %}
|
||||||
|
def initialize({{ var_names.map { |v| "@#{v}" }.join(", ").id }})
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
|
||||||
def source
|
def source
|
||||||
Source.new({{source_file}}, {{source_line}})
|
Source.new({{source_file}}, {{source_line}})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def num
|
||||||
|
0
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new
|
{% if given_vars.empty? %}
|
||||||
|
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new
|
||||||
|
{% else %}
|
||||||
|
{% for given_var in given_vars %}
|
||||||
|
{% var_name = given_var[0] %}
|
||||||
|
{% collection = given_var[1] %}
|
||||||
|
{{collection}}.each do |{{var_name}}|
|
||||||
|
{% end %}
|
||||||
|
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new({{var_names.join(", ").id}})
|
||||||
|
{% for given_var in given_vars %}
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
def it_behaves_like
|
def it_behaves_like
|
||||||
|
@ -81,6 +108,20 @@ module Spectator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro given(collection, source_file = __FILE__, source_line = __LINE__, &block)
|
||||||
|
context({{collection}}, {{source_file}}, {{source_line}}, "Given") do
|
||||||
|
{% var_name = block.args.empty? ? "value" : block.args.first %}
|
||||||
|
|
||||||
|
module Locals
|
||||||
|
getter {{var_name.id}}
|
||||||
|
end
|
||||||
|
|
||||||
|
{% GIVEN_VARIABLES << {var_name, collection} %}
|
||||||
|
|
||||||
|
{{block.body}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def before_all
|
def before_all
|
||||||
raise NotImplementedError.new("Spectator::DSL#before_all")
|
raise NotImplementedError.new("Spectator::DSL#before_all")
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ module Spectator
|
||||||
include ::Spectator::DSL
|
include ::Spectator::DSL
|
||||||
|
|
||||||
CONTEXT_MODULE = ::Spectator::Examples
|
CONTEXT_MODULE = ::Spectator::Examples
|
||||||
|
GIVEN_VARIABLES = [] of Object
|
||||||
|
|
||||||
module Locals
|
module Locals
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue