Class: Minitest::Result
Overview
This represents a test result in a clean way that can be marshalled over a wire. Tests can do anything they want to the test instance and can create conditions that cause Marshal.dump to blow up. By using Result.from(a_test) you can be reasonably sure that the test result can be marshalled.
Direct Known Subclasses
Constant Summary
Constants inherited from Runnable
Instance Attribute Summary collapse
-
#klass ⇒ Object
The class name of the test result.
-
#name ⇒ Object
The test name of the test result.
-
#source_location ⇒ Object
The location of the test method.
Attributes inherited from Runnable
Class Method Summary collapse
-
.from(runnable) ⇒ Object
Create a new test result from a Runnable instance.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Did this run error?.
-
#location ⇒ Object
The location identifier of this test.
-
#passed? ⇒ Boolean
Did this run pass?.
-
#result_code ⇒ Object
Returns “.”, “F”, or “E” based on the result of the run.
-
#skipped? ⇒ Boolean
Was this run skipped?.
-
#to_s ⇒ Object
:nodoc:.
Methods inherited from Runnable
#failure, inherited, #initialize, #marshal_dump, #marshal_load, methods_matching, on_signal, reset, #run, run, run_one_method, runnable_methods, runnables, #time_it, with_info_handler
Constructor Details
This class inherits a constructor from Minitest::Runnable
Instance Attribute Details
#klass ⇒ Object
The class name of the test result.
453 454 455 |
# File 'lib/minitest.rb', line 453 def klass @klass end |
#name ⇒ Object
The test name of the test result.
458 459 460 |
# File 'lib/minitest.rb', line 458 def name @name end |
#source_location ⇒ Object
The location of the test method.
463 464 465 |
# File 'lib/minitest.rb', line 463 def source_location @source_location end |
Class Method Details
.from(runnable) ⇒ Object
Create a new test result from a Runnable instance.
468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/minitest.rb', line 468 def self.from runnable o = runnable r = self.new o.name r.klass = o.class.name r.assertions = o.assertions r.failures = o.failures.dup r.time = o.time r.source_location = o.method(o.name).source_location rescue ["unknown", -1] r end |
Instance Method Details
#error? ⇒ Boolean
Did this run error?
485 486 487 |
# File 'lib/minitest.rb', line 485 def error? self.failures.any? { |f| UnexpectedError === f } end |
#location ⇒ Object
The location identifier of this test.
492 493 494 495 |
# File 'lib/minitest.rb', line 492 def location loc = " [#{self.failure.location}]" unless passed? or error? "#{self.klass}##{self.name}#{loc}" end |
#passed? ⇒ Boolean
Did this run pass?
Note: skipped runs are not considered passing, but they don’t cause the process to exit non-zero.
503 504 505 |
# File 'lib/minitest.rb', line 503 def passed? not self.failure end |
#result_code ⇒ Object
Returns “.”, “F”, or “E” based on the result of the run.
510 511 512 |
# File 'lib/minitest.rb', line 510 def result_code self.failure and self.failure.result_code or "." end |
#skipped? ⇒ Boolean
Was this run skipped?
517 518 519 |
# File 'lib/minitest.rb', line 517 def skipped? self.failure and Skip === self.failure end |
#to_s ⇒ Object
:nodoc:
521 522 523 524 525 526 527 |
# File 'lib/minitest.rb', line 521 def to_s # :nodoc: return location if passed? and not skipped? failures.map { |failure| "#{failure.result_label}:\n#{self.location}:\n#{failure.}\n" }.join "\n" end |