free_mutant/spec/unit/mutant/env_spec.rb

104 lines
3.2 KiB
Ruby
Raw Normal View History

RSpec.describe Mutant::Env do
context '#kill' do
let(:object) do
described_class.new(
config: config,
actor_env: Mutant::Actor::Env.new(Thread),
parser: Mutant::Parser.new,
selector: selector,
subjects: [],
mutations: [],
matchable_scopes: [],
integration: integration
)
end
2015-11-16 01:35:59 +00:00
let(:integration) { instance_double(Mutant::Integration) }
let(:config) do
2015-09-04 20:20:56 +00:00
Mutant::Config::DEFAULT.with(isolation: isolation, integration: integration_class)
end
2014-12-09 00:10:31 +00:00
let(:isolation) { instance_double(Mutant::Isolation::Fork.singleton_class) }
let(:mutation) { Mutant::Mutation::Evil.new(mutation_subject, Mutant::AST::Nodes::N_NIL) }
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) }
let(:tests) { [test_a, test_b] }
let(:selector) { instance_double(Mutant::Selector) }
let(:integration_class) { Mutant::Integration::Null }
let(:mutation_subject) do
instance_double(
Mutant::Subject,
identification: 'subject',
context: context,
source: 'original'
)
end
2014-12-09 00:10:31 +00:00
subject { object.kill(mutation) }
2014-12-09 00:10:31 +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
context 'when isolation does not raise error' do
let(:test_result) { instance_double(Mutant::Result::Test, passed: false) }
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)
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')
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
include_examples 'mutation kill'
2014-12-09 00:10:31 +00:00
end
end
end