Sha256: 4f8b3e0f84b86d08d3d8c0882b7e60115bae97974cd856850ee150046dec474b

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

describe "definition" do
  shared_examples :initializer do |in_context|
    subject { Test::Foo.new(1, bar: 2) }

    it "sets variables when defined via `#{in_context}`" do
      expect(subject.instance_variable_get(:@foo)).to eql 1
      expect(subject.instance_variable_get(:@bar)).to eql 2
    end
  end

  it_behaves_like :initializer, "extend Dry::Initializer" do
    before do
      class Test::Foo
        extend Dry::Initializer
        param  :foo
        option :bar
      end
    end
  end

  it_behaves_like :initializer, "extend Dry::Initializer" do
    before do
      class Test::Foo
        extend Dry::Initializer
        param  :foo
        option :bar
      end
    end
  end

  it_behaves_like :initializer, "extend Dry::Initializer[undefined: false]" do
    before do
      class Test::Foo
        extend Dry::Initializer[undefined: false]
        param  :foo
        option :bar
      end
    end
  end

  it_behaves_like :initializer, "include Dry::Initializer with block" do
    before do
      class Test::Foo
        include(
          Dry::Initializer.define do
            param  :foo
            option :bar
          end
        )
      end
    end
  end

  it_behaves_like :initializer, "include Dry::Initializer with lambda" do
    before do
      class Test::Foo
        include Dry::Initializer.define -> do
          param  :foo
          option :bar
        end
      end
    end
  end

  it_behaves_like :initializer, "include Dry::Initializer[undefined: false]" do
    before do
      class Test::Foo
        include(
          Dry::Initializer[undefined: false].define do
            param  :foo
            option :bar
          end
        )
      end
    end
  end

  # @deprecated
  it_behaves_like :initializer, "include Dry::Initializer::Mixin" do
    before do
      class Test::Foo
        include(
          Dry::Initializer::Mixin.define do
            param  :foo
            option :bar
          end
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-initializer-2.0.0 spec/definition_spec.rb