Injecting Dependencies for Fun and Profit
summary
Concrete examples show constructor-based injection replacing globals, with tests using RSpec verifying doubles via instance_double and allow/expect; failure behavior is exercised by having the weather service raise a NoPredictionAvailable error and asserting the fallback speech or mailer output. The talk contrasts this with partial mocking/monkeypatching, explains why explicit dependency lists aid comprehension and testing, and shows Rails-friendly service objects and mailer wiring — the presenter mentions using it across about 40 Rails apps.
AI-written summary · about
chapters (9)
- 0:00Start
- 0:33Dependency Injection's Benefits
- 0:55Intro to Dependency Injection
- 13:51Wait, Why Didn’t We Partially Mock?
- 18:06How Do I Inject Dependencies in Rails?
- 22:02Takeaways
- 22:40Sad Paths are Part of Your UX
- 22:55Explicit Dependencies Help You Know Your Code
- 23:19Dependency Injection is Possible & Useful in Rails
related talks
44mReal-World Functional Ruby
36mOpening up to change
35mReal-world Functional Ruby
39mFunctional Architecture for the Practical Rubyist
42mTaking inspiration from the functional world
39mFunctional Architecture for the Practical Rubyist
30mRuby Techniques by Example
46mBetter code through boring(er) tests
