diff --git a/spec/prius/registry_spec.rb b/spec/prius/registry_spec.rb index 8685e60..e6ffab0 100644 --- a/spec/prius/registry_spec.rb +++ b/spec/prius/registry_spec.rb @@ -26,6 +26,13 @@ it "doesn't blow up" do expect { registry.load(:name) }.to_not raise_error end + + context "but also a default value" do + it "raises an error" do + expect { registry.load(:name, default: "foo") }. + to raise_error(Prius::InvalidLoadError) + end + end end context "given a name that's not present in the environment" do @@ -38,6 +45,14 @@ it "doesn't blow up" do expect { registry.load(:slogan, required: false) }.to_not raise_error end + + context "when a default value is provided" do + it "doesn't blow up" do + expect do + registry.load(:slogan, required: false, default: "GO GO GO") + end.to_not raise_error + end + end end end @@ -48,6 +63,14 @@ end end + # TODO: Decide if default values should be strings or of the parsed type + context "when specifying a default for a non-string type" do + it "doesn't blow up" do + expect { registry.load(:blah, type: :int, required: false, default: "56") }. + to_not raise_error + end + end + context "when specifying :int as the type" do context "given a integer value" do it "doesn't blow up" do @@ -74,7 +97,7 @@ expect { registry.load(:alive, type: :bool) }.to_not raise_error end - it "stores an boolean" do + it "stores a boolean" do registry.load(:alive, type: :bool) expect(registry.get(:alive)).to be_a(TrueClass) end @@ -133,12 +156,20 @@ end end - context "given a nillable name that has been loaded" do + context "given a nilable name that has been loaded" do before { registry.load(:lightsabre, required: false) } it "returns nil" do expect(registry.get(:lightsabre)).to be_nil end + + context "with a default" do + before { registry.load(:lightsabre, required: false, default: "blue") } + + it "returns the default" do + expect(registry.get(:lightsabre)).to eq("blue") + end + end end end end