Extremely Defensive Coding
summary
RSpec saves and restores real method implementations to make stubbing reliable across weird Ruby code and interpreters. It builds a robust method retrieval (aspect_support_method_handle_for) that grabs Kernel.instance_method(:method), attempts rebinding, falls back to calling the object method and validates the result, a trust but verify strategy. It defends against objects that redefine method send or is_a? and against odd inheritance like SimpleDelegator, and supports 1.8.7 and JRuby (and Windows CI) so stubs actually get undone.
AI-written summary · about
chapters (7)
- 0:00Start
- 8:41User story
- 11:20How do you save a method?
- 15:43Instance method object Method without a target object
- 18:09Rebinding module methods
- 21:53Solution: trust but verify
- 26:32Write defensively, and your users will never know what's inside the box








