lib/opal/spec/example_group.rb in opal-spec-0.0.2 vs lib/opal/spec/example_group.rb in opal-spec-0.0.3
- old
+ new
@@ -3,20 +3,27 @@
@example_groups = []
def self.example_groups
@example_groups
end
+ @stack = []
def self.create desc, block
- @example_groups << self.new(desc, block)
+ group = self.new desc, @stack.last
+ @example_groups << group
+
+ @stack << group
+ group.instance_eval &block
+ @stack.pop
end
- def initialize desc, block
- @desc = desc
+ def initialize desc, parent
+ @desc = desc.to_s
+ @parent = parent
@examples = []
+
@before_hooks = []
- @after_hooks = []
- instance_eval &block
+ @after_hooks = []
end
def it desc, &block
@examples << Example.new(self, desc, block)
end
@@ -33,23 +40,23 @@
raise "unsupported after type: #{type}" unless type == :each
@after_hooks << block
end
def before_hooks
- @before_hooks
+ @parent ? @parent.before_hooks + @before_hooks : @before_hooks
end
def after_hooks
- @after_hooks
+ @parent ? @parent.after_hooks + @after_hooks : @after_hooks
end
def run runner
runner.example_group_started self
@examples.each { |example| example.run runner }
runner.example_group_finished self
end
def description
- @desc
+ @parent ? "#{@parent.description} #{@desc}" : @desc
end
end
end