Class: Megatest::Stubber
- Inherits:
-
Module
- Object
- Module
- Megatest::Stubber
- Defined in:
- lib/megatest/stubs.rb
Constant Summary collapse
- DEFAULT =
->(*) {}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.for(object) ⇒ Object
9 10 11 |
# File 'lib/megatest/stubs.rb', line 9 def for(object) for_class(class << object; self; end) end |
Instance Method Details
#stub_method(method, proc) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/megatest/stubs.rb', line 22 def stub_method(method, proc) proc ||= DEFAULT if method_defined?(method, false) # Already stubbed that method old_method = instance_method(method) alias_method(method, method) # Silence redefinition warnings define_method(method, &proc) -> do alias_method(method, method) # Silence redefinition warnings define_method(method, old_method) end else define_method(method, &proc) -> { remove_method(method) } end end |