spec/figleaf/settings_spec.rb in figleaf-0.2.5 vs spec/figleaf/settings_spec.rb in figleaf-0.2.6
- old
+ new
@@ -1,30 +1,8 @@
require 'spec_helper'
describe Figleaf::Settings do
-
- describe "self.load_file" do
- before do
- @fixture_path = File.expand_path("../../fixtures/service.yml", __FILE__)
- end
-
- it "converts file settings from given env" do
- settings = described_class.load_file(@fixture_path, "test")
- expect(settings.foo).to eq("bar")
- end
-
- it "allows env to be optional" do
- settings = described_class.load_file(@fixture_path)
- expect(settings.test.foo).to eq("bar")
- end
-
- it "returns nil for missing env" do
- settings = described_class.load_file(@fixture_path, "foo")
- expect(settings).to eq(nil)
- end
- end
-
describe "self.load_settings" do
before do
@fixtures_path = File.expand_path("../../fixtures/*.yml", __FILE__)
described_class.load_settings(@fixtures_path, "test")
@@ -72,22 +50,33 @@
expect(described_class.erb.foo).to eq('foo')
expect(described_class.erb.bar).to be_nil
end
it "raise exception when loading an undefined value" do
- YAML.stub(:load_file).and_return({ "test" => {} })
+ YAML.stub(:load_yaml_file).and_return({ "test" => {} })
described_class.load_settings
expect { described_class.service.blah }.to raise_error NoMethodError
end
context "with bad files" do
- let(:overload) { File.expand_path("../../fixtures/errors/*.yml", __FILE__) }
+ context "yaml" do
+ let(:overload) { File.expand_path("../../fixtures/errors/*.yml", __FILE__) }
- it "reports the file that has errors" do
- expect { described_class.load_settings(overload, "test") }.
- to raise_error(described_class::InvalidYAML)
+ it "reports the file that has errors" do
+ expect { described_class.load_settings(overload, "test") }.
+ to raise_error(described_class::InvalidYAML)
+ end
end
+
+ context "rb" do
+ let(:overload) { File.expand_path("../../fixtures/errors/*.rb", __FILE__) }
+
+ it "reports the file that has errors" do
+ expect { described_class.load_settings(overload, "test") }.
+ to raise_error(described_class::InvalidRb)
+ end
+ end
end
context "overloading settings" do
before do
overload = File.expand_path("../../fixtures/extra/*.yml", __FILE__)
@@ -125,19 +114,60 @@
end
end
context "using default as a YAML anchor is OK" do
before do
- default = File.expand_path("../../fixtures/extra/default_anchor.yml", __FILE__)
- described_class.load_settings(default, "test")
+ default_anchor = File.expand_path("../../fixtures/extra/default_anchor.yml", __FILE__)
+ described_class.load_settings(default_anchor, "test")
end
it "overrides values" do
- expect(described_class.default.foo).to eq("overriden")
+ expect(described_class.default_anchor.foo).to eq("overriden")
end
- it "respects values set in default" do
- expect(described_class.default.bar).to eq("baz")
+ it "respects values set in default_anchor" do
+ expect(described_class.default_anchor.bar).to eq("baz")
end
+ end
+ end
+
+ context "load ruby files" do
+ before do
+ fixtures_path = File.expand_path("../../fixtures/extra/*.rb", __FILE__)
+ described_class.load_settings(fixtures_path, "test")
+ end
+
+ it "load indifferently the key names" do
+ expect(described_class.code["foo"]).to eq("bar")
+ expect(described_class.code[:foo]).to eq("bar")
+ end
+
+ it "create foo as a method" do
+ expect(described_class.code.foo).to eq("bar")
+ end
+
+ it "create bool_true? and return true" do
+ expect(described_class.code.bool_true?).to eq(true)
+ end
+
+ it "create bool_false? and return false" do
+ expect(described_class.code.bool_false?).to eq(false)
+ end
+
+ it "work for array as well", :aggregate_failures do
+ expect(described_class.code.array).to eq([1, 2, 3, 4])
+ expect(described_class.code.array_alt).to eq([1, 2, 3, 4])
+ end
+
+ it "and for boolean (true)" do
+ expect(described_class.code.bool_true).to eq(true)
+ end
+
+ it "and for boolean (false)" do
+ expect(described_class.code.bool_false).to eq(false)
+ end
+
+ it "and for ENV values" do
+ expect(described_class.code.from_env).to eq('foo')
end
end
end