Sha256: 7d8bb72594c94e262e0d7c5277fb19d687495658c6022803d95c0c7c05b7e27b

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

# encoding: utf-8

describe AbstractMapper::Builder do

  before do
    AbstractMapper::Test::Builder = Class.new(described_class)
    AbstractMapper::Test::Foo     = Class.new(AbstractMapper::Node)
    AbstractMapper::Test::Bar     = Class.new(AbstractMapper::Branch)
  end

  let(:builder)  { test.new tree                          }
  let(:test)     { AbstractMapper::Test::Builder          }
  let(:commands) { AbstractMapper::Commands.new(registry) }
  let(:tree)     { AbstractMapper::Test::Foo.new          }
  let(:registry) do
    { foo: AbstractMapper::Test::Foo, bar: AbstractMapper::Test::Bar }
  end

  describe ".commands=" do

    subject { test.commands = commands }

    it "sets the commands" do
      expect { subject }.to change { test.commands }.to commands
    end

  end # describe .commands=

  describe ".update" do

    before { test.commands = commands }

    context "by default" do

      subject { test.update }

      it "is an empty branch" do
        expect(subject).to be_instance_of AbstractMapper::Branch
        expect(subject.entries).to be_empty
      end

    end # context

    context "initialized" do

      subject { test.update(tree) }
      it { is_expected.to eql tree }

    end # context

    context "with a block" do

      subject { test.update { bar { foo(:foo) { fail } } } }

      it "is built" do
        expect(subject.inspect).to eql "<Root [<Bar [<Foo(:foo)>]>]>"
        expect(subject.first.first.block).not_to be_nil
      end

    end # context

  end # describe .update

  describe ".new" do

    subject { builder }
    it { is_expected.to be_frozen }

  end # describe .new

  describe "#respond_to?" do

    subject { builder.respond_to? :arbitrary_method }
    it { is_expected.to eql true }

  end # describe #respond_to?

end # describe AbstractMapper::Builder

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
abstract_mapper-0.0.1 spec/unit/abstract_mapper/builder_spec.rb