Bit of cleanup around parent/group

This commit is contained in:
Michael Miller 2021-05-08 12:10:27 -06:00
parent d7ba47cc49
commit ef7fca3f95
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 13 additions and 13 deletions

View file

@ -57,8 +57,8 @@ module Spectator
# The example will be assigned to *group* if it is provided.
# A set of *tags* can be used for filtering and modifying example behavior.
# Note: The tags will not be merged with the parent tags.
def initialize(name : String? = nil, location : Location? = nil, group : ExampleGroup? = nil,
tags = Tags.new, &block : self ->)
def initialize(name : String? = nil, location : Location? = nil,
@group : ExampleGroup? = nil, tags = Tags.new, &block : self ->)
super(name, location, tags)
@context = NullContext.new
@ -85,13 +85,13 @@ module Spectator
begin
@result = Harness.run do
group?.try(&.call_once_before_all)
if (parent = group?)
@group.try(&.call_once_before_all)
if (parent = @group)
parent.call_around_each(self) { run_internal }
else
run_internal
end
if (parent = group?)
if (parent = @group)
parent.call_once_after_all if parent.finished?
end
end
@ -144,14 +144,14 @@ module Spectator
name = @name
# Prefix with group's full name if the node belongs to a group.
if (group = @group)
group.to_s(io)
if (parent = @group)
parent.to_s(io)
# Add padding between the node names
# only if the names don't appear to be symbolic.
# Skip blank group names (like the root group).
io << ' ' unless !group.name? || # ameba:disable Style/NegatedConditionsInUnless
(group.name?.is_a?(Symbol) && name.is_a?(String) &&
io << ' ' unless !parent.name? || # ameba:disable Style/NegatedConditionsInUnless
(parent.name?.is_a?(Symbol) && name.is_a?(String) &&
(name.starts_with?('#') || name.starts_with?('.')))
end

View file

@ -124,14 +124,14 @@ module Spectator
name = @name
# Prefix with group's full name if the node belongs to a group.
if (group = @group)
group.to_s(io)
if (parent = @group)
parent.to_s(io)
# Add padding between the node names
# only if the names don't appear to be symbolic.
# Skip blank group names (like the root group).
io << ' ' unless !group.name? || # ameba:disable Style/NegatedConditionsInUnless
(group.name?.is_a?(Symbol) && name.is_a?(String) &&
io << ' ' unless !parent.name? || # ameba:disable Style/NegatedConditionsInUnless
(parent.name?.is_a?(Symbol) && name.is_a?(String) &&
(name.starts_with?('#') || name.starts_with?('.')))
end