Class: Minitest::Queue::SingleExample

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runnable, method_name) ⇒ SingleExample

Returns a new instance of SingleExample.



403
404
405
406
# File 'lib/minitest/queue.rb', line 403

def initialize(runnable, method_name)
  @runnable = runnable
  @method_name = method_name
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



401
402
403
# File 'lib/minitest/queue.rb', line 401

def method_name
  @method_name
end

#runnableObject (readonly)

Returns the value of attribute runnable.



401
402
403
# File 'lib/minitest/queue.rb', line 401

def runnable
  @runnable
end

Instance Method Details

#<=>(other) ⇒ Object



425
426
427
# File 'lib/minitest/queue.rb', line 425

def <=>(other)
  id <=> other.id
end

#flaky?Boolean

Returns:

  • (Boolean)


446
447
448
# File 'lib/minitest/queue.rb', line 446

def flaky?
  Minitest.queue.flaky?(self)
end

#idObject



408
409
410
# File 'lib/minitest/queue.rb', line 408

def id
  @id ||= "#{@runnable}##{@method_name}".freeze
end

#queue_entryObject



412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/minitest/queue.rb', line 412

def queue_entry
  @queue_entry ||= begin
    unless runnable.is_a?(Module)
      raise ArgumentError, "runnable must be a Module (got #{runnable.class}). " \
        "Do not create SingleExample with string class names."
    end
    file_path = runnable.instance_method(method_name).source_location&.first
    raise ArgumentError, "Cannot resolve source file for #{id}" \
      "ensure the test method is defined in a Ruby source file" if file_path.nil?
    CI::Queue::QueueEntry.format(id, file_path)
  end
end

#runObject



440
441
442
443
444
# File 'lib/minitest/queue.rb', line 440

def run
  with_timestamps do
    @runnable.new(@method_name).run
  end
end

#source_locationObject



450
451
452
453
454
# File 'lib/minitest/queue.rb', line 450

def source_location
  @runnable.instance_method(@method_name).source_location
rescue NameError, NoMethodError
  nil
end

#with_timestampsObject



429
430
431
432
433
434
435
436
437
438
# File 'lib/minitest/queue.rb', line 429

def with_timestamps
  start_timestamp = current_timestamp
  result = yield
  result
ensure
  if result
    result.start_timestamp = start_timestamp
    result.finish_timestamp = current_timestamp
  end
end