Class: Minitest::Queue::LazySingleExample
- Inherits:
-
Object
- Object
- Minitest::Queue::LazySingleExample
- Defined in:
- lib/minitest/queue.rb
Constant Summary collapse
- RUNNABLE_METHODS_TRIGGERED =
:nodoc:
Concurrent::Map.new
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #flaky? ⇒ Boolean
- #id ⇒ Object
-
#initialize(class_name, method_name, file_path, loader:, resolver:, load_error: nil, queue_entry: nil) ⇒ LazySingleExample
constructor
A new instance of LazySingleExample.
- #marshal_dump ⇒ Object
- #marshal_load(payload) ⇒ Object
- #queue_entry ⇒ Object
- #run ⇒ Object
- #runnable ⇒ Object
- #source_location ⇒ Object
- #with_timestamps ⇒ Object
Constructor Details
#initialize(class_name, method_name, file_path, loader:, resolver:, load_error: nil, queue_entry: nil) ⇒ LazySingleExample
Returns a new instance of LazySingleExample.
466 467 468 469 470 471 472 473 474 475 |
# File 'lib/minitest/queue.rb', line 466 def initialize(class_name, method_name, file_path, loader:, resolver:, load_error: nil, queue_entry: nil) @class_name = class_name @method_name = method_name @file_path = file_path @loader = loader @resolver = resolver @load_error = load_error @queue_entry_override = queue_entry @runnable = nil end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
464 465 466 |
# File 'lib/minitest/queue.rb', line 464 def class_name @class_name end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
464 465 466 |
# File 'lib/minitest/queue.rb', line 464 def file_path @file_path end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
464 465 466 |
# File 'lib/minitest/queue.rb', line 464 def method_name @method_name end |
Instance Method Details
#<=>(other) ⇒ Object
485 486 487 |
# File 'lib/minitest/queue.rb', line 485 def <=>(other) id <=> other.id end |
#flaky? ⇒ Boolean
541 542 543 |
# File 'lib/minitest/queue.rb', line 541 def flaky? Minitest.queue.flaky?(self) end |
#id ⇒ Object
477 478 479 |
# File 'lib/minitest/queue.rb', line 477 def id @id ||= "#{@class_name}##{@method_name}".freeze end |
#marshal_dump ⇒ Object
553 554 555 556 557 558 559 560 561 |
# File 'lib/minitest/queue.rb', line 553 def marshal_dump { 'class_name' => @class_name, 'method_name' => @method_name, 'file_path' => @file_path, 'load_error' => serialize_error(@load_error), 'queue_entry' => @queue_entry_override, } end |
#marshal_load(payload) ⇒ Object
563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/minitest/queue.rb', line 563 def marshal_load(payload) @class_name = payload['class_name'] @method_name = payload['method_name'] @file_path = payload['file_path'] @load_error = deserialize_error(payload['load_error']) @queue_entry_override = payload['queue_entry'] @loader = CI::Queue::FileLoader.new @resolver = CI::Queue::ClassResolver @runnable = nil @id = nil @queue_entry = nil end |
#queue_entry ⇒ Object
481 482 483 |
# File 'lib/minitest/queue.rb', line 481 def queue_entry @queue_entry ||= @queue_entry_override || CI::Queue::QueueEntry.format(id, file_path) end |
#run ⇒ Object
527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/minitest/queue.rb', line 527 def run do if @load_error build_error_result(@load_error) elsif skip_stale_tests? && !(runnable.method_defined?(@method_name) || runnable.private_method_defined?(@method_name)) build_stale_skip_result else runnable.new(@method_name).run end rescue StandardError, ScriptError => error build_error_result(error) end end |
#runnable ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/minitest/queue.rb', line 491 def runnable @runnable ||= begin klass = @resolver.resolve(@class_name, file_path: @file_path, loader: @loader) unless RUNNABLE_METHODS_TRIGGERED[klass] klass.runnable_methods RUNNABLE_METHODS_TRIGGERED[klass] = true end # If the method doesn't exist, the class may have been autoloaded by # Zeitwerk without executing test-specific code (includes, helpers). # Force load the file so all class-definition-time code executes. unless klass.method_defined?(@method_name) || klass.private_method_defined?(@method_name) if @file_path && @loader @loader.load_file(@file_path) RUNNABLE_METHODS_TRIGGERED.delete(klass) klass.runnable_methods RUNNABLE_METHODS_TRIGGERED[klass] = true end end klass end end |
#source_location ⇒ Object
545 546 547 548 549 550 551 |
# File 'lib/minitest/queue.rb', line 545 def source_location return nil if @load_error runnable.instance_method(@method_name).source_location rescue NameError, NoMethodError, CI::Queue::FileLoadError, CI::Queue::ClassNotFoundError nil end |
#with_timestamps ⇒ Object
515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/minitest/queue.rb', line 515 def = result = yield result ensure if result result. = result. = result.time ||= (result. - result.).to_f end end |