2016-05-05 23:36:46 -07:00
|
|
|
RSpec.describe Mutant::Registry do
|
2016-09-16 01:04:31 -07:00
|
|
|
let(:lookup) { object.lookup(type) }
|
|
|
|
let(:object) { described_class.new }
|
|
|
|
let(:mutator) { class_double(Mutant::Mutator) }
|
2016-05-05 23:36:46 -07:00
|
|
|
|
|
|
|
def register_mutator
|
|
|
|
object.register(type, mutator)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on registered type' do
|
|
|
|
subject { register_mutator }
|
|
|
|
|
|
|
|
let(:type) { :true }
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
it 'returns registered mutator' do
|
|
|
|
expect(lookup).to be(mutator)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a command method'
|
|
|
|
|
|
|
|
context 'when registered twice' do
|
|
|
|
it 'fails upon registration' do
|
|
|
|
expect { register_mutator }.to raise_error(described_class::RegistryError, 'Duplicate type registration: :true')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on unknown type' do
|
|
|
|
let(:type) { :unknown }
|
|
|
|
|
|
|
|
it 'raises error' do
|
|
|
|
expect { lookup }.to raise_error(described_class::RegistryError, 'No entry for: :unknown')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when registering an invalid node type' do
|
|
|
|
let(:type) { :invalid }
|
|
|
|
|
|
|
|
it 'raises error' do
|
|
|
|
expect { register_mutator }.to raise_error(described_class::RegistryError, 'Invalid type registration: :invalid')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|