Undefine methods before loading mutants

* Closes #163
This commit is contained in:
Markus Schirp 2014-03-14 21:34:21 +00:00
parent fd5fd42125
commit df9207cad4
5 changed files with 48 additions and 0 deletions

View file

@ -15,6 +15,7 @@ module Mutant
# @api private
#
def call
subject.prepare
eval(
source,
TOPLEVEL_BINDING,

View file

@ -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]

View file

@ -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]

View file

@ -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

View file

@ -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 }