Sha256: a8a1e7ff8a977d0e4191e6bba79116eaaaa502c9bf6d4e2ee102babf9ccd88b5

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

RSpec.describe Mutant::Mutator::Registry do
  describe '#lookup' do
    subject { Mutant::Mutator::REGISTRY.lookup(node) }

    context 'on registred node' do
      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
        expect { subject }.to raise_error(described_class::RegistryError, "No mutator to handle: :unknown")
      end
    end
  end

  describe '#register' do
    let(:object) { described_class.new }

    let(:mutator) { double('Mutator') }

    subject { object.register(type, mutator) }

    context 'when registring an invalid node type' do
      let(:type) { :invalid }

      it 'raises error' do
        expect { subject }.to raise_error(described_class::RegistryError, 'Invalid type registration: invalid')
      end
    end

    context 'when registring a valid node type' do
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mutant-0.6.7 spec/unit/mutant/mutator/registry_spec.rb