Sha256: c35737fda587af487dad55fc002a1c9812410b66c5ddbd789cc071c39fd9bede
Contents?: true
Size: 1.43 KB
Versions: 6
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true require "spec_helpers" describe Wayfarer::Config::Struct do let(:struct) do Wayfarer::Config::Struct.new(members) end let(:members) { { foo: options } } let(:options) { {} } let(:env) { {} } subject { struct.new(env) } describe "Reader" do context "without environment values and default" do let(:options) { {} } it "returns nil" do expect(subject.foo).to be(nil) end end context "with default only" do let(:options) { { default: 42 } } it "returns the default" do expect(subject.foo).to be(42) end end context "with environment key specified" do let(:options) { { env_key: "FOO" } } context "with environment value" do let(:env) { { "FOO" => "hello" } } it "returns the value" do expect(subject.foo).to eq("hello") end context "with type specified" do let(:options) { { env_key: "FOO", type: Symbol } } it "parses the value" do expect(subject.foo).to be(:hello) end end end context "without environment value" do it "returns nil" do expect(subject.foo).to be(nil) end end end end describe "Writer" do it "allows overriding environment values and defaults" do expect { subject.foo = 3 }.to change { subject.foo }.from(nil).to(3) end end end
Version data entries
6 entries across 6 versions & 1 rubygems