Class: RSpec::Core::Bisect::ShellCommand

Inherits:
Object
  • Object
show all
Includes:
ShellEscape
Defined in:
lib/rspec/core/bisect/shell_command.rb

Overview

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

Constant Summary

Constants included from ShellEscape

ShellEscape::SHELLS_ALLOWING_UNQUOTED_IDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ShellEscape

conditionally_quote, quote, shell_allows_unquoted_ids?

Constructor Details

#initialize(original_cli_args) ⇒ ShellCommand

Returns a new instance of ShellCommand



13
14
15
# File 'lib/rspec/core/bisect/shell_command.rb', line 13

def initialize(original_cli_args)
  @original_cli_args = original_cli_args.reject { |arg| arg.start_with?("--bisect") }
end

Instance Attribute Details

#original_cli_argsObject (readonly)

Returns the value of attribute original_cli_args



11
12
13
# File 'lib/rspec/core/bisect/shell_command.rb', line 11

def original_cli_args
  @original_cli_args
end

Instance Method Details

#bisect_environment_hashObject



47
48
49
50
51
52
53
# File 'lib/rspec/core/bisect/shell_command.rb', line 47

def bisect_environment_hash
  if ENV.key?('SPEC_OPTS')
    { 'SPEC_OPTS' => spec_opts_without_bisect }
  else
    {}
  end
end

#command_for(locations, server) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/core/bisect/shell_command.rb', line 17

def command_for(locations, server)
  parts = []

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

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

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

  parts.join(" ")
end

#original_locationsObject



43
44
45
# File 'lib/rspec/core/bisect/shell_command.rb', line 43

def original_locations
  parsed_original_cli_options.fetch(:files_or_directories_to_run)
end

#repro_command_from(locations) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/rspec/core/bisect/shell_command.rb', line 32

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

#spec_opts_without_bisectObject



55
56
57
58
59
60
61
# File 'lib/rspec/core/bisect/shell_command.rb', line 55

def spec_opts_without_bisect
  Shellwords.join(
    Shellwords.split(ENV.fetch('SPEC_OPTS', '')).reject do |arg|
      arg =~ /^--bisect/
    end
  )
end