Skip to content

Application container not to be finalized in test env #39

Open
@stefanrendevski

Description

@stefanrendevski

Components get booted immediately, before test setup is allowed to run. This means that items registered in the container from these boot files cannot be stubbed, before they are injected into other components that require them.

For example, the following setup will not work:

# config/system/boot/event.rb
MyApp::Container.boot(:event) do
  start do
     register('event_bus', MyEventBus.new)
  end
end

# config/system/boot/component.rb
MyApp::Container.boot(:component) do |container|
  use :event
  
  start do
    container['event_bus'].subscribe(MyListener.new, to: [MyEvent])
  end
end

# spec/rails_helper.rb
before do
  # Both :event and :component are already started at this point,
  # so this setup has no effect at all if container memoizes the registered items

  MyApp::Container.start(:event)
  MyApp::Container.stub('event_bus', TestDoubleEventBus.new)
  MyApp::Container.start(:component)
end

This behavior was already present in Dry::System::Rails, where the components had to be booted manually.

Resources

https://discourse.dry-rb.org/t/different-behavior-in-finalizing-container-between-dry-rails-and-dry-rails/1129

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions