spec/unit/loader_spec.rb in a9n-0.4.5 vs spec/unit/loader_spec.rb in a9n-0.4.6

- old
+ new

@@ -1,14 +1,14 @@ -require "spec_helper" - -describe A9n::Loader do +RSpec.describe A9n::Loader do + let(:scope) { A9n::Scope.new("configuration") } let(:env) { "test" } let(:root) { File.expand_path("../../../test_app", __FILE__) } let(:file_path) { File.join(root, "config/configuration.yml") } - subject { described_class.new(file_path, env) } + subject { described_class.new(file_path, scope, env) } describe "#intialize" do + it { expect(subject.scope).to eq(scope) } it { expect(subject.env).to eq(env) } it { expect(subject.local_file).to eq(file_path) } it { expect(subject.example_file).to eq("#{file_path}.example") } end @@ -24,13 +24,12 @@ let(:env) { "tropical" } let(:config) { subject.get } context "when no configuration file exists" do before do - expect(described_class).to receive(:load_yml).with(subject.example_file, env).and_return(nil) - expect(described_class).to receive(:load_yml).with(subject.local_file, env).and_return(nil) - expect(subject).to receive(:verify!).never + expect(described_class).to receive(:load_yml).with(subject.example_file, scope, env).and_return(nil) + expect(described_class).to receive(:load_yml).with(subject.local_file, scope, env).and_return(nil) end it "raises expection" do expect { subject.load @@ -38,13 +37,12 @@ end end context "when only example configuration file exists" do before do - expect(described_class).to receive(:load_yml).with(subject.example_file, env).and_return(example_config) - expect(described_class).to receive(:load_yml).with(subject.local_file, env).and_return(nil) - expect(described_class).to receive(:verify!).never + expect(described_class).to receive(:load_yml).with(subject.example_file, scope, env).and_return(example_config) + expect(described_class).to receive(:load_yml).with(subject.local_file, scope, env).and_return(nil) subject.load end it { expect(config.app_url).to eq("http://127.0.0.1:3000") } it { expect(config.api_key).to eq("example1234") } @@ -54,13 +52,12 @@ end end context "when only local configuration file exists" do before do - expect(described_class).to receive(:load_yml).with(subject.example_file, env).and_return(nil) - expect(described_class).to receive(:load_yml).with(subject.local_file, env).and_return(local_config) - expect(described_class).to receive(:verify!).never + expect(described_class).to receive(:load_yml).with(subject.example_file, scope, env).and_return(nil) + expect(described_class).to receive(:load_yml).with(subject.local_file, scope, env).and_return(local_config) subject.load end it { expect(config.app_host).to eq("127.0.0.1:3000") } it { expect(config.api_key).to eq("local1234") } @@ -71,12 +68,12 @@ end context "when both local and base configuration file exists without defaults" do context "with same data" do before do - expect(described_class).to receive(:load_yml).with(subject.example_file, env).and_return(example_config) - expect(described_class).to receive(:load_yml).with(subject.local_file, env).and_return(example_config) + expect(described_class).to receive(:load_yml).with(subject.example_file, scope, env).and_return(example_config) + expect(described_class).to receive(:load_yml).with(subject.local_file, scope, env).and_return(example_config) subject.load end it { expect(config.app_url).to eq("http://127.0.0.1:3000") } it { expect(config.api_key).to eq("example1234") } @@ -86,12 +83,12 @@ end end context "with different data" do before do - expect(described_class).to receive(:load_yml).with(subject.example_file, env).and_return(example_config) - expect(described_class).to receive(:load_yml).with(subject.local_file, env).and_return(local_config) + expect(described_class).to receive(:load_yml).with(subject.example_file, scope, env).and_return(example_config) + expect(described_class).to receive(:load_yml).with(subject.local_file, scope, env).and_return(local_config) end let(:missing_variables_names) { example_config.keys - local_config.keys } it "raises expection with missing variables names" do @@ -103,10 +100,10 @@ end end describe ".load_yml" do let(:env) { "test" } - subject { described_class.load_yml(file_path, env) } + subject { described_class.load_yml(file_path, scope, env) } context "when file not exists" do let(:file_path) { "file_not_existing_in_the_universe.yml" } it{ expect(subject).to be_nil }