Skip to content

Commit

Permalink
Add some specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ameykusurkar committed Jul 12, 2024
1 parent a4603a6 commit 6e050dc
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions spec/prius/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 6e050dc

Please sign in to comment.