Hello,
I’m wondering if it is possible to stub a container which is auto-injected? I have the following error: Dry::Container::Error: Nothing registered with the key "my_repo" at /dry-auto_inject-0.4.3/lib/dry/auto_inject/strategies/kwargs.rb:13
when I try to do so.
I guess it’s because the injection is done on class loading, before the test setup which calls the stub method. Here is a simplified version of my code:
module Domain
class Repositories
extend Dry::Container::Mixin
end
ImportRepositories = Dry::AutoInject(Repositories)
class Service
include ImportRepositories['my_repo']
def list
my_repo.all.sort_by(&:name)
end
end
end
describe Service do
before do
Domain::Repositories.enable_stubs!
Domain::Repositories.stub(:my_repo, InMemoryRepository.new)
end
after { Domain::Repositories.unstub(:my_repo) }
it 'test things' do
# ...
end
end
What do you think about it?