Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Include SPEC_OPTS in bisect reproduction command #2274

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/command_line/bisect.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@with-clean-spec-opts
Feature: Bisect

RSpec's `--order random` and `--seed` options help surface flickering examples that only fail when one or more other examples are executed first. It can be very difficult to isolate the exact combination of examples that triggers the failure. The `--bisect` flag helps solve that problem.
Expand Down
2 changes: 1 addition & 1 deletion features/support/require_expect_syntax_in_aruba_specs.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if defined?(Cucumber)
require 'shellwords'
Before('~@allow-should-syntax') do
Before('~@allow-should-syntax', '~@with-clean-spec-opts') do
set_env('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
end

Expand Down
7 changes: 7 additions & 0 deletions lib/rspec/core/bisect/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def command_for(locations)
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
Expand Down Expand Up @@ -103,6 +104,12 @@ def bisect_environment_hash
end
end

def environment_repro_parts
bisect_environment_hash.map do |k, v|
%Q(#{k}="#{v}")
end
end

def spec_opts_without_bisect
Shellwords.join(
Shellwords.split(ENV.fetch('SPEC_OPTS', '')).reject do |arg|
Expand Down
7 changes: 7 additions & 0 deletions spec/rspec/core/bisect/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ def repro_command_from(ids)
expect(cmd).to include("--seed 1234").and exclude("spec/unit ")
end

it 'includes the original SPEC_OPTS but excludes the --bisect flag' do
with_env_vars('SPEC_OPTS' => '--bisect --seed 1234') do
cmd = repro_command_from(%w[ ./spec/unit/1_spec.rb[1:1] ])
expect(cmd).to include('SPEC_OPTS="--seed 1234"').and exclude("--bisect")
end
end

it 'includes original options that `command_for` excludes' do
original_cli_args << "--format" << "progress"
expect(runner.command_for(%w[ ./foo.rb[1:1] ])).to exclude("--format progress")
Expand Down