Sha256: 6048e8dccab8aaec2863b5de1e5dae578ebb6e1f5cfe811e07d17e692c3881b6
Contents?: true
Size: 1.07 KB
Versions: 6
Compression:
Stored size: 1.07 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 "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
6 entries across 6 versions & 1 rubygems