require "spec_helper" module Hexx describe Dependencies do # Mocks gem core module to test dependencies from before { module Test; extend Dependencies; end } after { Hexx.send :remove_const, :Test } let(:described_module) { Test } describe ".configure" do it "is defined" do expect(described_module).to respond_to :configure end it "yields block with self" do described_module.configure do |config| expect(config).to eq described_module end end end describe ".depends_on" do it "is defined" do expect(described_module).to respond_to :depends_on end it "allows symbolic attributes" do expect { described_module.depends_on :item }.not_to raise_error end it "allows string attributes" do expect { described_module.depends_on "item" }.not_to raise_error end it "fails when wrong object given" do expect { described_module.depends_on 1 }.to raise_error TypeError end it "fails when blank object given" do expect { described_module.depends_on "" }.to raise_error ArgumentError end it "adds dependencies getters" do described_module.depends_on :item, "user" expect(described_module).to respond_to :item expect(described_module).to respond_to :user end it "adds dependencies setters" do described_module.depends_on :item, "user" expect(described_module).to respond_to :item= expect(described_module).to respond_to :user= end context ":item" do before { described_module.depends_on :item } it "allows setting string and constantizes it" do described_module.item = "String" expect(described_module.item).to eq String end it "allows setting symbol and constantizes it" do described_module.item = :String expect(described_module.item).to eq String end it "allows setting constant" do described_module.item = String expect(described_module.item).to eq String end it "fails if wrong value type given" do expect { described_module.item = 1 }.to raise_error TypeError end it "fails if blank string given" do expect { described_module.item = "" }.to raise_error ArgumentError end end end end end