2018-10-14 23:10:12 +00:00
|
|
|
require "./example_group"
|
|
|
|
|
|
|
|
module Spectator
|
2018-11-20 21:04:14 +00:00
|
|
|
# A collection of examples and other example groups.
|
|
|
|
# This group can be nested under other groups.
|
2018-10-14 23:10:12 +00:00
|
|
|
class NestedExampleGroup < ExampleGroup
|
2018-11-20 21:04:14 +00:00
|
|
|
# Description from the user of the group's contents.
|
2019-02-17 23:27:41 +00:00
|
|
|
# This is a symbol when referencing a type.
|
2019-09-26 22:49:44 +00:00
|
|
|
getter description : Symbol | String
|
2018-10-14 23:10:12 +00:00
|
|
|
|
2019-09-26 22:23:13 +00:00
|
|
|
getter source : Source
|
|
|
|
|
2018-11-20 21:04:14 +00:00
|
|
|
# Group that this is nested in.
|
2018-10-15 00:00:55 +00:00
|
|
|
getter parent : ExampleGroup
|
2018-10-14 23:10:12 +00:00
|
|
|
|
2018-11-20 21:04:14 +00:00
|
|
|
# Creates a new example group.
|
2019-09-26 22:49:44 +00:00
|
|
|
# The *description* argument is a description from the user.
|
2019-02-18 06:01:43 +00:00
|
|
|
# The *parent* should contain this group.
|
2018-11-20 21:04:14 +00:00
|
|
|
# After creating this group, the parent's children should be updated.
|
|
|
|
# The parent's children must contain this group,
|
|
|
|
# otherwise there may be unexpected behavior.
|
2019-02-18 06:01:43 +00:00
|
|
|
# The *hooks* are stored to be triggered later.
|
2019-09-26 22:49:44 +00:00
|
|
|
def initialize(@description, @source, @parent, context)
|
2019-09-18 02:57:59 +00:00
|
|
|
super(context)
|
2018-10-14 23:10:12 +00:00
|
|
|
end
|
|
|
|
|
2019-02-17 23:27:41 +00:00
|
|
|
# Indicates wheter the group references a type.
|
2019-09-24 02:32:21 +00:00
|
|
|
def symbolic? : Bool
|
2019-09-26 22:49:44 +00:00
|
|
|
@description.is_a?(Symbol)
|
2019-02-17 23:27:41 +00:00
|
|
|
end
|
|
|
|
|
2018-11-20 21:04:14 +00:00
|
|
|
# Creates a string representation of the group.
|
2019-09-26 22:49:44 +00:00
|
|
|
# The string consists of `#description` appended to the parent.
|
2018-11-20 21:04:14 +00:00
|
|
|
# This results in a string like:
|
2019-02-18 06:01:43 +00:00
|
|
|
# ```text
|
|
|
|
# Foo#bar does something
|
|
|
|
# ```
|
2018-11-20 21:04:14 +00:00
|
|
|
# for the following structure:
|
|
|
|
# ```
|
|
|
|
# describe Foo do
|
|
|
|
# describe "#bar" do
|
|
|
|
# it "does something" do
|
|
|
|
# # ...
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# ```
|
2018-10-14 23:10:12 +00:00
|
|
|
def to_s(io)
|
2018-10-15 00:00:55 +00:00
|
|
|
parent.to_s(io)
|
2019-02-18 00:05:10 +00:00
|
|
|
io << ' ' unless (symbolic? || parent.is_a?(RootExampleGroup)) && parent.symbolic?
|
2019-09-26 22:49:44 +00:00
|
|
|
io << description
|
2018-10-14 23:10:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|