Sha256: 511874bf37be851bc029e0775dbc22ad85d3b3bba471f674fd1c0394fd17ee03

Contents?: true

Size: 990 Bytes

Versions: 18

Compression:

Stored size: 990 Bytes

Contents

describe "plugin registry" do
  before do
    # Define a plugin
    module Test::Stringifier
      class Plugin < Dry::Initializer::Plugins::Base
        def call
          "@#{name} = @#{name}.to_s"
        end
      end

      def self.extended(klass)
        klass.register_initializer_plugin(Plugin)
      end
    end

    # Define superclass
    class Test::Foo
      extend Dry::Initializer::Mixin

      param :foo
    end

    # Apply the plugin to the subclass
    class Test::Bar < Test::Foo
      extend Test::Stringifier

      param :bar
    end
  end

  let(:instance_of_superclass) { Test::Foo.new :FOO }
  let(:instance_of_subclass)   { Test::Bar.new :FOO, :BAR }

  it "does not pollute superclass" do
    expect(instance_of_superclass.foo).to eql :FOO
  end

  it "preserves declarations made in superclass" do
    expect(instance_of_subclass.foo).to eql :FOO
  end

  it "applies plugin to new declarations" do
    expect(instance_of_subclass.bar).to eql "BAR"
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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