class RSpec::Core::Bisect::Runner

Provides an API to run the suite for a set of locations, using the given bisect server to capture the results. @private

Constants

RUBY

Path to the currently running Ruby executable, borrowed from Rake: github.com/ruby/rake/blob/v10.4.2/lib/rake/file_utils.rb#L8-L12 Note that we skip `ENV` because we don't have to deal with running RSpec from within a MRI source repository: github.com/ruby/rake/commit/968682759b3b65e42748cd2befb2ff3e982272d9

Attributes

original_cli_args[R]

Public Class Methods

new(server, original_cli_args) click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 14
def initialize(server, original_cli_args)
  @server            = server
  @original_cli_args = original_cli_args.reject { |arg| arg.start_with?("--bisect") }
end

Public Instance Methods

command_for(locations) click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 23
def command_for(locations)
  parts = []

  parts << RUBY << load_path
  parts << open3_safe_escape(RSpec::Core.path_to_executable)

  parts << "--format"   << "bisect"
  parts << "--drb-port" << @server.drb_port

  parts.concat reusable_cli_options
  parts.concat locations.map { |l| open3_safe_escape(l) }

  parts.join(" ")
end
original_results() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 49
def original_results
  @original_results ||= run_locations(original_locations)
end
repro_command_from(locations) click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 38
def repro_command_from(locations)
  parts = []

  parts.concat environment_repro_parts
  parts << "rspec"
  parts.concat Formatters::Helpers.organize_ids(locations)
  parts.concat original_cli_args_without_locations

  parts.join(" ")
end
run(locations) click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 19
def run(locations)
  run_locations(locations, original_results.failed_example_ids)
end

Private Instance Methods

bisect_environment_hash() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 99
def bisect_environment_hash
  if ENV.key?('SPEC_OPTS')
    { 'SPEC_OPTS' => spec_opts_without_bisect }
  else
    {}
  end
end
environment_repro_parts() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 107
def environment_repro_parts
  bisect_environment_hash.map do |k, v|
    %Q(#{k}="#{v}")
  end
end
load_path() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 153
def load_path
  @load_path ||= "-I#{$LOAD_PATH.map { |p| open3_safe_escape(p) }.join(':')}"
end
original_cli_args_without_locations() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 138
def original_cli_args_without_locations
  @original_cli_args_without_locations ||= begin
    files_or_dirs = parsed_original_cli_options.fetch(:files_or_directories_to_run)
    @original_cli_args - files_or_dirs
  end
end
original_locations() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 149
def original_locations
  parsed_original_cli_options.fetch(:files_or_directories_to_run)
end
parsed_original_cli_options() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 145
def parsed_original_cli_options
  @parsed_original_cli_options ||= Parser.parse(@original_cli_args)
end
reusable_cli_options() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 121
def reusable_cli_options
  @reusable_cli_options ||= begin
    opts = original_cli_args_without_locations

    if (port = parsed_original_cli_options[:drb_port])
      opts -= %W[ --drb-port #{port} ]
    end

    parsed_original_cli_options.fetch(:formatters) { [] }.each do |(name, out)|
      opts -= %W[ --format #{name} -f -f#{name} ]
      opts -= %W[ --out #{out} -o -o#{out} ]
    end

    opts
  end
end
run_command(cmd) click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 75
def run_command(cmd)
  Open3.capture2e(bisect_environment_hash, cmd).first
end
run_locations(*capture_args) click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 66
def run_locations(*capture_args)
  @server.capture_run_results(*capture_args) do
    run_command command_for([])
  end
end
spec_opts_without_bisect() click to toggle source
# File lib/rspec/core/bisect/runner.rb, line 113
def spec_opts_without_bisect
  Shellwords.join(
    Shellwords.split(ENV.fetch('SPEC_OPTS', '')).reject do |arg|
      arg =~ /^--bisect/
    end
  )
end