free_mutant/spec/unit/mutant/subject/method/instance_spec.rb

113 lines
2.3 KiB
Ruby

RSpec.describe Mutant::Subject::Method::Instance do
let(:object) { described_class.new(config, context, node) }
let(:context) { double }
let(:config) { Mutant::Config::DEFAULT }
let(:node) 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
attr_reader :bar
def initialize
@bar = :boo
end
def foo
end
end
end
subject { object.prepare }
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'
end
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
end
describe '#source' do
subject { object.source }
it { should eql("def foo\nend") }
end
end
RSpec.describe Mutant::Subject::Method::Instance::Memoized do
let(:object) { described_class.new(config, context, node) }
let(:context) { double }
let(:config) { Mutant::Config::DEFAULT }
let(:node) 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 }
it { should eql("def foo\nend\nmemoize(:foo)") }
end
end