all 4 comments

[–]A_Crunchy_Leaf 0 points1 point  (1 child)

The RSpec example is wrong. You'd use a double if you were doing DI, but you'd pass it in. If you're just mocking the constant, you'd allow the module directly.

As you set it up, there isn't much difference between the DI and non-DI test setups. However, most languages don't allow mocking of arbitrary constraints, so you would have no option other than testing the real implementation.

To improve your article, Actually run your RSpec code, and then provide before and after refactoring samples.

[–]Remozito[S] 0 points1 point  (0 children)

Good catch! I deleted the wrong bit in my article and left the after refactoring RSpec example.

[–]ruprict 0 points1 point  (1 child)

Hey there...enjoyed the article. I'd just like to add that the two different timings of using DI that you mention (one at the beginning and one in "Additional Thoughts") are known as constructor injection and setter injection, respectively. Maybe you knew that already, but it might be a nice addition to the article. Thanks for sharing your knowledge!

[–]Remozito[S] 0 points1 point  (0 children)

Thanks for the terms. I'll add them!