mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move tags code to a common location
This commit is contained in:
parent
bd942bb644
commit
ba967218fa
4 changed files with 35 additions and 48 deletions
|
@ -5,6 +5,7 @@ require "./dsl/expectations"
|
||||||
require "./dsl/groups"
|
require "./dsl/groups"
|
||||||
require "./dsl/hooks"
|
require "./dsl/hooks"
|
||||||
require "./dsl/matchers"
|
require "./dsl/matchers"
|
||||||
|
require "./dsl/tags"
|
||||||
require "./dsl/top"
|
require "./dsl/top"
|
||||||
require "./dsl/values"
|
require "./dsl/values"
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require "../context"
|
require "../context"
|
||||||
require "../source"
|
require "../source"
|
||||||
require "./builder"
|
require "./builder"
|
||||||
|
require "./tags"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
# DSL methods for defining examples and test code.
|
# DSL methods for defining examples and test code.
|
||||||
module Examples
|
module Examples
|
||||||
|
include Tags
|
||||||
|
|
||||||
# Defines a macro to generate code for an example.
|
# Defines a macro to generate code for an example.
|
||||||
# The *name* is the name given to the macro.
|
# The *name* is the name given to the macro.
|
||||||
# TODO: Mark example as pending if block is omitted.
|
# TODO: Mark example as pending if block is omitted.
|
||||||
|
@ -64,29 +67,6 @@ module Spectator::DSL
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Defines a class method named *name* that combines tags
|
|
||||||
# returned by *source* with *tags* and *metadata*.
|
|
||||||
# Any falsey items from *metadata* are removed.
|
|
||||||
private macro _spectator_tags(name, source, *tags, **metadata)
|
|
||||||
def self.{{name.id}}
|
|
||||||
%tags = {{source.id}}
|
|
||||||
{% unless tags.empty? %}
|
|
||||||
%tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
|
||||||
{% end %}
|
|
||||||
{% for k, v in metadata %}
|
|
||||||
%cond = begin
|
|
||||||
{{v}}
|
|
||||||
end
|
|
||||||
if %cond
|
|
||||||
%tags.add({{k.id.symbolize}})
|
|
||||||
else
|
|
||||||
%tags.delete({{k.id.symbolize}})
|
|
||||||
end
|
|
||||||
{% end %}
|
|
||||||
%tags
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
define_example :example
|
define_example :example
|
||||||
|
|
||||||
define_example :it
|
define_example :it
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
require "../source"
|
require "../source"
|
||||||
require "./builder"
|
require "./builder"
|
||||||
|
require "./tags"
|
||||||
|
|
||||||
module Spectator::DSL
|
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
|
||||||
|
include Tags
|
||||||
|
|
||||||
macro define_example_group(name, *tags, **metadata)
|
macro define_example_group(name, *tags, **metadata)
|
||||||
# Defines a new example group.
|
# Defines a new example group.
|
||||||
# The *what* argument is a name or description of the group.
|
# The *what* argument is a name or description of the group.
|
||||||
|
@ -16,8 +19,8 @@ module Spectator::DSL
|
||||||
class Group\%group < \{{@type.id}}
|
class Group\%group < \{{@type.id}}
|
||||||
_spectator_group_subject(\{{what}})
|
_spectator_group_subject(\{{what}})
|
||||||
|
|
||||||
_spectator_tags_method(:tags, :super, {{tags.splat(", ")}} {{metadata.double_splat}})
|
_spectator_tags(:tags, :super, {{tags.splat(", ")}} {{metadata.double_splat}})
|
||||||
_spectator_tags_method(:tags, :previous_def, \{{tags.splat(", ")}} \{{metadata.double_splat}})
|
_spectator_tags(:tags, :previous_def, \{{tags.splat(", ")}} \{{metadata.double_splat}})
|
||||||
|
|
||||||
::Spectator::DSL::Builder.start_group(
|
::Spectator::DSL::Builder.start_group(
|
||||||
_spectator_group_name(\{{what}}),
|
_spectator_group_name(\{{what}}),
|
||||||
|
@ -84,29 +87,6 @@ module Spectator::DSL
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Defines a class method named *name* that combines tags
|
|
||||||
# returned by *source* with *tags* and *metadata*.
|
|
||||||
# Any falsey items from *metadata* are removed.
|
|
||||||
private macro _spectator_tags_method(name, source, *tags, **metadata)
|
|
||||||
def self.{{name.id}}
|
|
||||||
%tags = {{source.id}}
|
|
||||||
{% unless tags.empty? %}
|
|
||||||
%tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
|
||||||
{% end %}
|
|
||||||
{% for k, v in metadata %}
|
|
||||||
%cond = begin
|
|
||||||
{{v}}
|
|
||||||
end
|
|
||||||
if %cond
|
|
||||||
%tags.add({{k.id.symbolize}})
|
|
||||||
else
|
|
||||||
%tags.delete({{k.id.symbolize}})
|
|
||||||
end
|
|
||||||
{% end %}
|
|
||||||
%tags
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
define_example_group :example_group
|
define_example_group :example_group
|
||||||
|
|
||||||
define_example_group :describe
|
define_example_group :describe
|
||||||
|
|
26
src/spectator/dsl/tags.cr
Normal file
26
src/spectator/dsl/tags.cr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
module Spectator::DSL
|
||||||
|
module Tags
|
||||||
|
# Defines a class method named *name* that combines tags
|
||||||
|
# returned by *source* with *tags* and *metadata*.
|
||||||
|
# Any falsey items from *metadata* are removed.
|
||||||
|
private macro _spectator_tags(name, source, *tags, **metadata)
|
||||||
|
def self.{{name.id}}
|
||||||
|
%tags = {{source.id}}
|
||||||
|
{% unless tags.empty? %}
|
||||||
|
%tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
||||||
|
{% end %}
|
||||||
|
{% for k, v in metadata %}
|
||||||
|
%cond = begin
|
||||||
|
{{v}}
|
||||||
|
end
|
||||||
|
if %cond
|
||||||
|
%tags.add({{k.id.symbolize}})
|
||||||
|
else
|
||||||
|
%tags.delete({{k.id.symbolize}})
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
%tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue