Sha256: a56f8575826d33c4d1ff11050955e7046ebe8d9c6a47698345546852281b421f

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

RSpec.describe "Container auto-injection (aka \"Deps\") mixin", :app_integration do
  # rubocop:disable Metrics/MethodLength
  def with_app
    with_tmp_directory(Dir.mktmpdir) do
      write "config/app.rb", <<~RUBY
        require "hanami"

        module TestApp
          class App < Hanami::App
          end
        end
      RUBY

      write "app/some_service.rb", <<~'RUBY'
        module TestApp
          class SomeService
          end
        end
      RUBY

      write "app/some_operation.rb", <<~'RUBY'
        module TestApp
          class SomeOperation
            include Deps["some_service"]
          end
        end
      RUBY

      yield
    end
  end
  # rubocop:enable Metrics/MethodLength

  specify "Dependencies are auto-injected in a booted app" do
    with_app do
      require "hanami/boot"

      op = TestApp::App["some_operation"]
      expect(op.some_service).to be_a TestApp::SomeService
    end
  end

  specify "Dependencies are lazily resolved and auto-injected in an unbooted app" do
    with_app do
      require "hanami/prepare"

      op = TestApp::App["some_operation"]
      expect(op.some_service).to be_a TestApp::SomeService
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hanami-2.2.1 spec/integration/container/auto_injection_spec.rb
hanami-2.2.0 spec/integration/container/auto_injection_spec.rb
hanami-2.2.0.rc1 spec/integration/container/auto_injection_spec.rb
hanami-2.2.0.beta2 spec/integration/container/auto_injection_spec.rb
hanami-2.2.0.beta1 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0.rc3 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0.rc2 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0.rc1 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0.beta2.1 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0.beta2 spec/integration/container/auto_injection_spec.rb
hanami-2.1.0.beta1 spec/integration/container/auto_injection_spec.rb
hanami-2.0.3 spec/integration/container/auto_injection_spec.rb
hanami-2.0.2 spec/integration/container/auto_injection_spec.rb
hanami-2.0.1 spec/integration/container/auto_injection_spec.rb
hanami-2.0.0 spec/integration/container/auto_injection_spec.rb
hanami-2.0.0.rc1 spec/integration/container/auto_injection_spec.rb
hanami-2.0.0.beta4 spec/integration/container/auto_injection_spec.rb
hanami-2.0.0.beta3 spec/integration/container/auto_injection_spec.rb
hanami-2.0.0.beta2 spec/new_integration/container/auto_injection_spec.rb