Skip to content

A platform for community discussion. Free, open, simple.

1.4 KB
Raw Blame
# encoding: utf-8
# frozen_string_literal: true

require "archetype"

RSpec.describe Archetype do
  describe "default archetype" do
    it "has an Archetype by default" do
      expect(Archetype.list).to be_present
    end

    it "has an id of default" do
      expect(Archetype.list.first.id).to eq(Archetype.default)
    end

    context "with duplicate" do
      before do
        @old_size = Archetype.list.size
        Archetype.register(Archetype.default)
      end

      it "does not add the same archetype twice" do
        expect(Archetype.list.size).to eq(@old_size)
      end
    end
  end

  describe ".exists?" do
    it "returns true for registered archetypes" do
      expect(Archetype.exists?(Archetype.default)).to eq(true)
      expect(Archetype.exists?(Archetype.private_message)).to eq(true)
      expect(Archetype.exists?(Archetype.banner)).to eq(true)
    end

    it "returns false for unregistered archetypes" do
      expect(Archetype.exists?("unknown")).to eq(false)
      expect(Archetype.exists?(nil)).to eq(false)
    end
  end

  describe "register an archetype" do
    it "has one more element" do
      @list = Archetype.list.dup
      Archetype.register("glados")
      expect(Archetype.list.size).to eq(@list.size + 1)
      expect(Archetype.list.find { |a| a.id == "glados" }).to be_present
      Archetype.deregister("glados")
    end
  end
end