Sha256: 076c1eae86b141036cc8dae648ab06adc308f02f7c6fbbc1da53df378483a910

Contents?: true

Size: 1.84 KB

Versions: 8

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true
require_relative "../spec_helper"

require_relative "../../lib/ultravisor"

describe Ultravisor do
  describe ".new" do
    context "without arguments" do
      it "does not explode" do
        expect { Ultravisor.new }.to_not raise_error
      end

      it "gives us an Ultravisor instance" do
        expect(Ultravisor.new).to be_a(Ultravisor)
      end
    end

    context "with empty children" do
      it "does not explode" do
        expect { Ultravisor.new children: [] }.to_not raise_error
      end
    end

    context "with children that isn't an array" do
      it "raises an error" do
        [{}, "ohai!", nil, 42].each do |v|
          expect { Ultravisor.new children: v }.to raise_error(ArgumentError)
        end
      end
    end

    context "with valid children" do
      let(:ultravisor) { Ultravisor.new(children: [{ id: :testy, klass: Object, method: :to_s }]) }

      it "registers the child by its ID" do
        expect(ultravisor[:testy]).to be_a(Ultravisor::Child)
      end
    end

    context "with two children with the same ID" do
      it "explodes" do
        expect do
          Ultravisor.new(
            children: [
              { id: :testy, klass: Object, method: :to_s },
              { id: :testy, klass: Class, method: :to_s },
            ]
          )
        end.to raise_error(Ultravisor::DuplicateChildError)
      end
    end

    context "with a valid strategy" do
      it "does not explode" do
        expect { Ultravisor.new strategy: :all_for_one }.to_not raise_error
      end
    end

    [
      { strategy: :bob },
      { strategy: "all_for_one" },
      { strategy: ["games"] },
    ].each do |s|
      context "with invalid strategy #{s.inspect}" do
        it "explodes" do
          expect { Ultravisor.new **s }.to raise_error(ArgumentError)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
service_skeleton-2.2.0 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-2.1.0 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-1.0.5 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-2.0.2 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-2.0.1 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-2.0.0 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-1.0.4 ultravisor/spec/ultravisor/new_spec.rb
service_skeleton-0.0.0.1.ENOTAG ultravisor/spec/ultravisor/new_spec.rb