2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::Subject::Method::Instance do
|
2014-12-22 10:42:21 -05:00
|
|
|
let(:object) { described_class.new(context, node) }
|
2014-08-11 10:56:39 -04:00
|
|
|
let(:context) { Mutant::Context::Scope.new(scope, double('Source Path')) }
|
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
|
|
|
|
2015-06-21 10:44:33 -04:00
|
|
|
it { should eql(parse_expression('Test#foo')) }
|
2014-04-22 14:59:38 -04:00
|
|
|
|
2014-10-08 11:16:05 -04:00
|
|
|
it_should_behave_like 'an idempotent method'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#match_expression' do
|
|
|
|
subject { object.match_expressions }
|
|
|
|
|
2015-06-21 10:44:33 -04:00
|
|
|
it { should eql(%w[Test#foo Test*].map(&method(:parse_expression))) }
|
2014-10-08 11:16:05 -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-11-27 11:34:08 -05:00
|
|
|
it 'undefines method on scope' do
|
|
|
|
expect { subject }.to change { scope.instance_methods.include?(:foo) }.from(true).to(false)
|
2014-03-14 17:34:21 -04:00
|
|
|
end
|
|
|
|
|
2014-11-27 11:34:08 -05:00
|
|
|
it_should_behave_like 'a command method'
|
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
|
2014-11-17 16:16:25 -05:00
|
|
|
|
|
|
|
describe '#public?' do
|
|
|
|
subject { object.public? }
|
|
|
|
|
|
|
|
context 'when method is public' do
|
|
|
|
it { should be(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when method is private' do
|
|
|
|
before do
|
|
|
|
scope.class_eval do
|
|
|
|
private :foo
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should be(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when method is protected' do
|
|
|
|
before do
|
|
|
|
scope.class_eval do
|
|
|
|
protected :foo
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should be(false) }
|
|
|
|
end
|
|
|
|
end
|
2013-10-30 04:06:39 -04:00
|
|
|
end
|
|
|
|
|
2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::Subject::Method::Instance::Memoized do
|
2014-12-22 10:42:21 -05:00
|
|
|
let(:object) { described_class.new(context, node) }
|
|
|
|
let(:context) { double('Context') }
|
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
|
|
|
|
|
2014-11-17 16:13:07 -05:00
|
|
|
describe '#mutations' do
|
|
|
|
subject { object.mutations }
|
|
|
|
|
|
|
|
let(:expected) do
|
|
|
|
[
|
2014-10-23 07:37:53 -04:00
|
|
|
Mutant::Mutation::Neutral.new(
|
|
|
|
object,
|
|
|
|
s(:begin,
|
|
|
|
s(:def, :foo, s(:args)), s(:send, nil, :memoize, s(:args, s(:sym, :foo))))
|
|
|
|
),
|
|
|
|
Mutant::Mutation::Evil.new(
|
|
|
|
object,
|
|
|
|
s(:begin,
|
|
|
|
s(:def, :foo, s(:args), s(:send, nil, :raise)), s(:send, nil, :memoize, s(:args, s(:sym, :foo))))
|
|
|
|
),
|
|
|
|
Mutant::Mutation::Evil.new(
|
|
|
|
object,
|
|
|
|
s(:begin,
|
|
|
|
s(:def, :foo, s(:args), nil), s(:send, nil, :memoize, s(:args, s(:sym, :foo))))
|
2015-08-13 23:35:23 -04:00
|
|
|
),
|
|
|
|
Mutant::Mutation::Evil.new(
|
|
|
|
object,
|
|
|
|
s(:begin,
|
|
|
|
s(:send, nil, :remove_method, s(:sym, :foo)), s(:send, nil, :memoize, s(:args, s(:sym, :foo))))
|
2014-10-23 07:37:53 -04:00
|
|
|
)
|
2014-11-17 16:13:07 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should eql(expected) }
|
|
|
|
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
|