diff --git a/lib/rspec/core/bisect/fork_runner.rb b/lib/rspec/core/bisect/fork_runner.rb index 16d20dcb9..5c0f32dbe 100644 --- a/lib/rspec/core/bisect/fork_runner.rb +++ b/lib/rspec/core/bisect/fork_runner.rb @@ -81,7 +81,8 @@ def initialize(runner, channel) @runner = runner @channel = channel - @spec_output = StringIO.new + require "tempfile" + @spec_output = Tempfile.new runner.configuration.tap do |c| c.reset_reporter @@ -122,7 +123,7 @@ def run_specs(run_descriptor) latest_run_results = formatter.results if latest_run_results.nil? || latest_run_results.all_example_ids.empty? - @channel.send(@spec_output.string) + @channel.send(@spec_output.tap(&:rewind).read) else @channel.send(latest_run_results) end diff --git a/spec/integration/bisect_spec.rb b/spec/integration/bisect_spec.rb index f4fe29e8c..c7ef5db26 100644 --- a/spec/integration/bisect_spec.rb +++ b/spec/integration/bisect_spec.rb @@ -68,6 +68,13 @@ def bisect(cli_args, expected_status=nil) end end + context "when specs use the `output` expectation" do + it 'does not break the capture helper' do + output = bisect(%w[spec/rspec/core/resources/bisect/output_capture_specs.rb]) + expect(output).to include("No failures found") + end + end + class RSpecChildProcess Ps = Struct.new(:pid, :ppid, :state, :command) diff --git a/spec/rspec/core/resources/bisect/output_capture_specs.rb b/spec/rspec/core/resources/bisect/output_capture_specs.rb new file mode 100644 index 000000000..364ffab2b --- /dev/null +++ b/spec/rspec/core/resources/bisect/output_capture_specs.rb @@ -0,0 +1,7 @@ +# Deliberately named _specs.rb to avoid being loaded except when specified + +RSpec.describe "output capture" do + it "can still capture output when running under --bisect" do + expect { puts "hi" }.to output("hi\n").to_stdout_from_any_process + end +end