2014-11-17 21:03:40 +00:00
|
|
|
RSpec.describe Mutant::Env do
|
2014-12-22 16:21:51 +00:00
|
|
|
context '#kill' do
|
2014-12-22 15:42:21 +00:00
|
|
|
let(:object) do
|
|
|
|
described_class.new(
|
|
|
|
actor_env: Mutant::Actor::Env.new(Thread),
|
2015-11-15 20:13:48 +00:00
|
|
|
config: config,
|
|
|
|
integration: integration,
|
|
|
|
matchable_scopes: [],
|
|
|
|
mutations: [],
|
2014-12-22 15:42:21 +00:00
|
|
|
selector: selector,
|
|
|
|
subjects: [],
|
2015-11-15 20:13:48 +00:00
|
|
|
parser: Mutant::Parser.new
|
2014-12-22 15:42:21 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-02-14 21:11:32 +00:00
|
|
|
let(:integration) { instance_double(Mutant::Integration) }
|
|
|
|
let(:context) { instance_double(Mutant::Context) }
|
|
|
|
let(:test_a) { instance_double(Mutant::Test) }
|
|
|
|
let(:test_b) { instance_double(Mutant::Test) }
|
|
|
|
let(:tests) { [test_a, test_b] }
|
|
|
|
let(:selector) { instance_double(Mutant::Selector) }
|
|
|
|
let(:integration_class) { Mutant::Integration::Null }
|
|
|
|
let(:isolation) { instance_double(Mutant::Isolation::Fork) }
|
2015-06-21 14:44:33 +00:00
|
|
|
|
2015-11-21 22:02:51 +00:00
|
|
|
let(:mutation) do
|
|
|
|
instance_double(
|
|
|
|
Mutant::Mutation,
|
|
|
|
subject: mutation_subject
|
|
|
|
)
|
2014-12-22 15:42:21 +00:00
|
|
|
end
|
2014-12-09 00:10:31 +00:00
|
|
|
|
2015-11-21 22:02:51 +00:00
|
|
|
let(:config) do
|
|
|
|
Mutant::Config::DEFAULT.with(
|
|
|
|
isolation: isolation,
|
|
|
|
integration: integration_class,
|
2016-01-24 21:16:43 +00:00
|
|
|
kernel: class_double(Kernel)
|
2015-11-21 22:02:51 +00:00
|
|
|
)
|
|
|
|
end
|
2014-12-22 14:42:20 +00:00
|
|
|
|
2014-12-22 15:42:21 +00:00
|
|
|
let(:mutation_subject) do
|
2015-11-15 20:16:42 +00:00
|
|
|
instance_double(
|
|
|
|
Mutant::Subject,
|
2016-03-19 13:51:21 -07:00
|
|
|
context: context,
|
2015-11-15 20:13:48 +00:00
|
|
|
identification: 'subject',
|
2016-03-19 13:51:21 -07:00
|
|
|
source: 'original'
|
2014-12-22 15:42:21 +00:00
|
|
|
)
|
|
|
|
end
|
2014-12-09 00:10:31 +00:00
|
|
|
|
2014-12-22 16:21:51 +00:00
|
|
|
subject { object.kill(mutation) }
|
2014-12-09 00:10:31 +00:00
|
|
|
|
2014-12-22 15:42:21 +00:00
|
|
|
shared_examples_for 'mutation kill' do
|
2015-11-21 22:02:51 +00:00
|
|
|
specify do
|
|
|
|
should eql(
|
|
|
|
Mutant::Result::Mutation.new(
|
2016-03-19 13:51:21 -07:00
|
|
|
mutation: mutation,
|
2015-11-21 22:02:51 +00:00
|
|
|
test_result: test_result
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
2014-12-22 15:42:21 +00:00
|
|
|
end
|
|
|
|
|
2014-12-09 00:10:31 +00:00
|
|
|
before do
|
2015-11-16 01:35:59 +00:00
|
|
|
expect(selector).to receive(:call)
|
|
|
|
.with(mutation_subject)
|
|
|
|
.and_return(tests)
|
|
|
|
|
|
|
|
allow(Time).to receive_messages(now: Time.at(0))
|
2014-12-09 00:10:31 +00:00
|
|
|
end
|
|
|
|
|
2014-12-22 15:42:21 +00:00
|
|
|
context 'when isolation does not raise error' do
|
2015-11-21 22:02:51 +00:00
|
|
|
let(:test_result) do
|
|
|
|
instance_double(
|
|
|
|
Mutant::Result::Test,
|
|
|
|
passed: false
|
|
|
|
)
|
|
|
|
end
|
2014-12-22 15:42:21 +00:00
|
|
|
|
|
|
|
before do
|
2015-11-16 01:35:59 +00:00
|
|
|
expect(isolation).to receive(:call)
|
|
|
|
.ordered
|
|
|
|
.and_yield
|
|
|
|
|
2015-11-21 22:02:51 +00:00
|
|
|
expect(mutation).to receive(:insert)
|
2015-11-16 01:35:59 +00:00
|
|
|
.ordered
|
2015-11-21 22:02:51 +00:00
|
|
|
.with(config.kernel)
|
2015-11-16 01:35:59 +00:00
|
|
|
|
|
|
|
expect(integration).to receive(:call)
|
|
|
|
.ordered
|
|
|
|
.with(tests)
|
|
|
|
.and_return(test_result)
|
2014-12-22 15:42:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'mutation kill'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when isolation does raise error' do
|
|
|
|
before do
|
2015-11-16 01:35:59 +00:00
|
|
|
expect(isolation).to receive(:call)
|
|
|
|
.and_raise(Mutant::Isolation::Error, 'test-error')
|
2014-12-22 15:42:21 +00:00
|
|
|
end
|
|
|
|
|
2015-11-16 01:35:59 +00:00
|
|
|
let(:test_result) do
|
|
|
|
Mutant::Result::Test.new(
|
|
|
|
output: 'test-error',
|
|
|
|
passed: false,
|
2015-11-15 20:13:48 +00:00
|
|
|
runtime: 0.0,
|
|
|
|
tests: tests
|
2015-11-16 01:35:59 +00:00
|
|
|
)
|
|
|
|
end
|
2014-12-22 15:42:21 +00:00
|
|
|
|
|
|
|
include_examples 'mutation kill'
|
2014-12-09 00:10:31 +00:00
|
|
|
end
|
|
|
|
end
|
2014-11-17 21:03:40 +00:00
|
|
|
end
|