Sha256: bdea119cde52d5101c5802eba1e509d6315f430b413a8dd4d2d115289b1cae2d

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

RSpec.describe Dry::Component::Injector do
  before do
    class Test::Container < Dry::Component::Container
      configure do |config|
        config.root = SPEC_ROOT.join("fixtures/test").realpath
      end

      load_paths! "lib"
    end

    Test::Inject = Test::Container.injector
  end

  it "supports args injection by default" do
    obj = Class.new do
      include Test::Inject["test.dep"]
    end.new

    expect(obj.dep).to be_a Test::Dep
  end

  it "supports args injection with explicit method" do
    obj = Class.new do
      include Test::Inject.args["test.dep"]
    end.new

    expect(obj.dep).to be_a Test::Dep
  end

  it "supports hash injection" do
    obj = Class.new do
      include Test::Inject.hash["test.dep"]
    end.new

    expect(obj.dep).to be_a Test::Dep
  end

  it "support kwargs injection" do
    obj = Class.new do
      include Test::Inject.kwargs["test.dep"]
    end.new

    expect(obj.dep).to be_a Test::Dep
  end

  it "allows injection strategies to be swapped" do
    obj = Class.new do
      include Test::Inject.kwargs.hash["test.dep"]
    end.new

    expect(obj.dep).to be_a Test::Dep
  end

  it "supports aliases" do
    obj = Class.new do
      include Test::Inject[foo: "test.dep"]
    end.new

    expect(obj.foo).to be_a Test::Dep
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-component-0.4.3 spec/unit/injector_spec.rb
dry-component-0.4.2 spec/unit/injector_spec.rb