diff --git a/lib/mutant.rb b/lib/mutant.rb index 2e9459acc..67d3f1db3 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -330,6 +330,7 @@ module Mutant recorder: recorder, stderr: $stderr, stdout: $stdout, + tempfile: Tempfile, thread: Thread, time: Time, timer: timer diff --git a/lib/mutant/env.rb b/lib/mutant/env.rb index 3d53d4399..1c8a2bacd 100644 --- a/lib/mutant/env.rb +++ b/lib/mutant/env.rb @@ -194,11 +194,13 @@ def timer world.timer end + # TODO: Move this to an isolation based capture. + # mutant:disable def with_capture stderr, stdout = world.stderr, world.stdout original_stdout = stderr.dup original_stderr = stderr.dup - Tempfile.create('capture') do |io| + world.tempfile.create('capture') do |io| stdout.reopen(io) stdout.sync = true stderr.reopen(stdout) diff --git a/lib/mutant/integration/rspec.rb b/lib/mutant/integration/rspec.rb index c06957166..5e75eb7d6 100644 --- a/lib/mutant/integration/rspec.rb +++ b/lib/mutant/integration/rspec.rb @@ -49,6 +49,7 @@ def initialize(*) def setup @setup_elapsed = timer.elapsed do @runner.setup(world.stderr, world.stdout) + fail 'Rspec setup failure' if RSpec.world.rspec_is_quitting example_group_map end reset_examples diff --git a/lib/mutant/world.rb b/lib/mutant/world.rb index 1e07c0358..80c18eb0e 100644 --- a/lib/mutant/world.rb +++ b/lib/mutant/world.rb @@ -22,6 +22,7 @@ class World :recorder, :stderr, :stdout, + :tempfile, :thread, :time, :timer diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a31ce3645..1477d9a14 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -120,8 +120,9 @@ def fake_world process: class_double(Process), random: class_double(Random), recorder: instance_double(Mutant::Segment::Recorder), - stderr: instance_double(IO), - stdout: instance_double(IO), + stderr: instance_double(IO, :stderr), + stdout: instance_double(IO, :stdout), + tempfile: class_double(Tempfile), thread: class_double(Thread), time: class_double(Time), timer: instance_double(Mutant::Timer) diff --git a/spec/unit/mutant/env_spec.rb b/spec/unit/mutant/env_spec.rb index 89f6d0910..78f3f97de 100644 --- a/spec/unit/mutant/env_spec.rb +++ b/spec/unit/mutant/env_spec.rb @@ -77,6 +77,49 @@ def isolation_success(value) ) end + describe '#run_test_index' do + def apply + subject.run_test_index(test_index) + end + + let(:test_index) { 0 } + + let(:stderr_dup) { instance_double(IO, :stderr_dup) } + let(:stdout_dup) { instance_double(IO, :stdout_dup) } + let(:tempfile) { instance_double(IO, :tempfile) } + + let(:raw_expectations) do + [ + { + receiver: world.stdout, + selector: :dup, + arguments: [], + reaction: { return: stdout_dup } + }, + { + receiver: world.stderr, + selector: :dup, + arguments: [], + reaction: { return: stderr_dup } + }, + { + receiver: world.tempfile, + selector: :create, + reaction: { yields: [tempfile] } + }, + { + receiver: world.stdout, + selector: :reopen, + arguments: [tempfile] + }, + ] + end + + it 'returns env result' do + verify_events { expect(apply).to eql(nil) } + end + end + describe '#cover_index' do let(:mutation_index) { 0 } diff --git a/spec/unit/mutant/integration/rspec_spec.rb b/spec/unit/mutant/integration/rspec_spec.rb index 1d297bbe0..6d36ad48c 100644 --- a/spec/unit/mutant/integration/rspec_spec.rb +++ b/spec/unit/mutant/integration/rspec_spec.rb @@ -17,6 +17,7 @@ let(:rspec_options) { instance_double(RSpec::Core::ConfigurationOptions) } let(:rspec_runner) { instance_double(RSpec::Core::Runner) } let(:world) { fake_world } + let(:rspec_is_quitting) { false } let(:example_a) do double( @@ -113,7 +114,8 @@ RSpec::Core::World, example_groups: example_groups, filtered_examples: filtered_examples, - ordered_example_groups: ordered_example_groups + ordered_example_groups: ordered_example_groups, + rspec_is_quitting: rspec_is_quitting ) end