Use block to create examples
Seems that nodes can't be duped/cloned easily.
This commit is contained in:
parent
4ff27defff
commit
1f91836de1
|
@ -93,6 +93,13 @@ module Spectator
|
||||||
group << self if group
|
group << self if group
|
||||||
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
|
||||||
|
yield self
|
||||||
|
end
|
||||||
|
|
||||||
# Removes the specified *node* from the group.
|
# Removes the specified *node* from the group.
|
||||||
# The node will be unassigned from this group.
|
# The node will be unassigned from this group.
|
||||||
def delete(node : Node)
|
def delete(node : Node)
|
||||||
|
|
|
@ -19,6 +19,13 @@ module Spectator
|
||||||
end
|
end
|
||||||
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.
|
# Adds the specified *node* to the group.
|
||||||
# Assigns the node to this group.
|
# Assigns the node to this group.
|
||||||
# If the node already belongs to a 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.
|
# It will be yielded two arguments - the example created by this method, and the *context* argument.
|
||||||
# The return value of the block is ignored.
|
# The return value of the block is ignored.
|
||||||
# It is expected that the test code runs when the block is called.
|
# It is expected that the test code runs when the block is called.
|
||||||
#
|
def add_example(name, location, context, metadata = Metadata.new, &block : Example -> _)
|
||||||
# The newly created example is returned.
|
|
||||||
def add_example(name, location, context, metadata = Metadata.new, &block : Example -> _) : Example
|
|
||||||
Log.trace { "Add example: #{name} @ #{location}; metadata: #{metadata}" }
|
Log.trace { "Add example: #{name} @ #{location}; metadata: #{metadata}" }
|
||||||
Example.new(context, block, name, location, current_group, metadata)
|
current_group.create_child do |group|
|
||||||
# The example is added to the current group by `Example` initializer.
|
Example.new(context, block, name, location, group, metadata)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Defines a new pending example.
|
# Defines a new pending example.
|
||||||
|
@ -143,8 +142,9 @@ module Spectator
|
||||||
# The newly created example is returned.
|
# The newly created example is returned.
|
||||||
def add_pending_example(name, location, metadata = Metadata.new, reason = nil) : Example
|
def add_pending_example(name, location, metadata = Metadata.new, reason = nil) : Example
|
||||||
Log.trace { "Add pending example: #{name} @ #{location}; metadata: #{metadata}" }
|
Log.trace { "Add pending example: #{name} @ #{location}; metadata: #{metadata}" }
|
||||||
Example.pending(name, location, current_group, metadata, reason)
|
current_group.create_child do |group|
|
||||||
# The example is added to the current group by `Example` initializer.
|
Example.pending(name, location, group, metadata, reason)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Attaches a hook to be invoked before any and all examples in the current group.
|
# Attaches a hook to be invoked before any and all examples in the current group.
|
||||||
|
|
Loading…
Reference in New Issue