123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::ExampleStatusPersister Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-core/lib/rspec/core/example_status_persister.rb

Overview

Persists example ids and their statuses so that we can filter to just the ones that failed the last time they ran.

Class Method Summary

Instance Method Summary

Class Method Details

.load_from(file_name)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 9

def self.load_from(file_name)
  return [] unless File.exist?(file_name)
  ExampleStatusParser.parse(File.read(file_name))
end

.persist(examples, file_name)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 14

def self.persist(examples, file_name)
  new(examples, file_name).persist
end

Instance Method Details

#dump_statuses(unparsed_previous_runs) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 40

def dump_statuses(unparsed_previous_runs)
  statuses_from_previous_runs = ExampleStatusParser.parse(unparsed_previous_runs)
  merged_statuses = ExampleStatusMerger.merge(statuses_from_this_run, statuses_from_previous_runs)
  ExampleStatusDumper.dump(merged_statuses)
end

#persist

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 23

def persist
  RSpec::Support::DirectoryMaker.mkdir_p(File.dirname(@file_name))
  File.open(@file_name, File::RDWR | File::CREAT) do |f|
    # lock the file while reading / persisting to avoid a race
    # condition where parallel or unrelated spec runs race to
    # update the same file
    f.flock(File::LOCK_EX)
    unparsed_previous_runs = f.read
    f.rewind
    f.write(dump_statuses(unparsed_previous_runs))
    f.flush
    f.truncate(f.pos)
  end
end

#statuses_from_this_run (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 46

def statuses_from_this_run
  @examples.map do |ex|
    result = ex.execution_result

    {
      :example_id => ex.id,
      :status     => result.status ? result.status.to_s : Configuration::UNKNOWN_STATUS,
      :run_time   => result.run_time ? Formatters::Helpers.format_duration(result.run_time) : ""
    }
  end
end