Finally thought of a name for the cool Mocktail API that overrides `YourClass​​​​․new` exactly once so that the test can instantiate its own dependencies instead of having to pass them in:

```
thing = Mocktail.of_next(Thing)
subject = ThingHaver․new
```

And receive the mock in its initializer:

```ruby
class ThingHaver
def initialize
@thing = Thing․new
end
end
```

It's not Dependency Injection, it's :sparkles: ✨ Dependency Inception ✨

4
Share
Share on Mastodon
Share on Twitter
Share on Facebook
Share on Linkedin
José Albornoz

@searls hey that’s pretty neat!

0
1y
Steven Harman

@searls this looks like one of those :neat: and easy things, that ends up being complex (or pehaps papering over complexity)? As are all sharp tools, I guess? 🤷

1
1y
0
1y
Orion Edwards

@searls @thing I love ruby, but I don’t love the part that lets you do that!

0
1y
Replies