Class: DTest::Progress
- Inherits:
-
Object
- Object
- DTest::Progress
- Defined in:
- lib/dtest/progress.rb
Class Method Summary collapse
- .case_str(testcase_size) ⇒ Object
- .error_str(size) ⇒ Object
- .print_failure(failure) ⇒ Object
- .print_result(gresult) ⇒ Object
- .setUpGlobal(testcase) ⇒ Object
- .setUpTestCase(name, size) ⇒ Object
- .tearDownGlobal ⇒ Object
- .tearDownTestCase(name, size, elapsed) ⇒ Object
- .test(casename, name) ⇒ Object
- .test_fail(casename, name) ⇒ Object
- .test_str(test_size) ⇒ Object
- .test_success(casename, name) ⇒ Object
Class Method Details
.case_str(testcase_size) ⇒ Object
11 12 13 14 |
# File 'lib/dtest/progress.rb', line 11 def self.case_str(testcase_size) testcase_str = testcase_size > 1 ? 'cases' : 'case' "#{testcase_size} #{testcase_str}" end |
.error_str(size) ⇒ Object
16 17 18 19 20 |
# File 'lib/dtest/progress.rb', line 16 def self.error_str(size) str = 'error' str += 's' if size > 0 "#{size} #{str}" end |
.print_failure(failure) ⇒ Object
160 161 162 163 164 |
# File 'lib/dtest/progress.rb', line 160 def self.print_failure(failure) failure.failure.each do |msg| msg.print end end |
.print_result(gresult) ⇒ Object
56 57 58 59 60 61 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/dtest/progress.rb', line 56 def self.print_result(gresult) # collect TestCase failures cases = [] gresult.result.each do |result| # test test = [] result.result.each do |r| unless r.empty? && r.ba_empty? test << r end end unless result.ba_empty? && test.empty? cases << { :case => result, :test => test, } end end global_failed = !gresult.ba_empty? ##################### # Output error status split = global_failed || !cases.empty? Report.split if split # Report Global if global_failed err = [] err << 'before' unless gresult.before_failure.empty? err << 'after' unless gresult.after_failure.empty? Report.tag :global, "Global failure" Report.tag :empty, " " + err.join(', ') end # Report TestCase unless cases.empty? str = cases.inject([]) {|a, s| a << s[:case].name }.join(', ') Report.tag :testcase, "#{case_str(cases.size)}" Report.tag :empty, " #{str}" end # Report test each cases cases.each do |x| c = x[:case] t = x[:test] err = [] err << 'beforeCase' unless c.before_failure.empty? err << 'afterCase' unless c.after_failure.empty? err = t.inject(err) {|a, s| a << s.name } Report.tag :test, "#{c.name}: #{error_str(err.size)}" Report.tag :empty, " #{err.join(', ')}" end ################## # Output failures Report.split if split # Global before/after failure if global_failed # before Report.tag :fail, 'Global.before' unless gresult.before_failure.empty? print_failure(gresult.before_failure) # after Report.tag :fail, 'Global.after' unless gresult.after_failure.empty? print_failure(gresult.after_failure) end # Report testcase and test failures cases.each do |x| c = x[:case] casename = c.name #Report.tag :testcase, "#{casename}" # testcase before/after Report.tag :fail, "#{casename}.beforeCase" unless c.before_failure.empty? print_failure(c.before_failure) Report.tag :fail, "#{casename}.afterCase" unless c.after_failure.empty? print_failure(c.after_failure) # test before/test/after x[:test].each do |t| name = t.name Report.tag :fail, "#{casename}.#{name}.before" unless t.before_failure.empty? print_failure(t.before_failure) Report.tag :fail, "#{casename}.#{name}" unless t.failure.empty? print_failure(t) Report.tag :fail, "#{casename}.#{name}.after" unless t.after_failure.empty? print_failure(t.after_failure) end end puts "" puts "Finished in #{gresult.elapsed} seconds" puts "--------------------------------" Report.tag :passed, gresult.passed Report.tag :failed, gresult.failed Report.tag :tested, gresult.executed Report.tag :untest, gresult.untested end |
.setUpGlobal(testcase) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/dtest/progress.rb', line 22 def self.setUpGlobal(testcase) test_size = testcase.inject(0) { |sum, t| sum += t.test.size} Report.tag :global, test_str(test_size) + " from " + case_str(testcase.size) Report.tag :global, "Global test environment set-up." puts '' end |
.setUpTestCase(name, size) ⇒ Object
33 34 35 36 |
# File 'lib/dtest/progress.rb', line 33 def self.setUpTestCase(name, size) Report.tag :line, test_str(size) + " from #{name}" Report.tag :testcase, "#{name} set-up." end |
.tearDownGlobal ⇒ Object
29 30 31 |
# File 'lib/dtest/progress.rb', line 29 def self.tearDownGlobal Report.tag :global, "Global test environment tear-down." end |
.tearDownTestCase(name, size, elapsed) ⇒ Object
38 39 40 41 42 |
# File 'lib/dtest/progress.rb', line 38 def self.tearDownTestCase(name, size, elapsed) Report.tag :testcase, "#{name} tear-down." Report.tag :line, test_str(size) + " executed from #{name} (#{elapsed} seconds)" puts '' end |
.test(casename, name) ⇒ Object
44 45 46 |
# File 'lib/dtest/progress.rb', line 44 def self.test(casename, name) Report.left :run, "#{casename}.#{name}" end |
.test_fail(casename, name) ⇒ Object
52 53 54 |
# File 'lib/dtest/progress.rb', line 52 def self.test_fail(casename, name) Report.right :fail, "#{casename}.#{name}" end |
.test_str(test_size) ⇒ Object
6 7 8 9 |
# File 'lib/dtest/progress.rb', line 6 def self.test_str(test_size) test_str = test_size > 1 ? 'tests' : 'test' "#{test_size} #{test_str}" end |