Sha256: 8f9afb9c94a8259df151c77eedd039b9f86b6813d228a73b56b41521d573494e

Contents?: true

Size: 740 Bytes

Versions: 7

Compression:

Stored size: 740 Bytes

Contents

describe Dry::Initializer, ".dry_initializer.public_attributes" do
  subject { instance.class.dry_initializer.public_attributes(instance) }

  context "when class has params" do
    before do
      class Test::Foo
        extend Dry::Initializer
        param  :foo, proc(&:to_s), desc: "a weird parameter"
        option :moo, optional: true
        option :bar, default: proc { 1 },     reader: false
        option :baz, optional: true,          reader: :protected
        option :qux, proc(&:to_s), as: :quxx, reader: :private
      end
    end

    let(:instance) { Test::Foo.new(:FOO, bar: :BAR, baz: :BAZ, qux: :QUX) }

    it "collects public options only" do
      expect(subject).to eq({ foo: "FOO", moo: nil })
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-initializer-3.0.2 spec/public_attributes_utility_spec.rb
dry-initializer-3.0.1 spec/public_attributes_utility_spec.rb
dry-initializer-3.0.0 spec/public_attributes_utility_spec.rb
dry-initializer-2.5.0 spec/public_attributes_utility_spec.rb
dry-initializer-2.4.0 spec/public_attributes_utility_spec.rb
dry-initializer-2.3.0 spec/public_attributes_utility_spec.rb
dry-initializer-2.2.0 spec/public_attributes_utility_spec.rb