From df7de1ee86c2c69cf80379b747e890612d27abfa Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Fri, 28 Mar 2014 15:42:46 +0000 Subject: [PATCH] Delete memoizer on Subject#prepare --- lib/mutant/subject/method/instance.rb | 12 ++++++++ .../mutant/subject/method/instance_spec.rb | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/mutant/subject/method/instance.rb b/lib/mutant/subject/method/instance.rb index c741b5df..cceb4124 100644 --- a/lib/mutant/subject/method/instance.rb +++ b/lib/mutant/subject/method/instance.rb @@ -52,6 +52,18 @@ module Mutant end memoize :source + # Prepare subject for mutation insertion + # + # @return [self] + # + # @api private + # + def prepare + scope.send(:memoized_methods).instance_variable_get(:@memory).delete(name) + scope.send(:undef_method, name) + self + end + private # Return mutations diff --git a/spec/unit/mutant/subject/method/instance_spec.rb b/spec/unit/mutant/subject/method/instance_spec.rb index 02d71ec0..76b29207 100644 --- a/spec/unit/mutant/subject/method/instance_spec.rb +++ b/spec/unit/mutant/subject/method/instance_spec.rb @@ -51,6 +51,35 @@ describe Mutant::Subject::Method::Instance::Memoized 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 + include Memoizable + def foo + end + memoize :foo + end + end + + subject { object.prepare } + + it 'undefines memoizer' do + expect { subject }.to change { scope.memoized?(:foo) }.from(true).to(false) + end + + 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 }