Hi all, I am new to integrant and try to replace a ref with a mock implementation I want to provide in the test... The mock dep is built in a let like:
diagnostic-report-repo (shrub/stub repository/Repository
{:-one nil})
And what I'd like to do is to set it as "already" initialized depIt's too late to do that after you have initialized your system as references to the actual implementation will not be affected. This is assuming you are using ig/ref in your system map. I would recommend setting up your system map correctly (before calling ig/init). You can use https://github.com/weavejester/integrant#derived-keywords so that Integrant uses the test component when the actual component is not in your system map.
I have somewhat complex system maps and use https://github.com/juxt/aero to generate the variations. You just have to write a reader tag implementation which calls ig/ref and you can describe your system structure in an edn file.
thank you for the hint...I was thinking about maybe
(ig/init-key :com.cohesic.acuity.infra2.reporting-service/impl
{:diagnostic-report-repository diagnostic-report-repo})
Would that be a good idea? it's kind of bypassing resolutionI am leaning towards a yes, it makes for a very simple way of unit testing (if I had to "integration test" I would definitely go for aero
and a proper test.edn
config)
still curious though on how to use derive
for swapping dependencies
You can init one component with init-key if you have no dependencies but I might misunderstand your intent here.
With derive you can use (derive :test/impl :com.cohesic.acuity.infra2.reporting-service/impl) and replace the actual key-value -pair in your system map with :test/impl {config here} and just implement the test version as you would any component.
Another option would be something like
(derive :com.cohesic.acuity.infra2.reporting-service/impl :interface/reporting-service)
(derive :test-reporting-thing/impl :interface/reporting-service)
and just reference :interface/reporting-service in other components. I don't do this but it might be reasonable, especially if the components implement the same interface and it is used by components which depend on it.But these are more for integration tests where you would have a mostly complete system.
ok I see thank you
the problem is the every test will have a different stub so I think I need init-key
there
but thanks a lot this is very helpful - I there is definitely some different in thinking around this compared to component
or mount