2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::Subject::Method::Instance do
|
2014-07-03 17:16:12 -04:00
|
|
|
let(:object) { described_class.new(config, context, node) }
|
2014-08-11 10:56:39 -04:00
|
|
|
let(:context) { Mutant::Context::Scope.new(scope, double('Source Path')) }
|
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-08-11 10:56:39 -04:00
|
|
|
let(:scope) do
|
|
|
|
Class.new do
|
|
|
|
attr_reader :bar
|
2014-03-14 17:34:21 -04:00
|
|
|
|
2014-08-11 10:56:39 -04:00
|
|
|
def initialize
|
|
|
|
@bar = :boo
|
|
|
|
end
|
|
|
|
|
|
|
|
def foo
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.name
|
|
|
|
'Test'
|
|
|
|
end
|
2014-03-14 17:34:21 -04:00
|
|
|
end
|
2014-08-11 10:56:39 -04:00
|
|
|
end
|
2014-03-14 17:34:21 -04:00
|
|
|
|
2014-08-11 10:56:39 -04:00
|
|
|
describe '#expression' do
|
|
|
|
subject { object.expression }
|
2014-04-22 14:59:38 -04:00
|
|
|
|
2014-08-11 10:56:39 -04:00
|
|
|
it { should eql(Mutant::Expression.parse('Test#foo')) }
|
2014-04-22 14:59:38 -04:00
|
|
|
|
2014-08-11 10:56:39 -04:00
|
|
|
it_should_behave_like 'an idempotent method'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#prepare' do
|
|
|
|
|
|
|
|
let(:context) do
|
|
|
|
Mutant::Context::Scope.new(scope, double('Source Path'))
|
2014-03-14 17:34:21 -04:00
|
|
|
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
|
|
|
|
|
2014-08-10 17:04:05 -04:00
|
|
|
RSpec.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
|