diff --git a/config/flay.yml b/config/flay.yml index 01bcef9d..d9dc814e 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1121 +total_score: 1119 diff --git a/lib/mutant/loader.rb b/lib/mutant/loader.rb index aae58b0e..0ddd097d 100644 --- a/lib/mutant/loader.rb +++ b/lib/mutant/loader.rb @@ -13,14 +13,13 @@ module Mutant # @api private # def call - subject.prepare eval( source, TOPLEVEL_BINDING, subject.source_path.to_s, subject.source_line ) - nil + self end private diff --git a/lib/mutant/mutation.rb b/lib/mutant/mutation.rb index 14612bcc..545c2e8b 100644 --- a/lib/mutant/mutation.rb +++ b/lib/mutant/mutation.rb @@ -7,17 +7,6 @@ module Mutant CODE_DELIMITER = "\0".freeze CODE_RANGE = (0..4).freeze - # Return mutated root node - # - # @return [Parser::AST::Node] - # - # @api private - # - def root - subject.root(node) - end - memoize :root - # Insert mutated node # # FIXME: Cache subject visibility in a better way! Ideally dont mutate it @@ -30,6 +19,7 @@ module Mutant # def insert subject.public? + subject.prepare Loader::Eval.call(root, subject) self end @@ -102,6 +92,16 @@ module Mutant end memoize :sha1 + # Return mutated root node + # + # @return [Parser::AST::Node] + # + # @api private + # + def root + subject.root(node) + end + # Evil mutation that should case mutations to fail tests class Evil < self diff --git a/spec/unit/mutant/loader/eval_spec.rb b/spec/unit/mutant/loader/eval_spec.rb index 2570b433..0f9fbc07 100644 --- a/spec/unit/mutant/loader/eval_spec.rb +++ b/spec/unit/mutant/loader/eval_spec.rb @@ -10,10 +10,6 @@ RSpec.describe Mutant::Loader::Eval, '.call' do double('Subject', source_path: path, source_line: line) end - before do - expect(mutation_subject).to receive(:prepare).and_return(mutation_subject) - end - let(:source) do <<-RUBY class SomeNamespace diff --git a/spec/unit/mutant/mutation_spec.rb b/spec/unit/mutant/mutation_spec.rb index a1ba70f2..51318329 100644 --- a/spec/unit/mutant/mutation_spec.rb +++ b/spec/unit/mutant/mutation_spec.rb @@ -6,7 +6,6 @@ RSpec.describe Mutant::Mutation do let(:object) { TestMutation.new(mutation_subject, Mutant::AST::Nodes::N_NIL) } let(:mutation_subject) { double('Subject', identification: 'subject', source: 'original') } - let(:node) { double('Node') } describe '#code' do subject { object.code } @@ -24,6 +23,21 @@ RSpec.describe Mutant::Mutation do it_should_behave_like 'an idempotent method' end + describe '#insert' do + subject { object.insert } + + let(:wrapped_node) { double('Wrapped Node') } + + before do + expect(mutation_subject).to receive(:public?).ordered.and_return(true) + expect(mutation_subject).to receive(:prepare).ordered + expect(mutation_subject).to receive(:root).ordered.with(s(:nil)).and_return(wrapped_node) + expect(Mutant::Loader::Eval).to receive(:call).ordered.with(wrapped_node, mutation_subject).and_return(nil) + end + + it_should_behave_like 'a command method' + end + describe '#source' do subject { object.source }