Remove Locals sub-module

This allows for seamless helper methods.
This commit is contained in:
Michael Miller 2018-09-12 19:16:41 -06:00
parent 718be70edd
commit 9b07f669ed
3 changed files with 36 additions and 47 deletions

View file

@ -93,7 +93,7 @@ In no particular order, features that have been implemented and are planned:
- [ ] Before and after hooks - `before_each`, `before_all`, `after_each`, `after_all`, `around_each` - [ ] Before and after hooks - `before_each`, `before_all`, `after_each`, `after_all`, `around_each`
- [ ] One-liner syntax - [ ] One-liner syntax
- [ ] Should syntax - [ ] Should syntax
- [ ] Helper methods and modules - [X] Helper methods and modules
- [ ] Aliasing - custom example group types with preset attributes - [ ] Aliasing - custom example group types with preset attributes
- [ ] Pending tests - `pending` - [ ] Pending tests - `pending`
- [ ] Shared examples - `behaves_like`, `include_examples` - [ ] Shared examples - `behaves_like`, `include_examples`

View file

@ -24,8 +24,7 @@ module Spectator
} %} } %}
::Spectator::ContextDefinitions::MAPPING[{{absolute_module_name.stringify}}] = Context.new({{what_arg}}, ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}]) ::Spectator::ContextDefinitions::MAPPING[{{absolute_module_name.stringify}}] = Context.new({{what_arg}}, ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}])
module Locals include {{parent_module}}
include {{parent_module}}::Locals
{% if what.is_a?(Path) || what.is_a?(Generic) %} {% if what.is_a?(Path) || what.is_a?(Generic) %}
def described_class def described_class
@ -39,7 +38,6 @@ module Spectator
described_class.new described_class.new
end end
{% end %} {% end %}
end
{{block.body}} {{block.body}}
end end
@ -54,7 +52,6 @@ module Spectator
{% raise "Duplicate given variable name \"#{var_name.id}\"" %} {% raise "Duplicate given variable name \"#{var_name.id}\"" %}
{% end %} {% end %}
module Locals
@%wrapper : ValueWrapper? @%wrapper : ValueWrapper?
private def %collection private def %collection
@ -73,7 +70,6 @@ module Spectator
private def {{setter}}(value) private def {{setter}}(value)
@%wrapper = TypedValueWrapper(typeof(%collection_first)).new(value) @%wrapper = TypedValueWrapper(typeof(%collection_first)).new(value)
end end
end
\{% ::Spectator::ContextDefinitions::ALL[@type.id][:given] << {name: "{{var_name}}".id, collection: "{{collection}}".id, setter: "{{setter}}".id} %} \{% ::Spectator::ContextDefinitions::ALL[@type.id][:given] << {name: "{{var_name}}".id, collection: "{{collection}}".id, setter: "{{setter}}".id} %}
@ -88,7 +84,6 @@ module Spectator
macro let(name, &block) macro let(name, &block)
let!(%value) {{block}} let!(%value) {{block}}
module Locals
@%wrapper : ValueWrapper? @%wrapper : ValueWrapper?
def {{name.id}} def {{name.id}}
@ -101,15 +96,12 @@ module Spectator
end end
end end
end end
end
macro let!(name, &block) macro let!(name, &block)
module Locals
def {{name.id}} def {{name.id}}
{{block.body}} {{block.body}}
end end
end end
end
macro before_all(&block) macro before_all(&block)
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].before_all_hooks << -> {{block}} ::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}].before_all_hooks << -> {{block}}
@ -143,7 +135,7 @@ module Spectator
{% var_names = given_vars.map { |v| v[:name] } %} {% var_names = given_vars.map { |v| v[:name] } %}
class Example%example class Example%example
include ExampleDSL include ExampleDSL
include Locals include {{parent_module}}
def %run({{ var_names.join(", ").id }}) def %run({{ var_names.join(", ").id }})
{{block.body}} {{block.body}}
@ -151,7 +143,7 @@ module Spectator
end end
class {{class_name.id}} < ::Spectator::Example class {{class_name.id}} < ::Spectator::Example
include Locals include {{parent_module}}
{% if given_vars.empty? %} {% if given_vars.empty? %}
def initialize(context) def initialize(context)

View file

@ -10,8 +10,5 @@ module Spectator
given: [] of Object given: [] of Object
} %} } %}
::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}] = ::Spectator::Context::ROOT ::Spectator::ContextDefinitions::MAPPING[{{@type.stringify}}] = ::Spectator::Context::ROOT
module Locals
end
end end
end end