Class: MiniTest::Unit::TestCase

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/minitest/unit.rb

Direct Known Subclasses

Spec

Constant Summary collapse

PASSTHROUGH_EXCEPTIONS =
[NoMemoryError, SignalException, Interrupt,
SystemExit]
SUPPORTS_INFO_SIGNAL =

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#_assertions, #_assertions=, #assert, #assert_block, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_nil, #assert_operator, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_throws, #capture_io, #exception_details, #flunk, #message, #mu_pp, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_respond_to, #refute_same, #skip

Constructor Details

#initialize(name) ⇒ TestCase

Returns a new instance of TestCase.



472
473
474
475
# File 'lib/minitest/unit.rb', line 472

def initialize name
  @__name__ = name
  @passed = nil
end

Instance Attribute Details

#__name__Object (readonly)

Returns the value of attribute __name__.



434
435
436
# File 'lib/minitest/unit.rb', line 434

def __name__
  @__name__
end

Class Method Details

.inherited(klass) ⇒ Object



483
484
485
# File 'lib/minitest/unit.rb', line 483

def self.inherited klass
  @@test_suites[klass] = true
end

.resetObject



477
478
479
# File 'lib/minitest/unit.rb', line 477

def self.reset
  @@test_suites = {}
end

.test_methodsObject



495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/minitest/unit.rb', line 495

def self.test_methods
  methods = public_instance_methods(true).grep(/^test/).map { |m|
    m.to_s
  }.sort

  if self.test_order == :random then
    max = methods.size
    methods = methods.sort_by { rand(max) }
  end

  methods
end

.test_orderObject



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

def self.test_order
  :random
end

.test_suitesObject



491
492
493
# File 'lib/minitest/unit.rb', line 491

def self.test_suites
  @@test_suites.keys.sort_by { |ts| ts.name }
end

Instance Method Details

#passed?Boolean

Returns:

  • (Boolean)


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

def passed?
  @passed
end

#run(runner) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/minitest/unit.rb', line 441

def run runner
  trap 'INFO' do
    warn '%s#%s %.2fs' % [self.class, self.__name__,
      (Time.now - runner.start_time)]
    runner.status $stderr
  end if SUPPORTS_INFO_SIGNAL

  result = '.'
  begin
    @passed = nil
    self.setup
    self.__send__ self.__name__
    @passed = true
  rescue *PASSTHROUGH_EXCEPTIONS
    raise
  rescue Exception => e
    @passed = false
    result = runner.puke(self.class, self.__name__, e)
  ensure
    begin
      self.teardown
    rescue *PASSTHROUGH_EXCEPTIONS
      raise
    rescue Exception => e
      result = runner.puke(self.class, self.__name__, e)
    end
    trap 'INFO', 'DEFAULT' if SUPPORTS_INFO_SIGNAL
  end
  result
end

#setupObject



508
# File 'lib/minitest/unit.rb', line 508

def setup; end

#teardownObject



509
# File 'lib/minitest/unit.rb', line 509

def teardown; end