-
-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Milestone
Description
Describe the bug
When a dependency is imported via key-based argument, stubbing doesn't affect it's resolving.
I've made a sample app that reproduces the issue: https://github.com/mgpnd/import_example
Here's the most important snippets from the app:
# Operation that will be imported and stubbed
module Example
class Show
def call
self.class.name
end
end
endclass ExampleController < ApplicationController
include ImportExample::Import[
show_example: "example.show"
]
def index
@auto_imported = show_example.()
@manually_resolved = ImportExample::Container["example.show"].()
end
end/spec/controllers/example_controler_spec.rb:
RSpec.describe ExampleController, type: :controller do
describe '#index' do
subject { get :index, params: { format: 'text/hmtl' } }
...
before do
# Stubbing is enabled somewhere else so this part works properly
ImportExample::Container.stub('example.show', -> { 'operation stub' })
end
# Fails, @auto_imported == "Example::Show"
it 'calls auto imported stub' do
subject
expect(assigns(:auto_imported)).to eq('operation stub')
end
# Passes, @manually_resolved == "operation stub"
it 'calls manually resolved stub' do
subject
expect(assigns(:manually_resolved)).to eq('operation stub')
end
end
endTo Reproduce
- Define a dependency via auto_inject
Importwith key-based argument - Stub the dependency in any test
Expected behavior
The dependency resolved to provided stub.
Your environment
- Affects my production application: NO
- Ruby version: 2.7
I've tried to reproduce the issue with plain dry-auto_inject and with basic dry-system, but it doesn't appear there, in both gems importing works properly so I'm reporting it here.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed