Created
March 6, 2014 18:59
-
-
Save eqdw/9396923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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