Skip to content

Instantly share code, notes, and snippets.

@eqdw
Created March 6, 2014 18:59
Show Gist options
  • Save eqdw/9396923 to your computer and use it in GitHub Desktop.
Save eqdw/9396923 to your computer and use it in GitHub Desktop.
# As soon as #account returns, cls stops existing because it's a local
# so you call .calls on the returned object, which attemts to return a
# non-existant local variable. In javascript/lisp/etc cls would be retained
# in a closure.
class BrokenMockTwilioClient
def account
act = Object.new
cls = Object.new
def cls.create(opts={})
nil
end
def act.calls
cls
end
act
end
# Instead, I have to create the cls object on the fly in the
# calls method that is defined on the account stub object
class WorkingMockTwilioClient
# this is so hacky
def account
act = Object.new
# WHAT HAVE I DONE
# I hate myself
def act.calls
# OH GOD WHY
cls = Object.new
def cls.create(opts={})
nil
end
cls
end
act
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment