2013-12-07 13:07:18 -05:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
2013-10-30 04:06:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Mutant::Subject::Method::Instance do
|
2014-07-03 17:16:12 -04:00
|
|
|
let(:object) { described_class.new(config, context, node) }
|
2013-10-30 04:06:39 -04:00
|
|
|
let(:context) { double }
|
2014-07-03 17:16:12 -04:00
|
|
|
let(:config) { Mutant::Config::DEFAULT }
|
2013-10-30 04:06:39 -04:00
|
|
|
|
|
|
|
let(:node) do
|
|
|
|
s(:def, :foo, s(:args))
|
|
|
|
end
|
|
|
|
|
2014-03-14 17:34:21 -04:00
|
|
|
describe '#prepare' do
|
|
|
|
|
|
|
|
let(:context) do
|
|
|
|
Mutant::Context::Scope.new(scope, double('Source Path'))
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:scope) do
|
|
|
|
Class.new do
|
2014-04-22 14:59:38 -04:00
|
|
|
attr_reader :bar
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@bar = :boo
|
|
|
|
end
|
|
|
|
|
2014-03-14 17:34:21 -04:00
|
|
|
def foo
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { object.prepare }
|
|
|
|
|
2014-04-22 14:59:38 -04:00
|
|
|
context 'on non initialize methods' do
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
2014-03-14 17:34:21 -04:00
|
|
|
end
|
|
|
|
|
2014-04-22 14:59:38 -04:00
|
|
|
context 'on initialize method' do
|
|
|
|
|
|
|
|
let(:node) do
|
|
|
|
s(:def, :initialize, s(:args))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not write warnings' do
|
|
|
|
warnings = Mutant::WarningFilter.use do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
expect(warnings).to eql([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'undefines method on scope' do
|
|
|
|
subject
|
|
|
|
expect { scope.new }.to raise_error(NoMethodError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'a command method'
|
|
|
|
end
|
2014-03-14 17:34:21 -04:00
|
|
|
end
|
|
|
|
|
2013-10-30 04:06:39 -04:00
|
|
|
describe '#source' do
|
|
|
|
subject { object.source }
|
|
|
|
|
|
|
|
it { should eql("def foo\nend") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Mutant::Subject::Method::Instance::Memoized do
|
2014-07-03 17:16:12 -04:00
|
|
|
let(:object) { described_class.new(config, context, node) }
|
|
|
|
let(:context) { double }
|
|
|
|
let(:config) { Mutant::Config::DEFAULT }
|
2013-10-30 04:06:39 -04:00
|
|
|
|
|
|
|
let(:node) do
|
|
|
|
s(:def, :foo, s(:args))
|
|
|
|
end
|
|
|
|
|
2014-03-28 11:42:46 -04:00
|
|
|
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
|
|
|
|
|
2013-10-30 04:06:39 -04:00
|
|
|
describe '#source' do
|
|
|
|
subject { object.source }
|
|
|
|
|
|
|
|
it { should eql("def foo\nend\nmemoize(:foo)") }
|
|
|
|
end
|
|
|
|
end
|