dry-rb / dry-container

A simple, configurable object container implemented in Ruby
https://dry-rb.org/gems/dry-container
MIT License
335 stars 41 forks source link

Stubbing non-existant container values #48

Closed tylerhunt closed 5 years ago

tylerhunt commented 6 years ago

I ran into an problem writing a test with a stubbed container value where the container in question was empty when the test is run in isolation. This caused a hard-to-find issue where some code in dry-transaction was calling #key? on the container, and it was returning false even though a stubbed value had been registered.

Is this something that should be supported, or is the current code right to assume that only existing registered values can be stubbed?

If we allow non-registered values to be stubbed, I think we'll either need a different approach to stubbing or the stubbing API will need to be fleshed out to better support the full API of Dry::Container::Mixin.

flash-gordon commented 5 years ago

I'm sure that's a poor experience, and it should be fixed by raising an error. The fix will be included in the upcoming release.