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.



323
324
325
326
# File 'lib/minitest/queue.rb', line 323

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.



321
322
323
# File 'lib/minitest/queue.rb', line 321

def method_name
  @method_name
end

#runnableObject (readonly)

Returns the value of attribute runnable.



321
322
323
# File 'lib/minitest/queue.rb', line 321

def runnable
  @runnable
end

Instance Method Details

#<=>(other) ⇒ Object



345
346
347
# File 'lib/minitest/queue.rb', line 345

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

#flaky?Boolean

Returns:

  • (Boolean)


366
367
368
# File 'lib/minitest/queue.rb', line 366

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

#idObject



328
329
330
# File 'lib/minitest/queue.rb', line 328

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

#queue_entryObject



332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/minitest/queue.rb', line 332

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



360
361
362
363
364
# File 'lib/minitest/queue.rb', line 360

def run
  with_timestamps do
    Minitest.run_one_method(@runnable, @method_name)
  end
end

#source_locationObject



370
371
372
373
374
# File 'lib/minitest/queue.rb', line 370

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

#with_timestampsObject



349
350
351
352
353
354
355
356
357
358
# File 'lib/minitest/queue.rb', line 349

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