mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use block to create examples
Seems that nodes can't be duped/cloned easily.
This commit is contained in:
parent
4ff27defff
commit
1f91836de1
3 changed files with 21 additions and 7 deletions
|
@ -93,6 +93,13 @@ module Spectator
|
|||
group << self if group
|
||||
end
|
||||
|
||||
# Creates a child that is attched to the group.
|
||||
# Yields zero or more times to create the child.
|
||||
# The group the child should be attached to is provided as a block argument.
|
||||
def create_child
|
||||
yield self
|
||||
end
|
||||
|
||||
# Removes the specified *node* from the group.
|
||||
# The node will be unassigned from this group.
|
||||
def delete(node : Node)
|
||||
|
|
|
@ -19,6 +19,13 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
# Creates a child that is attched to the group.
|
||||
# Yields zero or more times to create the child.
|
||||
# The group the child should be attached to is provided as a block argument.
|
||||
def create_child
|
||||
@nodes.each { |child| yield child.as(Iteration(T)) }
|
||||
end
|
||||
|
||||
# Adds the specified *node* to the group.
|
||||
# Assigns the node to this group.
|
||||
# If the node already belongs to a group,
|
||||
|
|
|
@ -119,12 +119,11 @@ module Spectator
|
|||
# It will be yielded two arguments - the example created by this method, and the *context* argument.
|
||||
# The return value of the block is ignored.
|
||||
# It is expected that the test code runs when the block is called.
|
||||
#
|
||||
# The newly created example is returned.
|
||||
def add_example(name, location, context, metadata = Metadata.new, &block : Example -> _) : Example
|
||||
def add_example(name, location, context, metadata = Metadata.new, &block : Example -> _)
|
||||
Log.trace { "Add example: #{name} @ #{location}; metadata: #{metadata}" }
|
||||
Example.new(context, block, name, location, current_group, metadata)
|
||||
# The example is added to the current group by `Example` initializer.
|
||||
current_group.create_child do |group|
|
||||
Example.new(context, block, name, location, group, metadata)
|
||||
end
|
||||
end
|
||||
|
||||
# Defines a new pending example.
|
||||
|
@ -143,8 +142,9 @@ module Spectator
|
|||
# The newly created example is returned.
|
||||
def add_pending_example(name, location, metadata = Metadata.new, reason = nil) : Example
|
||||
Log.trace { "Add pending example: #{name} @ #{location}; metadata: #{metadata}" }
|
||||
Example.pending(name, location, current_group, metadata, reason)
|
||||
# The example is added to the current group by `Example` initializer.
|
||||
current_group.create_child do |group|
|
||||
Example.pending(name, location, group, metadata, reason)
|
||||
end
|
||||
end
|
||||
|
||||
# Attaches a hook to be invoked before any and all examples in the current group.
|
||||
|
|
Loading…
Reference in a new issue