Sha256: a2cb7e2bc39bf4993fe188c4e6540280dc400a0a4401dddc972d48aa58650d56

Contents?: true

Size: 930 Bytes

Versions: 13

Compression:

Stored size: 930 Bytes

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 "is left UNDEFINED by default" do
      subject = Test::Foo.new(1)

      expect(subject.foo).to eq 1
      expect(subject.bar).to eq Dry::Initializer::UNDEFINED
    end

    it "can be set explicitly" do
      subject = Test::Foo.new(1, "qux")

      expect(subject.foo).to eq 1
      expect(subject.bar).to eq "qux"
    end
  end

  context "when has 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.foo).to eq 1
      expect(subject.bar).to eq "baz"
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dry-initializer-0.11.0 spec/optional_spec.rb
dry-initializer-0.10.2 spec/optional_spec.rb
dry-initializer-0.10.1 spec/optional_spec.rb
dry-initializer-0.10.0 spec/optional_spec.rb
dry-initializer-0.9.3 spec/optional_spec.rb
dry-initializer-0.9.2 spec/optional_spec.rb
dry-initializer-0.9.1 spec/optional_spec.rb
dry-initializer-0.9.0 spec/optional_spec.rb
dry-initializer-0.8.1 spec/optional_spec.rb
dry-initializer-0.8.0 spec/optional_spec.rb
dry-initializer-0.7.0 spec/dry/optional_spec.rb
dry-initializer-0.6.0 spec/dry/optional_spec.rb
dry-initializer-0.5.0 spec/dry/optional_spec.rb