Sha256: 65207b64a5c75ba383cb0a9db50e7dcfbe5c6f122afbda7d0a0a53ffd846f447
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
describe "optional value" do context "when has no default value" do before do class Test::Foo extend Dry::Initializer::Mixin param :foo param :bar, optional: true end end it "quacks like nil" do subject = Test::Foo.new(1) expect(subject.bar).to eq nil end it "keeps info about been UNDEFINED" do subject = Test::Foo.new(1) expect(subject.instance_variable_get(:@bar)) .to eq Dry::Initializer::UNDEFINED end it "can be set explicitly" do subject = Test::Foo.new(1, "qux") expect(subject.bar).to eq "qux" end end context "with undefined: false" do before do class Test::Foo extend Dry::Initializer[undefined: false] param :foo param :bar, optional: true end end it "sets undefined values to nil" do subject = Test::Foo.new(1) expect(subject.instance_variable_get(:@bar)).to be_nil end end context "when has a default value" do before do class Test::Foo extend Dry::Initializer::Mixin param :foo param :bar, optional: true, default: proc { "baz" } end end it "is takes default value" do subject = Test::Foo.new(1) expect(subject.bar).to eq "baz" end it "can be set explicitly" do subject = Test::Foo.new(1, "qux") expect(subject.bar).to eq "qux" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-initializer-1.4.1 | spec/optional_spec.rb |
dry-initializer-1.4.0 | spec/optional_spec.rb |
dry-initializer-1.3.0 | spec/optional_spec.rb |