Extremely Defensive Coding
summary
Claim: RSpec restores an object's original method after a test so tests don't leave objects broken. The code shown is a defensive wrapper, RSpec::Support.method_handle_for, that grabs method objects even when users override Kernel#method or when interpreters differ. The implementation evolves through checking Kernel, using instance_method, rebinding tricks and fallbacks, and ends up working across many runtimes including MRI 1.8.7, JRuby and REE, so the feature actually operates in real legacy and hybrid deployments.
AI-written summary · about
chapters (9)
- 0:00Start
- 0:11EXTREMELY DEFENSIVE CODING
- 6:59Internals?
- 19:15Instance method object Method without a target object
- 20:08Grab the Kernel implementation of #method
- 22:44Rebinding module methods
- 23:21RSpec does not support Rubinius
- 30:31Interface?
- 31:59Minitest Mock is 169 lines of code
related talks
28mExtremely Defensive Coding
32m'method_missing' Should be Missing
25mIn Defense of Ruby Metaprogramming
29mControl methods like a pro: A guide to Ruby's awesomeness, a.k.a. metaprogramming
22mRSpec: The Bad Parts
36mMetaprogramming? Not good enough!
29mThe Case of the Missing Method: A Ruby Mystery Story
33mReading RSpec — a journey of meta programming
