-
-
Notifications
You must be signed in to change notification settings - Fork 753
Support bisect in spec opts #2271
Changes from all commits
9780a52
b420cf5
b5741ab
4add368
d52c969
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ rvm: | |
- 1.9.3 | ||
- 2.0.0 | ||
- 2.1 | ||
- 2.2 | ||
- 2.2.5 | ||
- 2.3.1 | ||
- ruby-head | ||
- ree | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
option_parser | ||
configuration_options | ||
runner | ||
invocations | ||
example | ||
shared_example_group | ||
example_group | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module RSpec | ||
module Core | ||
# @private | ||
module Invocations | ||
# @private | ||
class InitializeProject | ||
def call(*_args) | ||
RSpec::Support.require_rspec_core "project_initializer" | ||
ProjectInitializer.new.run | ||
0 | ||
end | ||
end | ||
|
||
# @private | ||
class DRbWithFallback | ||
def call(options, err, out) | ||
require 'rspec/core/drb' | ||
begin | ||
return DRbRunner.new(options).run(err, out) | ||
rescue DRb::DRbConnError | ||
err.puts "No DRb server is running. Running in local process instead ..." | ||
end | ||
RSpec::Core::Runner.new(options).run(err, out) | ||
end | ||
end | ||
|
||
# @private | ||
class Bisect | ||
def call(options, _err, _out) | ||
RSpec::Support.require_rspec_core "bisect/coordinator" | ||
|
||
success = RSpec::Core::Bisect::Coordinator.bisect_with( | ||
options.args, | ||
RSpec.configuration, | ||
bisect_formatter_for(options.options[:bisect]) | ||
) | ||
|
||
success ? 0 : 1 | ||
end | ||
|
||
private | ||
|
||
def bisect_formatter_for(argument) | ||
return Formatters::BisectDebugFormatter if argument == "verbose" | ||
Formatters::BisectProgressFormatter | ||
end | ||
end | ||
|
||
# @private | ||
class PrintVersion | ||
def call(_options, _err, out) | ||
out.puts RSpec::Core::Version::STRING | ||
0 | ||
end | ||
end | ||
|
||
# @private | ||
PrintHelp = Struct.new(:parser, :invalid_options) do | ||
def call(_options, _err, out) | ||
# Removing the blank invalid options from the output. | ||
out.puts parser.to_s.gsub(/^\s+(#{invalid_options.join('|')})\s*$\n/, '') | ||
0 | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,19 +213,75 @@ def repro_command_from(ids) | |
open3_method = Open3.respond_to?(:capture2e) ? :capture2e : :popen3 | ||
open3_method = :popen3 if RSpec::Support::Ruby.jruby? | ||
|
||
def called_environment | ||
@called_environment | ||
end | ||
|
||
if open3_method == :capture2e | ||
RSpec::Matchers.define :invoke_command_with_env do |command, environment| | ||
match do |block| | ||
block.call | ||
|
||
expect(Open3).to have_received(open3_method).with(environment, command) | ||
end | ||
|
||
supports_block_expectations | ||
end | ||
elsif open3_method == :popen3 | ||
RSpec::Matchers.define :invoke_command_with_env do |command, environment| | ||
match do |block| | ||
block.call | ||
|
||
expect(Open3).to have_received(open3_method).with(command) | ||
expect(called_environment).to include(environment) | ||
end | ||
|
||
supports_block_expectations | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just be |
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a merge blocker, but I think maybe the matcher should be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh - yeah, that's an artifact of switching to the non-block style and back again, will change it now. |
||
|
||
before do | ||
allow(Open3).to receive(open3_method).and_return( | ||
allow(Open3).to receive(open3_method) do | ||
@called_environment = ENV.to_hash.dup | ||
[double("Exit Status"), double("Stdout/err")] | ||
) | ||
end | ||
|
||
allow(server).to receive(:capture_run_results) do |&block| | ||
block.call | ||
"the results" | ||
end | ||
end | ||
|
||
it "runs the suite with the original CLI options" do | ||
runner.original_results | ||
expect(Open3).to have_received(open3_method).with(a_string_including("--seed 1234")) | ||
expect { | ||
runner.original_results | ||
}.to invoke_command_with_env(a_string_including("--seed 1234"), {}) | ||
end | ||
|
||
context 'when --bisect is present in SPEC_OPTS' do | ||
it "runs the suite with --bisect removed from the environment" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can test the effect of removing with_env_var 'SPEC_OPTS' => '--bisect --fail-fast' do
expect(@runner.spec_opts_without_bisect).to eq('--fail-fast')
end
# and then
with_env_vars 'RSPEC_TEMP' => 'original' do
actual = @runner.run_command "ruby -e 'puts ENV['RSPEC_TEMP']"
expect(actual).to eq('original')
end |
||
expect { | ||
with_env_vars 'SPEC_OPTS' => '--bisect --fail-fast' do | ||
runner.original_results | ||
end | ||
}.to invoke_command_with_env( | ||
a_string_including("--seed 1234"), | ||
{ 'SPEC_OPTS' => '--fail-fast' } | ||
) | ||
end | ||
end | ||
|
||
context 'when --bisect=verbose is present in SPEC_OPTS' do | ||
it "runs the suite with --bisect removed from the environment" do | ||
expect { | ||
with_env_vars 'SPEC_OPTS' => '--bisect=verbose --fail-fast' do | ||
runner.original_results | ||
end | ||
}.to invoke_command_with_env( | ||
a_string_including("--seed 1234"), | ||
{ 'SPEC_OPTS' => '--fail-fast' } | ||
) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you mean about it being tricky to figure out what to treat as the subject for these expectations. Maybe the block approach does make the most sense. I'm happy to merge with this has it is but if you want to switch back to the block form that would be fine, too. |
||
end | ||
|
||
it 'returns the run results' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 did you try using the open3 feature of passing in the env opts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upside of supporting ruby 1.8.7 is that I get to use the old hash syntax without feeling guilt. The downside is that some of stdlib wasn't as capable back then, and
Open3
/Process.spawn
is one of those bits, unfortunately. I've used the new passed environment where possible, but for 1.8.7 it's either put the new env in the command string or mutateENV
, so I plumped for the latter.