2014-11-17 12:05:02 -05:00
|
|
|
RSpec.describe Mutant::Mutator::Registry do
|
|
|
|
describe '#lookup' do
|
|
|
|
subject { Mutant::Mutator::REGISTRY.lookup(node) }
|
|
|
|
|
2014-11-22 14:16:07 -05:00
|
|
|
context 'on registered node' do
|
2014-11-17 12:05:02 -05:00
|
|
|
let(:node) { s(:true) }
|
|
|
|
|
|
|
|
it { should eql(Mutant::Mutator::Node::Literal::Boolean) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on unknown node' do
|
|
|
|
let(:node) { s(:unknown) }
|
|
|
|
|
|
|
|
it 'raises error' do
|
2014-11-22 14:16:41 -05:00
|
|
|
expect { subject }.to raise_error(described_class::RegistryError, 'No mutator to handle: :unknown')
|
2014-11-17 12:05:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#register' do
|
|
|
|
let(:object) { described_class.new }
|
|
|
|
|
|
|
|
let(:mutator) { double('Mutator') }
|
|
|
|
|
|
|
|
subject { object.register(type, mutator) }
|
|
|
|
|
2014-11-22 14:16:07 -05:00
|
|
|
context 'when registering an invalid node type' do
|
2014-11-17 12:05:02 -05:00
|
|
|
let(:type) { :invalid }
|
|
|
|
|
|
|
|
it 'raises error' do
|
|
|
|
expect { subject }.to raise_error(described_class::RegistryError, 'Invalid type registration: invalid')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-22 14:16:07 -05:00
|
|
|
context 'when registering a valid node type' do
|
2014-11-17 12:05:02 -05:00
|
|
|
let(:type) { :true }
|
|
|
|
|
|
|
|
it 'allows to lookup mutator' do
|
|
|
|
subject
|
|
|
|
expect(object.lookup(s(type))).to be(mutator)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a command method'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when duplicate the registration of a valid node type' do
|
|
|
|
let(:type) { :true }
|
|
|
|
|
|
|
|
it 'allows to lookup mutator' do
|
|
|
|
object.register(type, mutator)
|
|
|
|
expect { subject }.to raise_error(described_class::RegistryError, 'Duplicate type registration: true')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a command method'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|