diff --git a/lib/mutant/loader.rb b/lib/mutant/loader.rb index 89565217..7a0b6b7e 100644 --- a/lib/mutant/loader.rb +++ b/lib/mutant/loader.rb @@ -15,6 +15,7 @@ module Mutant # @api private # def call + subject.prepare eval( source, TOPLEVEL_BINDING, diff --git a/lib/mutant/subject.rb b/lib/mutant/subject.rb index f032a24e..247ec039 100644 --- a/lib/mutant/subject.rb +++ b/lib/mutant/subject.rb @@ -29,6 +29,16 @@ module Mutant context.source_path end + # Prepare the subject for the insertion of mutation + # + # @return [self] + # + # @api private + # + def prepare + self + end + # Return source line # # @return [Fixnum] diff --git a/lib/mutant/subject/method.rb b/lib/mutant/subject/method.rb index cafebcba..fc414168 100644 --- a/lib/mutant/subject/method.rb +++ b/lib/mutant/subject/method.rb @@ -27,6 +27,17 @@ module Mutant node.children[self.class::NAME_INDEX] end + # Prepare subject for mutation insertion + # + # @return [self] + # + # @api private + # + def prepare + scope.send(:undef_method, name) + self + end + # Return match expression # # @return [String] diff --git a/spec/unit/mutant/loader/eval_spec.rb b/spec/unit/mutant/loader/eval_spec.rb index 8194a9e7..0c4d03d5 100644 --- a/spec/unit/mutant/loader/eval_spec.rb +++ b/spec/unit/mutant/loader/eval_spec.rb @@ -14,6 +14,10 @@ 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/subject/method/instance_spec.rb b/spec/unit/mutant/subject/method/instance_spec.rb index b9236024..02d71ec0 100644 --- a/spec/unit/mutant/subject/method/instance_spec.rb +++ b/spec/unit/mutant/subject/method/instance_spec.rb @@ -12,6 +12,28 @@ describe Mutant::Subject::Method::Instance do s(:def, :foo, s(:args)) end + describe '#prepare' do + + let(:context) do + Mutant::Context::Scope.new(scope, double('Source Path')) + end + + let(:scope) do + Class.new do + def foo + end + end + end + + subject { object.prepare } + + it 'undefines method on scope' do + expect { subject }.to change { scope.instance_methods.include?(:foo) }.from(true).to(false) + end + + it_should_behave_like 'a command method' + end + describe '#source' do subject { object.source }