Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application container not to be finalized in test env #39

Open
stefanrendevski opened this issue Sep 9, 2020 · 0 comments
Open

Application container not to be finalized in test env #39

stefanrendevski opened this issue Sep 9, 2020 · 0 comments
Labels
feature help wanted Extra attention is needed
Milestone

Comments

@stefanrendevski
Copy link

stefanrendevski commented Sep 9, 2020

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

@solnic solnic added this to the 0.4.0 milestone Sep 10, 2020
@solnic solnic added the help wanted Extra attention is needed label Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants