Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Feb 16, 2024
1 parent 6691b0a commit 35f3694
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ module Mutant
recorder: recorder,
stderr: $stderr,
stdout: $stdout,
tempfile: Tempfile,
thread: Thread,
time: Time,
timer: timer
Expand Down
4 changes: 3 additions & 1 deletion lib/mutant/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/mutant/integration/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/mutant/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class World
:recorder,
:stderr,
:stdout,
:tempfile,
:thread,
:time,
:timer
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions spec/unit/mutant/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 3 additions & 1 deletion spec/unit/mutant/integration/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 35f3694

Please sign in to comment.