Sha256: dcbcbb6bf2dbb0d96a8db2e29057bd3b6644e85eba981868fbcfdbc16ec68159

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

class AbstractMapper

  describe AbstractMapper::Commands do

    let(:foo)       { Test::Foo = Class.new(AbstractMapper::Branch) }
    let(:bar)       { Test::Bar = Class.new(AbstractMapper::Node)   }
    let(:test)      { Class.new(described_class)                    }
    let(:commands)  { test.new                                      }
    let(:converter) { -> v { v.reverse }                            }

    describe ".new" do

      let(:registry) { { foo: foo, bar: bar } }
      subject { test.new(registry) }

      it { is_expected.to be_frozen }

      it "doesn't freeze arguments" do
        expect { subject }.not_to change { registry.frozen? }
      end

    end # describe .new

    describe "#[]" do

      subject { commands << ["foo", foo] }

      it "returns registered command" do
        expect(subject["foo"]).to be_kind_of Command
      end

      it "complains about unknown command" do
        expect { subject[:baz] }.to raise_error do |error|
          expect(error).to be_kind_of AbstractMapper::Errors::UnknownCommand
          expect(error.message).to include "baz"
        end
      end

    end # describe #[]

    describe "#<<" do

      subject { commands << ["foo", foo] << ["bar", bar, converter] }

      it { is_expected.to be_kind_of test }

      it "preserves registered commands" do
        expect(subject[:foo]).to be_kind_of Command
      end

      it "registers new command" do
        expect(subject[:bar]).to be_kind_of Command
        expect(subject[:bar].name).to eql :bar
        expect(subject[:bar].klass).to eql bar
        expect(subject[:bar].converter).to eql converter
      end

    end # describe #<<

  end # describe AbstractMapper::Commands

end # class AbstractMapper

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
abstract_mapper-0.0.2 spec/unit/abstract_mapper/commands_spec.rb