Sha256: 88faf302d22edbab29c92f9a9d1c60b03f7be45d94a8dba35abc542ef43f632c

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Split::Persistence do
  subject { Split::Persistence }

  describe ".adapter" do
    context "when the persistence config is a symbol" do
      it "should return the appropriate adapter for the symbol" do
        expect(Split.configuration).to receive(:persistence).twice.and_return(:cookie)
        expect(subject.adapter).to eq(Split::Persistence::CookieAdapter)
      end

      it "should return an adapter whose class is present in Split::Persistence::ADAPTERS" do
        expect(Split.configuration).to receive(:persistence).twice.and_return(:cookie)
        expect(Split::Persistence::ADAPTERS.values).to include(subject.adapter)
      end

      it "should raise if the adapter cannot be found" do
        expect(Split.configuration).to receive(:persistence).twice.and_return(:something_weird)
        expect { subject.adapter }.to raise_error(Split::InvalidPersistenceAdapterError)
      end
    end
    context "when the persistence config is a class" do
      let(:custom_adapter_class) { MyCustomAdapterClass = Class.new }
      it "should return that class" do
        expect(Split.configuration).to receive(:persistence).twice.and_return(custom_adapter_class)
        expect(subject.adapter).to eq(MyCustomAdapterClass)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
split-4.0.4 spec/persistence_spec.rb
split-4.0.3 spec/persistence_spec.rb
split-4.0.2 spec/persistence_spec.rb