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
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.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/test-runner/example_group.rb', line 13 def initialize(obj, config:, parent: nil, order: nil, &block) @obj = obj @config = config @parent = parent @order = order || @config.default_order @block = block @groups = [] @examples = [] @before = { context: [], example: [] } @after = { context: [], example: [] } end |
Instance Attribute Details
#examples ⇒ Array<Example> (readonly)
7 8 9 |
# File 'lib/test-runner/example_group.rb', line 7 def examples @examples end |
#groups ⇒ Array<ExampleGroup> (readonly)
4 5 6 |
# File 'lib/test-runner/example_group.rb', line 4 def groups @groups end |
Instance Method Details
#add_after(type, block) ⇒ Object
55 56 57 |
# File 'lib/test-runner/example_group.rb', line 55 def add_after(type, block) @after[type] << block end |
#add_before(type, block) ⇒ Object
49 50 51 |
# File 'lib/test-runner/example_group.rb', line 49 def add_before(type, block) @before[type] << block end |
#add_example(example) ⇒ Object
43 44 45 |
# File 'lib/test-runner/example_group.rb', line 43 def add_example(example) @examples << example end |
#add_group(group) ⇒ Object
38 39 40 |
# File 'lib/test-runner/example_group.rb', line 38 def add_group(group) @groups << group end |
#evaluate {|, evaluated| ... } ⇒ Array<ExampleResult>
62 63 64 65 66 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 |
# File 'lib/test-runner/example_group.rb', line 62 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
25 26 27 28 |
# File 'lib/test-runner/example_group.rb', line 25 def load @block.call @block = nil end |
#message ⇒ String
31 32 33 34 35 |
# File 'lib/test-runner/example_group.rb', line 31 def ret = [@obj.to_s] ret << @parent. if @parent ret.reverse.join(' ') end |
#sort_by_order(array) ⇒ Object (protected)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/test-runner/example_group.rb', line 100 def sort_by_order(array) case @order when :defined array when :rand array.shuffle when Random array.shuffle(random: @order) when Integer array.shuffle(random: Random.new(@order)) else raise "Invalid order #{@order.inspect}" end end |