Class: RSpec::Core::ExampleStatusMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_status_persister.rb

Overview

Merges together a list of example statuses from this run and a list from previous runs (presumably loaded from disk). Each example status object is expected to be a hash with at least an ‘:example_id` and a `:status` key. Examples that were loaded but not executed (due to filtering, `–fail-fast` or whatever) should have a `:status` of `UNKNOWN_STATUS`.

This willl produce a new list that:

- Will be missing examples from previous runs that we know for sure
  no longer exist.
- Will have the latest known status for any examples that either
  definitively do exist or may still exist.
- Is sorted by file name and example definition order, so that
  the saved file is easily scannable if users want to inspect it.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(this_run, from_previous_runs) ⇒ ExampleStatusMerger

Returns a new instance of ExampleStatusMerger.



79
80
81
82
83
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_status_persister.rb', line 79

def initialize(this_run, from_previous_runs)
  @this_run           = hash_from(this_run)
  @from_previous_runs = hash_from(from_previous_runs)
  @file_exists_cache  = Hash.new { |hash, file| hash[file] = File.exist?(file) }
end

Class Method Details

.merge(this_run, from_previous_runs) ⇒ Object



75
76
77
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_status_persister.rb', line 75

def self.merge(this_run, from_previous_runs)
  new(this_run, from_previous_runs).merge
end

Instance Method Details

#mergeObject



85
86
87
88
89
90
91
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_status_persister.rb', line 85

def merge
  delete_previous_examples_that_no_longer_exist

  @this_run.merge(@from_previous_runs) do |_ex_id, new, old|
    new.fetch(:status) == Configuration::UNKNOWN_STATUS ? old : new
  end.values.sort_by(&method(:sort_value_from))
end