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(
|
|
|
|
config: config,
|
|
|
|
actor_env: Mutant::Actor::Env.new(Thread),
|
2015-11-13 04:47:47 +00:00
|
|
|
parser: Mutant::Parser.new,
|
2014-12-22 15:42:21 +00:00
|
|
|
selector: selector,
|
|
|
|
subjects: [],
|
|
|
|
mutations: [],
|
2015-06-29 02:10:04 +00:00
|
|
|
matchable_scopes: [],
|
2015-06-21 14:44:33 +00:00
|
|
|
integration: integration
|
2014-12-22 15:42:21 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-11-16 01:35:59 +00:00
|
|
|
let(:integration) { instance_double(Mutant::Integration) }
|
2015-06-21 14:44:33 +00:00
|
|
|
|
2014-12-22 15:42:21 +00:00
|
|
|
let(:config) do
|
2015-09-04 20:20:56 +00:00
|
|
|
Mutant::Config::DEFAULT.with(isolation: isolation, integration: integration_class)
|
2014-12-22 15:42:21 +00:00
|
|
|
end
|
2014-12-09 00:10:31 +00:00
|
|
|
|
2015-11-15 20:16:42 +00:00
|
|
|
let(:isolation) { instance_double(Mutant::Isolation::Fork.singleton_class) }
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:mutation) { Mutant::Mutation::Evil.new(mutation_subject, Mutant::AST::Nodes::N_NIL) }
|
2015-11-15 20:16:42 +00:00
|
|
|
let(:wrapped_node) { instance_double(Parser::AST::Node) }
|
|
|
|
let(:context) { instance_double(Mutant::Context) }
|
|
|
|
let(:test_a) { instance_double(Mutant::Test) }
|
|
|
|
let(:test_b) { instance_double(Mutant::Test) }
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:tests) { [test_a, test_b] }
|
2015-11-15 20:16:42 +00:00
|
|
|
let(:selector) { instance_double(Mutant::Selector) }
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:integration_class) { Mutant::Integration::Null }
|
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,
|
2014-12-22 15:42:21 +00:00
|
|
|
identification: 'subject',
|
|
|
|
context: context,
|
2015-11-15 20:16:42 +00: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
|
|
|
|
it { should eql(Mutant::Result::Mutation.new(mutation: mutation, test_result: test_result)) }
|
|
|
|
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-15 20:16:42 +00:00
|
|
|
let(:test_result) { instance_double(Mutant::Result::Test, passed: false) }
|
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
|
|
|
|
|
|
|
|
expect(mutation_subject).to receive(:prepare)
|
|
|
|
.ordered
|
|
|
|
.and_return(mutation_subject)
|
|
|
|
|
|
|
|
expect(context).to receive(:root)
|
|
|
|
.with(s(:nil))
|
|
|
|
.and_return(wrapped_node)
|
|
|
|
|
|
|
|
expect(Mutant::Loader::Eval).to receive(:call)
|
|
|
|
.ordered
|
|
|
|
.with(wrapped_node, mutation_subject)
|
|
|
|
.and_return(Mutant::Loader::Eval)
|
|
|
|
|
|
|
|
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(
|
|
|
|
tests: tests,
|
|
|
|
output: 'test-error',
|
|
|
|
passed: false,
|
|
|
|
runtime: 0.0
|
|
|
|
)
|
|
|
|
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
|