Sha256: fe70e56b2843962616157a7c27caf17da898ebd6f8977fadf1713fff4180b726

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

describe "repetitive definitions" do
  subject { Test::Foo.new }

  context "of params" do
    before do
      class Test::Foo
        extend Dry::Initializer::Mixin

        param :foo, default: proc { 0 }
        param :bar, default: proc { 1 }
        param :foo, default: proc { 2 }
      end
    end

    it "reloads the attribute" do
      expect(subject.foo).to eq 2
    end
  end

  context "of options" do
    before do
      class Test::Foo
        extend Dry::Initializer::Mixin

        option :foo, default: proc { 0 }
        option :bar, default: proc { 1 }
        option :foo, default: proc { 2 }
      end
    end

    it "reloads the attribute" do
      expect(subject.foo).to eq 2
    end
  end

  context "of param and option" do
    before do
      class Test::Foo
        extend Dry::Initializer::Mixin

        param  :foo, default: proc { 0 }
        option :bar, default: proc { 1 }
        option :foo, default: proc { 2 }
      end
    end

    it "reloads the attribute" do
      expect(subject.foo).to eq 2
    end
  end

  context "of optional param and option" do
    before do
      class Test::Foo
        extend Dry::Initializer::Mixin

        param  :foo, optional: true
        option :bar, optional: true
        option :foo, optional: true
      end
    end

    it "allows various assignments" do
      expect(Test::Foo.new(1).foo).to eq 1
      expect(Test::Foo.new(foo: 2).foo).to eq 2
      expect(Test::Foo.new(1, foo: 2).foo).to eq 2
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dry-initializer-1.4.1 spec/repetitive_definitions_spec.rb
dry-initializer-1.4.0 spec/repetitive_definitions_spec.rb
dry-initializer-1.3.0 spec/repetitive_definitions_spec.rb
dry-initializer-1.2.0 spec/repetitive_definitions_spec.rb
dry-initializer-1.1.3 spec/repetitive_definitions_spec.rb
dry-initializer-1.1.2 spec/repetitive_definitions_spec.rb
dry-initializer-1.1.1 spec/repetitive_definitions_spec.rb
dry-initializer-1.1.0 spec/repetitive_definitions_spec.rb
dry-initializer-1.0.0 spec/repetitive_definitions_spec.rb