Class: Test::Unit::TestResult
- Inherits:
-
Object
- Object
- Test::Unit::TestResult
- Includes:
- Util::Observable
- Defined in:
- lib/test/unit/testresult.rb
Overview
Collects Test::Unit::Failure and Test::Unit::Error so that they can be displayed to the user. To this end, observers can be added to it, allowing the dynamic updating of, say, a UI.
Constant Summary collapse
- CHANGED =
"CHANGED"
- FAULT =
"FAULT"
Constants included from Util::Observable
Instance Attribute Summary collapse
-
#assertion_count ⇒ Object
readonly
Returns the value of attribute assertion_count.
-
#run_count ⇒ Object
readonly
Returns the value of attribute run_count.
Instance Method Summary collapse
-
#add_assertion ⇒ Object
Records an individual assertion.
-
#add_error(error) ⇒ Object
Records a Test::Unit::Error.
-
#add_failure(failure) ⇒ Object
Records a Test::Unit::Failure.
-
#add_run ⇒ Object
Records a test run.
-
#error_count ⇒ Object
Returns the number of errors this TestResult has recorded.
-
#failure_count ⇒ Object
Returns the number of failures this TestResult has recorded.
-
#initialize ⇒ TestResult
constructor
Constructs a new, empty TestResult.
-
#passed? ⇒ Boolean
Returns whether or not this TestResult represents successful completion.
-
#to_s ⇒ Object
Returns a string contain the recorded runs, assertions, failures and errors in this TestResult.
Methods included from Util::Observable
#add_listener, #notify_listeners, #remove_listener
Constructor Details
#initialize ⇒ TestResult
Constructs a new, empty TestResult.
24 25 26 27 |
# File 'lib/test/unit/testresult.rb', line 24 def initialize @run_count, @assertion_count = 0, 0 @failures, @errors = Array.new, Array.new end |
Instance Attribute Details
#assertion_count ⇒ Object (readonly)
Returns the value of attribute assertion_count.
21 22 23 |
# File 'lib/test/unit/testresult.rb', line 21 def assertion_count @assertion_count end |
#run_count ⇒ Object (readonly)
Returns the value of attribute run_count.
21 22 23 |
# File 'lib/test/unit/testresult.rb', line 21 def run_count @run_count end |
Instance Method Details
#add_assertion ⇒ Object
Records an individual assertion.
50 51 52 53 |
# File 'lib/test/unit/testresult.rb', line 50 def add_assertion @assertion_count += 1 notify_listeners(CHANGED, self) end |
#add_error(error) ⇒ Object
Records a Test::Unit::Error.
43 44 45 46 47 |
# File 'lib/test/unit/testresult.rb', line 43 def add_error(error) @errors << error notify_listeners(FAULT, error) notify_listeners(CHANGED, self) end |
#add_failure(failure) ⇒ Object
Records a Test::Unit::Failure.
36 37 38 39 40 |
# File 'lib/test/unit/testresult.rb', line 36 def add_failure(failure) @failures << failure notify_listeners(FAULT, failure) notify_listeners(CHANGED, self) end |
#add_run ⇒ Object
Records a test run.
30 31 32 33 |
# File 'lib/test/unit/testresult.rb', line 30 def add_run @run_count += 1 notify_listeners(CHANGED, self) end |
#error_count ⇒ Object
Returns the number of errors this TestResult has recorded.
75 76 77 |
# File 'lib/test/unit/testresult.rb', line 75 def error_count return @errors.size end |
#failure_count ⇒ Object
Returns the number of failures this TestResult has recorded.
69 70 71 |
# File 'lib/test/unit/testresult.rb', line 69 def failure_count return @failures.size end |
#passed? ⇒ Boolean
Returns whether or not this TestResult represents successful completion.
63 64 65 |
# File 'lib/test/unit/testresult.rb', line 63 def passed? return @failures.empty? && @errors.empty? end |
#to_s ⇒ Object
Returns a string contain the recorded runs, assertions, failures and errors in this TestResult.
57 58 59 |
# File 'lib/test/unit/testresult.rb', line 57 def to_s "#{run_count} tests, #{assertion_count} assertions, #{failure_count} failures, #{error_count} errors" end |