Sha256: 7f114c2ef1eb8f90977b30ed023ca8fc09cd986038c474a357311efe2b4a80ee

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

describe "default values" do
  before do
    class Test::Foo
      extend Dry::Initializer::Mixin

      param  :foo, default: proc { :FOO }
      param  :bar, default: proc { :BAR }
      option :baz, default: proc { :BAZ }
      option :qux, default: proc { foo }
      option :mox, default: proc { default_mox }

      private

      def default_mox
        :MOX
      end
    end
  end

  it "instantiate arguments" do
    subject = Test::Foo.new(1, 2, baz: 3, qux: 4)

    expect(subject.foo).to eql 1
    expect(subject.bar).to eql 2
    expect(subject.baz).to eql 3
    expect(subject.qux).to eql 4
  end

  it "applies default values" do
    subject = Test::Foo.new

    expect(subject.foo).to eql :FOO
    expect(subject.bar).to eql :BAR
    expect(subject.baz).to eql :BAZ
    expect(subject.qux).to eql :FOO
  end

  it "applies default values partially" do
    subject = Test::Foo.new 1, baz: 3

    expect(subject.foo).to eql 1
    expect(subject.bar).to eql :BAR
    expect(subject.baz).to eql 3
    expect(subject.qux).to eql 1
  end

  it "applies default values from private methods" do
    subject = Test::Foo.new
    expect(subject.mox).to eql :MOX
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dry-initializer-0.10.0 spec/default_values_spec.rb
dry-initializer-0.9.3 spec/default_values_spec.rb
dry-initializer-0.9.2 spec/default_values_spec.rb
dry-initializer-0.9.1 spec/default_values_spec.rb
dry-initializer-0.9.0 spec/default_values_spec.rb
dry-initializer-0.8.1 spec/default_values_spec.rb
dry-initializer-0.8.0 spec/default_values_spec.rb
dry-initializer-0.7.0 spec/dry/default_values_spec.rb
dry-initializer-0.6.0 spec/dry/default_values_spec.rb
dry-initializer-0.5.0 spec/dry/default_values_spec.rb
dry-initializer-0.4.0 spec/dry/default_values_spec.rb
dry-initializer-0.3.3 spec/dry/default_values_spec.rb
dry-initializer-0.3.2 spec/dry/default_values_spec.rb
dry-initializer-0.3.1 spec/dry/default_values_spec.rb
dry-initializer-0.3.0 spec/dry/default_values_spec.rb
dry-initializer-0.2.1 spec/dry/default_values_spec.rb