Extremely Defensive Coding
summary
Explains how RSpec makes stubbing reliable by evolving method-handle retrieval from naive object.method calls to a layered approach: saving Kernel.instance_method(:method), attempting Kernel instance_method fallback, feature-detecting rebinding support per interpreter (MRI, JRuby), falling back to invoking and type-checking the user method, and a trust but verify policy for delegation edge cases like SimpleDelegator. The final implementation is large and messy but repeatedly proven to restore original methods and work across multiple Ruby VMs.
AI-written summary · about
chapters (17)
- 0:00Introduction and speaker background
- 2:11Story about overriding methods
- 4:59What makes a gem good
- 7:58RSpec mocking user story
- 10:50Ruby method objects explained
- 13:18Evolution of RSpec method handle
- 17:21Ruby users redefine methods
- 18:04Ruby interpreter differences
- 20:13RSpec multi-interpreter support
- 22:42Module method rebinding issues
- 23:24User-defined method delegation
- 24:47Final RSpec method handle implementation
- 25:08Why RSpec goes to extreme lengths
- 26:56Defensive coding in gems
- 28:22Gems as barriers of complexity
- 29:23Power and responsibility in Ruby
- 30:07Q&A session
related talks
36mUsing Ruby In Security Critical Applications
36mSandboxing Ruby: The Good, the Bad, and the Fugly
27mSquashing Security Bugs with Rubocop
35mMessage in a Bottle
41mSandboxing Ruby Code - Lessons from the battlefield
31mBypassing Anti-Debugging: A Hybrid Real-Simulated Approach to Rootkit Analysis
32mSAST and Sensibility: A Rubyist’s Guide to Static...
34mLow-level RASP: Protecting Applications Implemented in High-level Programming Languages
