lib/assert/default_suite.rb in assert-2.15.2 vs lib/assert/default_suite.rb in assert-2.16.0
- old
+ new
@@ -1,64 +1,59 @@
require 'assert/suite'
module Assert
- # This is the default suite used by assert. It stores test/result data in-memory.
+ # This is the default suite used by assert. In addition to the base suite
+ # behavior, it accumulates test/result counts in memory. This data is used
+ # by the runner/view for handling and presentation purposes.
class DefaultSuite < Assert::Suite
- # Test data
-
- def ordered_tests
- self.tests
+ def initialize(config)
+ super
+ reset_run_data
end
- def reversed_tests
- self.tests.reverse
- end
+ def test_count; @test_count; end
+ def result_count; @result_count; end
+ def pass_result_count; @pass_result_count; end
+ def fail_result_count; @fail_result_count; end
+ def error_result_count; @error_result_count; end
+ def skip_result_count; @skip_result_count; end
+ def ignore_result_count; @ignore_result_count; end
- def ordered_tests_by_run_time
- self.ordered_tests.sort{ |a, b| a.run_time <=> b.run_time }
- end
+ # Callbacks
- def reversed_tests_by_run_time
- self.ordered_tests_by_run_time.reverse
+ def on_start
+ reset_run_data
end
- def test_count
- self.tests.size
+ def before_test(test)
+ @test_count += 1
end
- # Result data
-
- def ordered_results
- self.ordered_tests.inject([]){ |results, test| results += test.results }
+ def on_result(result)
+ @result_count += 1
+ self.send("increment_#{result.type}_result_count")
end
- def reversed_results
- self.ordered_results.reverse
- end
+ private
- # dump failed or errored results,
- # dump skipped or ignored results if they have a message
- def ordered_results_for_dump
- self.ordered_results.select do |result|
- [:fail, :error].include?(result.to_sym) ||
- !!([:skip, :ignore].include?(result.to_sym) && result.message)
- end
- end
+ def increment_pass_result_count; @pass_result_count += 1; end
+ def increment_fail_result_count; @fail_result_count += 1; end
+ def increment_error_result_count; @error_result_count += 1; end
+ def increment_skip_result_count; @skip_result_count += 1; end
+ def increment_ignore_result_count; @ignore_result_count += 1; end
- def reversed_results_for_dump
- self.ordered_results_for_dump.reverse
+ def reset_run_data
+ @test_count = 0
+ @result_count = 0
+ @pass_result_count = 0
+ @fail_result_count = 0
+ @error_result_count = 0
+ @skip_result_count = 0
+ @ignore_result_count = 0
end
-
- def result_count(type = nil)
- self.tests.inject(0){ |count, test| count += test.result_count(type) }
- end
-
- # Callbacks
-
- # no custom callbacks
end
end