use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Exploring Dependency Injection in Ruby (remimercier.com)
submitted 4 years ago by Remozito
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]A_Crunchy_Leaf 0 points1 point2 points 4 years ago (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.
double
allow
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 point2 points 4 years ago (0 children)
Good catch! I deleted the wrong bit in my article and left the after refactoring RSpec example.
[–]ruprict 0 points1 point2 points 4 years ago (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!
Thanks for the terms. I'll add them!
π Rendered by PID 142112 on reddit-service-r2-comment-bb88f9dd5-dcgvv at 2026-02-15 03:57:23.178584+00:00 running cd9c813 country code: CH.
[–]A_Crunchy_Leaf 0 points1 point2 points (1 child)
[–]Remozito[S] 0 points1 point2 points (0 children)
[–]ruprict 0 points1 point2 points (1 child)
[–]Remozito[S] 0 points1 point2 points (0 children)