Class: Minitest::Result

Inherits:
Runnable show all
Defined in:
lib/minitest.rb

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

Test

Constant Summary

Constants inherited from Runnable

Minitest::Runnable::SIGNALS

Instance Attribute Summary collapse

Attributes inherited from Runnable

#assertions, #failures, #time

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runnable

#failure, inherited, #initialize, #marshal_dump, #marshal_load, methods_matching, #name, #name=, 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

#klassObject

The class name of the test result.



453
454
455
# File 'lib/minitest.rb', line 453

def klass
  @klass
end

#source_locationObject

The location of the test method.



458
459
460
# File 'lib/minitest.rb', line 458

def source_location
  @source_location
end

Class Method Details

.from(runnable) ⇒ Object

Create a new test result from a Runnable instance.



463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/minitest.rb', line 463

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?

Returns:

  • (Boolean)


480
481
482
# File 'lib/minitest.rb', line 480

def error?
  self.failures.any? { |f| UnexpectedError === f }
end

#locationObject

The location identifier of this test.



487
488
489
490
# File 'lib/minitest.rb', line 487

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.

Returns:

  • (Boolean)


498
499
500
# File 'lib/minitest.rb', line 498

def passed?
  not self.failure
end

#result_codeObject

Returns “.”, “F”, or “E” based on the result of the run.



505
506
507
# File 'lib/minitest.rb', line 505

def result_code
  self.failure and self.failure.result_code or "."
end

#skipped?Boolean

Was this run skipped?

Returns:

  • (Boolean)


512
513
514
# File 'lib/minitest.rb', line 512

def skipped?
  self.failure and Skip === self.failure
end

#to_sObject

:nodoc:



516
517
518
519
520
521
522
# File 'lib/minitest.rb', line 516

def to_s # :nodoc:
  return location if passed? and not skipped?

  failures.map { |failure|
    "#{failure.result_label}:\n#{self.location}:\n#{failure.message}\n"
  }.join "\n"
end