# Example Changes of dependencies

**URL:** <https://discourse.dry-rb.org/t/example-changes-of-dependencies/50>\
**Category:** dry-web\
**Created:** [July 12, 2016, 1:08pm UTC](https://discourse.dry-rb.org/t/example-changes-of-dependencies/50 "2016-07-12T13:08:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CoolElvis](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/coolelvis/32/28_2.png) [@CoolElvis](https://discourse.dry-rb.org/u/CoolElvis)\
**Post date:** [July 12, 2016, 1:08pm UTC](https://discourse.dry-rb.org/t/example-changes-of-dependencies/50/1 "2016-07-12T13:08:24Z")

</div>

I have looked at the berg example and did not see any changes of dependencies.  
I want to stub some repositories for tests.  
Can you provide relevant example for this case?

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [July 12, 2016, 7:45pm UTC](https://discourse.dry-rb.org/t/example-changes-of-dependencies/50/2 "2016-07-12T19:45:17Z")

</div>

You can simply pass in mocks into constructors, nothing special is needed, so ie:

```ruby
require 'my_app/import'

class DoSomething
  include MyApp::Import[:repo]

  def call
    data = repo.some_method
    # do something
  end
end

RSpec.describe DoSomething do
  subject(:do_something) { DoSomething.new(repo) }

  let(:repo) { double(:fake_repo) }

  it 'works' do
    expect(repo).to receive(:listing).and_return(...)
    do_something.call
    # expect something
  end
end

```

For high-level integration tests you can use container’s `stub` API ie:

```ruby
require "dry/container/stub"

MyApp::Container.enable_stubs!

MyApp::Container.stub(:repo, some_repo_stub)

# do something

MyApp::Container.unstub(:repo)

```

You can set up your tests/specs to stub things automatically for particular tests. At the moment dry-container doesn’t provide any test-lib-specific integrations, but I think we could very easily add that as it’s gonna be common so some conveniences here would be nice.

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [July 13, 2016, 12:18am UTC](https://discourse.dry-rb.org/t/example-changes-of-dependencies/50/3 "2016-07-13T00:18:36Z")

</div>

@solnic covered pretty much everything, but one thing I wanted to mention is that with the newer versions of dry-auto\_inject and dry-component, the “kwargs” injection strategy is now the default, so for a class like this:

```ruby
class DoSomething
  include MyApp::Import[:repo]

  def call
    data = repo.some_method
    # do something
  end
end

```

You’d pass your manual dependency with a keyword:

```ruby
DoSomething.new(repo: my_repo)

```

---

<div class="post-metadata">

**Author:** ![krisleech](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/krisleech/32/19_2.png) [@krisleech](https://discourse.dry-rb.org/u/krisleech)\
**Post date:** [July 13, 2016, 8:14am UTC](https://discourse.dry-rb.org/t/example-changes-of-dependencies/50/4 "2016-07-13T08:14:06Z")

</div>

Stubbing container keys was the one thing I was missing when I looked at Rodakase a while back. Great stuff!

---

<div class="post-metadata">

**Author:** ![CoolElvis](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/coolelvis/32/28_2.png) [@CoolElvis](https://discourse.dry-rb.org/u/CoolElvis)\
**Post date:** [July 13, 2016, 8:37am UTC](https://discourse.dry-rb.org/t/example-changes-of-dependencies/50/5 "2016-07-13T08:37:32Z")

</div>

Thank for answers!  
I think it deserves to be reflected in documentation.  
Especially, a fact that ‘AutoInject’ does injection through constructor.
