mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove Locals sub-module
This allows for seamless helper methods.
This commit is contained in:
parent
718be70edd
commit
9b07f669ed
3 changed files with 36 additions and 47 deletions
|
@ -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`
|
||||||
|
|
|
@ -24,22 +24,20 @@ 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
|
||||||
{{what}}.tap do |thing|
|
{{what}}.tap do |thing|
|
||||||
raise "#{thing} must be a type name to use #described_class or #subject,\
|
raise "#{thing} must be a type name to use #described_class or #subject,\
|
||||||
but it is a #{typeof(thing)}" unless thing.is_a?(Class)
|
but it is a #{typeof(thing)}" unless thing.is_a?(Class)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def subject
|
def subject
|
||||||
described_class.new
|
described_class.new
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
|
||||||
|
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
|
@ -54,25 +52,23 @@ 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
|
||||||
{{collection}}
|
{{collection}}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def %collection_first
|
private def %collection_first
|
||||||
%collection.first
|
%collection.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{var_name.id}}
|
def {{var_name.id}}
|
||||||
@%wrapper.as(TypedValueWrapper(typeof(%collection_first))).value
|
@%wrapper.as(TypedValueWrapper(typeof(%collection_first))).value
|
||||||
end
|
end
|
||||||
|
|
||||||
{% setter = "_set_#{var_name.id}".id %}
|
{% setter = "_set_#{var_name.id}".id %}
|
||||||
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,26 +84,22 @@ 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}}
|
||||||
if (wrapper = @%wrapper)
|
if (wrapper = @%wrapper)
|
||||||
wrapper.as(TypedValueWrapper(typeof(%value))).value
|
wrapper.as(TypedValueWrapper(typeof(%value))).value
|
||||||
else
|
else
|
||||||
%value.tap do |value|
|
%value.tap do |value|
|
||||||
@%wrapper = TypedValueWrapper(typeof(%value)).new(value)
|
@%wrapper = TypedValueWrapper(typeof(%value)).new(value)
|
||||||
end
|
|
||||||
end
|
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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue