Sha256: d76194f3151ce9ce86bb57d7b2b999b8cf35de2e17c3dc7f21ed84497aaa4730

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe DispatchRider::Registrars::Base do
  subject do
    described_class.new
  end

  describe "#initialize" do
    it "assigns store" do
      expect(subject.store).to be_empty
    end
  end

  describe "#register" do
    it "registers the value" do
      expect(subject).to receive(:value).with(:foo, {}).and_return("bar")
      subject.register(:foo)
      expect(subject.fetch(:foo)).to eq('bar')
    end

    it "should return the registrar" do
      expect(subject).to receive(:value).with(:foo, {}).and_return("bar")
      expect(subject.register(:foo)).to eq(subject)
    end

    context "when there is a missing constant while registering" do
      it "raises an exception" do
        expect(subject).to receive(:value).with(:foo, {}) { 'bar'.camelize.constantize }
        expect { subject.register(:foo) }.to raise_exception(DispatchRider::NotFound)
      end
    end
  end

  describe "#unregister" do
    before do
      allow(subject).to receive(:value).and_return('bar')
      subject.register(:foo)
    end

    it "unregisters the key/value pair from the registrar" do
      subject.unregister(:foo)
      expect { subject.fetch(:foo) }.to raise_exception(DispatchRider::NotRegistered)
    end

    it "returns the registrar" do
      expect(subject.unregister(:foo)).to eq(subject)
    end
  end

  describe "#fetch" do
    context "when a key/value pair is registered" do
      before do
        allow(subject).to receive(:value).and_return('bar')
        subject.register(:foo)
      end

      it "return the value for the key" do
        expect(subject.fetch(:foo)).to eq('bar')
      end
    end

    context "when a key/value pair is not registered" do
      it "raises an exception" do
        expect { subject.fetch(:foo) }.to raise_exception(DispatchRider::NotRegistered)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dispatch-rider-2.2.0 spec/lib/dispatch-rider/registrars/base_spec.rb