spec/unit/a9n_spec.rb in a9n-0.3.4 vs spec/unit/a9n_spec.rb in a9n-0.4.0

- old
+ new

@@ -2,10 +2,11 @@ describe A9n do subject { described_class } after { + subject.instance_variable_set(:@storage, nil) subject.instance_variable_set(:@env, nil) subject.root = nil subject.app = nil } @@ -103,45 +104,10 @@ before { ENV["DWARF"] = "little dwarf" } it { expect(subject.get_env_var("DWARF")).to eq("little dwarf")} it { expect(subject.get_env_var("IS_DWARF")).to be_nil} end - describe ".var_name_for" do - it { expect(subject.var_name_for(:configuration)).to eq(:@configuration) } - it { expect(subject.var_name_for("configuration.yml")).to eq(:@configuration) } - it { expect(subject.var_name_for("custom_dir/extra.yml")).to eq(:@extra) } - end - - describe ".fetch" do - let(:example_config) { A9n::Struct.new({hello: "world"}) } - before { - expect(subject).to receive(:scope).with(subject::DEFAULT_SCOPE).twice.and_return(example_config) - } - it { - expect(subject.fetch(:hello)).to eq("world") - expect(subject.fetch(:wold)).to eq(nil) - } - end - - describe ".scope" do - context "when config has been loaded" do - before { - subject.instance_variable_set(:@custom1, { api_key: '1234asdf'}) - expect(subject).to receive(:load).never - } - it { - expect(subject.scope(:custom1)).to eq({ api_key: '1234asdf'}) - } - end - context "when config has not been loaded yet" do - it { - expect(subject).to receive(:load) - subject.scope(:custom2) - } - end - end - describe ".default_files" do before { subject.root = File.expand_path("../../../test_app", __FILE__) } it { @@ -190,9 +156,29 @@ expect(subject).to receive(:default_files).never expect(subject).to receive(:get_absolute_paths_for).with(given_files).and_call_original } it { expect(subject.load(*given_files)).to eq(files.values) + } + end + end + + describe ".method_missing" do + context "when storage is empty" do + before { expect(subject).to receive(:load).once } + it { + expect(subject.storage).to be_empty + expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariable) + } + end + + context "when storage is not empty" do + before { + subject.storage[:whenever] = 'whenever' + expect(subject).not_to receive(:load) + } + it { + expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariable) } end end end