spec/unit/mutant/env_spec.rb in mutant-0.8.8 vs spec/unit/mutant/env_spec.rb in mutant-0.8.9

- old
+ new

@@ -1,75 +1,117 @@ RSpec.describe Mutant::Env do context '#kill' do let(:object) do described_class.new( - config: config, actor_env: Mutant::Actor::Env.new(Thread), - cache: Mutant::Cache.new, + config: config, + integration: integration, + matchable_scopes: [], + mutations: [], selector: selector, subjects: [], - mutations: [], - matchable_scopes: [], - integration: integration + parser: Mutant::Parser.new ) end - let(:integration) { integration_class.new(config) } + let(:integration) { instance_double(Mutant::Integration) } + 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(:config) do - Mutant::Config::DEFAULT.with(isolation: isolation, integration: integration_class) + let(:isolation) do + instance_double(Mutant::Isolation::Fork.singleton_class) end - let(:isolation) { double('Isolation') } - let(:mutation) { Mutant::Mutation::Evil.new(mutation_subject, Mutant::AST::Nodes::N_NIL) } - let(:wrapped_node) { double('Wrapped Node') } - let(:context) { double('Context') } - let(:test_a) { double('Test A') } - let(:test_b) { double('Test B') } - let(:tests) { [test_a, test_b] } - let(:selector) { double('Selector') } - let(:integration_class) { Mutant::Integration::Null } + let(:mutation) do + instance_double( + Mutant::Mutation, + subject: mutation_subject + ) + end + let(:config) do + Mutant::Config::DEFAULT.with( + isolation: isolation, + integration: integration_class, + kernel: instance_double(Kernel.singleton_class) + ) + end + let(:mutation_subject) do - double( - 'Subject', - identification: 'subject', + instance_double( + Mutant::Subject, context: context, - source: 'original', - tests: tests + identification: 'subject', + source: 'original' ) end subject { object.kill(mutation) } shared_examples_for 'mutation kill' do - it { should eql(Mutant::Result::Mutation.new(mutation: mutation, test_result: test_result)) } + specify do + should eql( + Mutant::Result::Mutation.new( + mutation: mutation, + test_result: test_result + ) + ) + end end before do - expect(selector).to receive(:call).with(mutation_subject).and_return(tests) - allow(Time).to receive(:now).and_return(Time.at(0)) + expect(selector).to receive(:call) + .with(mutation_subject) + .and_return(tests) + + allow(Time).to receive_messages(now: Time.at(0)) end context 'when isolation does not raise error' do - let(:test_result) { double('Test Result A', passed: false) } + let(:test_result) do + instance_double( + Mutant::Result::Test, + passed: false + ) + end before do - expect(isolation).to receive(:call).and_yield.and_return(test_result) - expect(mutation_subject).to receive(:prepare).and_return(mutation_subject).ordered - expect(context).to receive(:root).with(s(:nil)).and_return(wrapped_node).ordered - expect(Mutant::Loader::Eval).to receive(:call).with(wrapped_node, mutation_subject).and_return(nil).ordered + expect(isolation).to receive(:call) + .ordered + .and_yield + + expect(mutation).to receive(:insert) + .ordered + .with(config.kernel) + + 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 - expect(isolation).to receive(:call).and_raise(Mutant::Isolation::Error, 'test-error') + expect(isolation).to receive(:call) + .and_raise(Mutant::Isolation::Error, 'test-error') end - let(:test_result) { Mutant::Result::Test.new(tests: tests, output: 'test-error', passed: false, runtime: 0.0) } + let(:test_result) do + Mutant::Result::Test.new( + output: 'test-error', + passed: false, + runtime: 0.0, + tests: tests + ) + end include_examples 'mutation kill' end end end