class RSpecSearchAndDestroy::RSpecDriver

Constants

EXAMPLE_FILE
RESULT_FILE

Attributes

rspec_command[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/rspec-search-and-destroy/rspec_driver.rb, line 11
def initialize(options = {})
  @rspec_command = options.fetch(:command, 'rspec').split(/\s/)
end

Public Instance Methods

cleanup() click to toggle source
# File lib/rspec-search-and-destroy/rspec_driver.rb, line 43
def cleanup
  [EXAMPLE_FILE, RESULT_FILE].each do |fname|
    File.delete(fname) if File.exist? fname
  end
end
initial_run() click to toggle source
# File lib/rspec-search-and-destroy/rspec_driver.rb, line 28
def initial_run
  cleanup
  run_rspec
end
load_run_results() click to toggle source
# File lib/rspec-search-and-destroy/rspec_driver.rb, line 15
    def load_run_results
      unless File.exist? RESULT_FILE
        raise <<ERR
The RSpec result file was not created. Please ensure that SAD is
added to your RSpec configuration.
ERR
      end

      File.open(RESULT_FILE, 'rb') do |f|
        RSpecResults.new(Marshal.load(f))
      end
    end
run_examples(examples) click to toggle source
# File lib/rspec-search-and-destroy/rspec_driver.rb, line 33
def run_examples(examples)
  locations = examples.map {|x| x[:location]}

  File.open(EXAMPLE_FILE, 'wb') do |f|
    Marshal.dump(locations, f)
  end

  run_rspec
end

Private Instance Methods

run_rspec() click to toggle source
# File lib/rspec-search-and-destroy/rspec_driver.rb, line 51
def run_rspec
  process = ChildProcess.build(*rspec_command)
  process.io.inherit!
  process.environment["RSPEC_SAD_EXAMPLES"] = EXAMPLE_FILE
  process.environment["RSPEC_SAD_RESULTS"] = RESULT_FILE

  process.start
  process.wait
end