Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Simple Mock: Override_method

DZone's Guide to

Simple Mock: Override_method

·
Free Resource
Note: ALL code samples in this post were hijacked from: http://www.karmiccoding.com/articles/2006/03/11/under-the-hood-with-ruby-partial-mock-objects-for-unit-testing

# Overrides the method +method_name+ in +obj+ with the passed block
def override_method(obj, method_name, █)
  # Get the singleton class/eigenclass for 'obj'
  klass = class <
  
   
Outputs:
(0) I'm NOT okay!
(1) I'm okay!
(2) I'm okay!
(3) I'm okay!
(4) I'm okay!

  
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}