Class: Minitest::Result

Inherits:
Runnable show all
Includes:
Reportable
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.

Constant Summary

Constants inherited from Runnable

Minitest::Runnable::SIGNALS

Instance Attribute Summary collapse

Attributes inherited from Runnable

#assertions, #failures, #metadata, #time

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reportable

#error?, #location, #passed?, #result_code, #skipped?

Methods inherited from Runnable

#failure, inherited, #initialize, #marshal_dump, #marshal_load, #metadata?, methods_matching, #name, #name=, on_signal, #passed?, reset, #result_code, #run, run, run_one_method, runnable_methods, runnables, #skipped?, test_order, #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.



577
578
579
# File 'lib/minitest.rb', line 577

def klass
  @klass
end

#source_locationObject

The location of the test method.



582
583
584
# File 'lib/minitest.rb', line 582

def source_location
  @source_location
end

Class Method Details

.from(runnable) ⇒ Object

Create a new test result from a Runnable instance.



587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/minitest.rb', line 587

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.   = o. if o.metadata?

  r.source_location = o.method(o.name).source_location rescue ["unknown", -1]

  r
end

Instance Method Details

#class_nameObject

:nodoc:



602
603
604
# File 'lib/minitest.rb', line 602

def class_name # :nodoc:
  self.klass # for Minitest::Reportable
end

#to_sObject

:nodoc:



606
607
608
609
610
611
612
# File 'lib/minitest.rb', line 606

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