Fix undef before insertion for singleton methods

This commit is contained in:
Markus Schirp 2014-03-15 17:00:18 +00:00
parent df9207cad4
commit 15dc96f112
4 changed files with 64 additions and 11 deletions

View file

@ -27,17 +27,6 @@ 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

@ -24,6 +24,17 @@ module Mutant
end
memoize :public?
# Prepare subject for mutation insertion
#
# @return [self]
#
# @api private
#
def prepare
scope.send(:undef_method, name)
self
end
private
# Mutator for memoized instance methods

View file

@ -24,6 +24,17 @@ module Mutant
end
memoize :public?
# Prepare subject for mutation insertion
#
# @return [self]
#
# @api private
#
def prepare
scope.singleton_class.send(:undef_method, name)
self
end
end # Singleton
end # Method
end # Subject

View file

@ -0,0 +1,42 @@
# encoding: UTF-8
require 'spec_helper'
describe Mutant::Subject::Method::Singleton do
include Mutant::NodeHelpers
let(:object) { described_class.new(context, node) }
let(:context) { double }
let(:node) do
s(:defs, s(:self), :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 self.foo
end
end
end
subject { object.prepare }
it 'undefines method on scope' do
expect { subject }.to change { scope.methods.include?(:foo) }.from(true).to(false)
end
it_should_behave_like 'a command method'
end
describe '#source' do
subject { object.source }
it { should eql("def self.foo\nend") }
end
end