mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Nested macros for defining DSL keywords
This commit is contained in:
parent
9103bfde0f
commit
6363436afa
2 changed files with 22 additions and 41 deletions
|
@ -18,35 +18,11 @@ module Spectator::DSL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
define_example(:example)
|
define_example :example
|
||||||
|
|
||||||
macro it(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
define_example :it
|
||||||
{% puts "#{_source_file}:#{_source_line}" %}
|
|
||||||
def %test
|
|
||||||
{{yield}}
|
|
||||||
end
|
|
||||||
|
|
||||||
%source = ::Spectator::Source.new(__FILE__, __LINE__)
|
define_example :specify
|
||||||
::Spectator::DSL::Builder.add_example(
|
|
||||||
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
|
|
||||||
%source,
|
|
||||||
{{@type.name}}.new
|
|
||||||
) { |example, context| context.as({{@type.name}}).%test }
|
|
||||||
end
|
|
||||||
|
|
||||||
macro specify(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
|
||||||
{% puts "#{_source_file}:#{_source_line}" %}
|
|
||||||
def %test
|
|
||||||
{{yield}}
|
|
||||||
end
|
|
||||||
|
|
||||||
%source = ::Spectator::Source.new(__FILE__, __LINE__)
|
|
||||||
::Spectator::DSL::Builder.add_example(
|
|
||||||
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
|
|
||||||
%source,
|
|
||||||
{{@type.name}}.new
|
|
||||||
) { |example, context| context.as({{@type.name}}).%test }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
{% if block.is_a?(Nop) %}
|
{% if block.is_a?(Nop) %}
|
||||||
|
|
|
@ -5,25 +5,30 @@ module Spectator::DSL
|
||||||
# DSL methods and macros for creating example groups.
|
# DSL methods and macros for creating example groups.
|
||||||
# This module should be included as a mix-in.
|
# This module should be included as a mix-in.
|
||||||
module Groups
|
module Groups
|
||||||
# Defines a new example group.
|
macro define_example_group(name)
|
||||||
# The *what* argument is a name or description of the group.
|
# Defines a new example group.
|
||||||
# If it isn't a string literal, then it is symbolized for `ExampleNode#name`.
|
# The *what* argument is a name or description of the group.
|
||||||
|
# If it isn't a string literal, then it is symbolized for `ExampleNode#name`.
|
||||||
|
macro {{name.id}}(what, &block)
|
||||||
|
class Group%group < \{{@type.id}}; _spectator_group_subject(\{{what}})
|
||||||
|
# TODO: Handle string interpolation in examples and groups.
|
||||||
|
::Spectator::DSL::Builder.start_group(
|
||||||
|
\{{what.is_a?(StringLiteral) ? what : what.stringify}},
|
||||||
|
::Spectator::Source.new(__FILE__, __LINE__)
|
||||||
|
)
|
||||||
|
|
||||||
|
\{{block.body}}
|
||||||
|
|
||||||
# Example group: {{what.stringify}}
|
::Spectator::DSL::Builder.end_group
|
||||||
# Source: {{_source_file}}:{{_source_line}}
|
end
|
||||||
macro example_group(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
end
|
||||||
class Group%group < {{@type.id}}; _spectator_group_subject({{what}}); ::Spectator::DSL::Builder.start_group({{what.is_a?(StringLiteral) ? what : what.stringify}}, ::Spectator::Source.new(__FILE__, __LINE__)); {{block.body}}; ::Spectator::DSL::Builder.end_group; end
|
|
||||||
{% debug(false) %}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
macro describe(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
define_example_group :example_group
|
||||||
example_group({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
|
|
||||||
end
|
|
||||||
|
|
||||||
macro context(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
|
define_example_group :describe
|
||||||
example_group({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
|
|
||||||
end
|
define_example_group :context
|
||||||
|
|
||||||
# Defines the implicit subject for the test context.
|
# Defines the implicit subject for the test context.
|
||||||
# If *what* is a type, then the `described_class` method will be defined.
|
# If *what* is a type, then the `described_class` method will be defined.
|
||||||
|
|
Loading…
Reference in a new issue