Class: DohTest::GroupRunner
- Inherits:
-
Object
- Object
- DohTest::GroupRunner
- Defined in:
- lib/dohtest/group_runner.rb
Instance Method Summary collapse
- #assertion_passed ⇒ Object
- #caught_error(error, test_name = nil) ⇒ Object
- #create_group ⇒ Object
- #determine_test_methods ⇒ Object
- #find_after_each_method ⇒ Object
- #find_before_each_method ⇒ Object
-
#initialize(group_class, output, config = nil) ⇒ GroupRunner
constructor
A new instance of GroupRunner.
- #past_brink? ⇒ Boolean
- #run ⇒ Object
- #run_after_all ⇒ Object
- #run_after_each ⇒ Object
- #run_before_all ⇒ Object
- #run_before_each ⇒ Object
- #run_test_method ⇒ Object
- #run_tests ⇒ Object
- #setup_brink ⇒ Object
- #total_problems ⇒ Object
Constructor Details
#initialize(group_class, output, config = nil) ⇒ GroupRunner
Returns a new instance of GroupRunner.
6 7 8 9 10 11 12 13 |
# File 'lib/dohtest/group_runner.rb', line 6 def initialize(group_class, output, config = nil) @group_class,@output = group_class,output @config = config || {} @group_name = @group_class.to_s @before_all_failed = false @error_count = @tests_ran = @tests_skipped = @assertions_failed = @assertions_passed = 0 @test_name = 'no_test_name_set_yet' end |
Instance Method Details
#assertion_passed ⇒ Object
149 150 151 152 |
# File 'lib/dohtest/group_runner.rb', line 149 def assertion_passed @assertions_passed += 1 @output.assertion_passed(@group_name, @test_name) end |
#caught_error(error, test_name = nil) ⇒ Object
154 155 156 157 |
# File 'lib/dohtest/group_runner.rb', line 154 def caught_error(error, test_name = nil) @error_count += 1 @output.test_error(@group_name, test_name || @test_name, error) end |
#create_group ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/dohtest/group_runner.rb', line 26 def create_group @group = @group_class.new rescue => error caught_error(error, 'initialize') false else @group.runner = self true end |
#determine_test_methods ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/dohtest/group_runner.rb', line 140 def determine_test_methods @test_methods = @group_class.public_instance_methods.grep(/^test/) return unless @config.key?(:grep) original_test_count = @test_methods.size grep_filter = Regexp.new(@config[:grep]) @test_methods.select! { |method| method.to_s =~ grep_filter } @tests_skipped = original_test_count - @test_methods.size end |
#find_after_each_method ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dohtest/group_runner.rb', line 75 def find_after_each_method has_after_each = @group.respond_to?(:after_each) has_teardown = @group.respond_to?(:teardown) if has_after_each && has_teardown raise ":after_each and :teardown both defined; please pick one" elsif has_after_each @after_each_method = :after_each elsif has_teardown @after_each_method = :teardown else @after_each_method = nil end end |
#find_before_each_method ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dohtest/group_runner.rb', line 61 def find_before_each_method has_before_each = @group.respond_to?(:before_each) has_setup = @group.respond_to?(:setup) if has_before_each && has_setup raise ":before_each and :setup both defined; please pick one" elsif has_before_each @before_each_method = :before_each elsif has_setup @before_each_method = :setup else @before_each_method = nil end end |
#past_brink? ⇒ Boolean
117 118 119 |
# File 'lib/dohtest/group_runner.rb', line 117 def past_brink? (@max_errors && (@error_count > @max_errors)) || (@max_failures && (@assertions_failed > @max_failures)) end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dohtest/group_runner.rb', line 15 def run @output.group_begin(@group_name) if create_group run_before_all run_tests unless @before_all_failed run_after_all end @output.group_end(@group_name, @tests_ran, @tests_skipped, @assertions_passed, @assertions_failed) past_brink? end |
#run_after_all ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dohtest/group_runner.rb', line 49 def run_after_all @group.after_all if @group.respond_to?(:after_all) if @config[:post_group_callback] if (!@config[:post_group_callback].call(total_problems)) @error_count += 1 @output.callback_failed(@config[:post_group_callback].inspect) end end rescue => error caught_error(error, 'after_all') end |
#run_after_each ⇒ Object
96 97 98 99 100 |
# File 'lib/dohtest/group_runner.rb', line 96 def run_after_each @group.send(@after_each_method) rescue => error caught_error(error) end |
#run_before_all ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dohtest/group_runner.rb', line 36 def run_before_all @group.before_all if @group.respond_to?(:before_all) if @config[:pre_group_callback] if (!@config[:pre_group_callback].call()) @error_count += 1 @output.callback_failed(@config[:pre_group_callback].inspect) end end rescue => error @before_all_failed = true caught_error(error, 'before_all') end |
#run_before_each ⇒ Object
89 90 91 92 93 94 |
# File 'lib/dohtest/group_runner.rb', line 89 def run_before_each @group.send(@before_each_method) rescue => error @before_each_failed = true caught_error(error) end |
#run_test_method ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/dohtest/group_runner.rb', line 102 def run_test_method @group.send(@test_name) rescue DohTest::Failure => failure @assertions_failed += 1 @output.assertion_failed(@group_name, @test_name, failure) rescue => error caught_error(error) end |
#run_tests ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dohtest/group_runner.rb', line 121 def run_tests determine_test_methods find_before_each_method find_after_each_method setup_brink @test_methods.each do |method_name| break if @has_brink && past_brink? @test_name = method_name @before_each_failed = false @output.test_begin(@group_name, @test_name) run_before_each if @before_each_method run_test_method unless @before_each_failed run_after_each if @after_each_method @tests_ran += 1 @output.test_end(@group_name, @test_name) end end |
#setup_brink ⇒ Object
111 112 113 114 115 |
# File 'lib/dohtest/group_runner.rb', line 111 def setup_brink @max_errors = if @config.key?(:max_errors) then @config[:max_errors].to_i else nil end @max_failures = if @config.key?(:max_failures) then @config[:max_failures].to_i else nil end @has_brink = @max_errors || @max_failures end |
#total_problems ⇒ Object
159 160 161 |
# File 'lib/dohtest/group_runner.rb', line 159 def total_problems @error_count + @assertions_failed end |