Add specification for runner isolation errors

This commit is contained in:
Markus Schirp 2014-07-07 14:07:47 +00:00
parent c986cedd84
commit d5f5564dc0
2 changed files with 64 additions and 32 deletions

View file

@ -121,15 +121,18 @@ module Mutant
# @api private
#
def run_mutation_test(mutation, test)
time = Time.now
config.isolation.call do
mutation.insert
test.run
end.update(test: test, mutation: mutation)
rescue Isolation::Error
rescue Isolation::Error => exception
Result::Test.new(
test: test,
output: exception.message,
passed: false
test: test,
mutation: mutation,
runtime: Time.now - time,
output: exception.message,
passed: false
)
end

View file

@ -4,7 +4,7 @@ describe Mutant::Runner do
let(:object) { described_class.new(env) }
let(:reporter) { Mutant::Reporter::Trace.new }
let(:config) { Mutant::Config::DEFAULT.update(reporter: reporter) }
let(:config) { Mutant::Config::DEFAULT.update(reporter: reporter, isolation: Mutant::Isolation::None) }
let(:subjects) { [subject_a, subject_b] }
class Double
@ -63,36 +63,65 @@ describe Mutant::Runner do
allow(Time).to receive(:now).and_return(time)
end
let(:expected_subject_results) do
[
Mutant::Result::Subject.new(
subject: subject_a,
mutation_results: [
Mutant::Result::Mutation.new(
mutation: mutation_a1,
runtime: 0.0,
test_results: [test_report_a1]
),
Mutant::Result::Mutation.new(
mutation: mutation_a2,
runtime: 0.0,
test_results: [test_report_a1]
)
],
runtime: 0.0
),
Mutant::Result::Subject.new(
subject: subject_b,
mutation_results: [],
runtime: 0.0
)
]
end
describe '#result' do
subject { object.result }
context 'on normal execution' do
subject { object.result }
its(:env) { should be(env) }
its(:subject_results) { should eql(expected_subject_results) }
its(:env) { should be(env) }
its(:subject_results) { should eql(expected_subject_results) }
end
context 'when isolation raises error' do
subject { object.result }
its(:env) { should be(env) }
its(:subject_results) { should eql(expected_subject_results) }
before do
expect(Mutant::Isolation::None).to receive(:call).and_raise(Mutant::Isolation::Error.new('test-exception-message')).twice
expect(Mutant::Result::Test).to receive(:new).with(
test: test_a1,
mutation: mutation_a1,
runtime: 0.0,
output: 'test-exception-message',
passed: false
).and_return(test_report_a1)
expect(Mutant::Result::Test).to receive(:new).with(
test: test_a1,
mutation: mutation_a2,
runtime: 0.0,
output: 'test-exception-message',
passed: false
).and_return(test_report_a1)
end
let(:expected_subject_results) do
[
Mutant::Result::Subject.new(
subject: subject_a,
mutation_results: [
Mutant::Result::Mutation.new(
mutation: mutation_a1,
runtime: 0.0,
test_results: [test_report_a1]
),
Mutant::Result::Mutation.new(
mutation: mutation_a2,
runtime: 0.0,
test_results: [test_report_a1]
)
],
runtime: 0.0
),
Mutant::Result::Subject.new(
subject: subject_b,
mutation_results: [],
runtime: 0.0
)
]
end
end
end