Class: TestRunner::ExampleGroup
- Inherits:
-
Object
- Object
- TestRunner::ExampleGroup
- Defined in:
- lib/test-runner/example_group.rb
Instance Attribute Summary collapse
- #examples ⇒ Array<Example> readonly
- #groups ⇒ Array<ExampleGroup> readonly
- #order ⇒ nil, ... readonly
Instance Method Summary collapse
- #add_after(type, block) ⇒ Object
- #add_before(type, block) ⇒ Object
- #add_example(example) ⇒ Object
- #add_group(group) ⇒ Object
- #evaluate {|, evaluated| ... } ⇒ Array<ExampleResult>
-
#initialize(obj, config:, parent: nil, order: nil, &block) ⇒ ExampleGroup
constructor
A new instance of ExampleGroup.
- #load ⇒ Object
- #message ⇒ String
- #sort_by_order(array) ⇒ Object protected
Constructor Details
#initialize(obj, config:, parent: nil, order: nil, &block) ⇒ ExampleGroup
Returns a new instance of ExampleGroup.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/test-runner/example_group.rb', line 18 def initialize(obj, config:, parent: nil, order: nil, &block) @obj = obj @config = config @parent = parent @order = order || parent&.order || @config.default_order @block = block @groups = [] @examples = [] @before = { context: [], example: [] } @after = { context: [], example: [] } end |
Instance Attribute Details
#examples ⇒ Array<Example> (readonly)
9 10 11 |
# File 'lib/test-runner/example_group.rb', line 9 def examples @examples end |
#groups ⇒ Array<ExampleGroup> (readonly)
6 7 8 |
# File 'lib/test-runner/example_group.rb', line 6 def groups @groups end |
#order ⇒ nil, ... (readonly)
12 13 14 |
# File 'lib/test-runner/example_group.rb', line 12 def order @order end |
Instance Method Details
#add_after(type, block) ⇒ Object
60 61 62 |
# File 'lib/test-runner/example_group.rb', line 60 def add_after(type, block) @after[type] << block end |
#add_before(type, block) ⇒ Object
54 55 56 |
# File 'lib/test-runner/example_group.rb', line 54 def add_before(type, block) @before[type] << block end |
#add_example(example) ⇒ Object
48 49 50 |
# File 'lib/test-runner/example_group.rb', line 48 def add_example(example) @examples << example end |
#add_group(group) ⇒ Object
43 44 45 |
# File 'lib/test-runner/example_group.rb', line 43 def add_group(group) @groups << group end |
#evaluate {|, evaluated| ... } ⇒ Array<ExampleResult>
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/test-runner/example_group.rb', line 67 def evaluate(&block) results = [] @before[:context].each(&:call) sort_by_order(examples).each do |example| next if example.skip? # before hooks @before[:example].each(&:call) # before-progress hook block.call(:before, example) if block # evaluation result = example.evaluate # after-progress hook block.call(:after, result) if block # store result results << result # after hooks @after[:example].each(&:call) end sort_by_order(groups).each do |grp| results.concat(grp.evaluate(&block)) end @after[:context].each(&:call) results end |
#load ⇒ Object
30 31 32 33 |
# File 'lib/test-runner/example_group.rb', line 30 def load @block.call @block = nil end |
#message ⇒ String
36 37 38 39 40 |
# File 'lib/test-runner/example_group.rb', line 36 def ret = [@obj.to_s] ret << @parent. if @parent ret.reverse.join(' ') end |
#sort_by_order(array) ⇒ Object (protected)
105 106 107 |
# File 'lib/test-runner/example_group.rb', line 105 def sort_by_order(array) ExampleOrdering.sort_by_order(array, @order) end |