Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Created May 18, 2014 02:25
Show Gist options
  • Save jamonholmgren/311fb8d252f2fc1de962 to your computer and use it in GitHub Desktop.
Save jamonholmgren/311fb8d252f2fc1de962 to your computer and use it in GitHub Desktop.
class MyObj
def now(&callback)
return callback.call @my_ivar if @my_ivar
Dispatch::Queue.new("a").async do
sleep 0.1 # simulate an http response
Dispatch::Queue.main.sync do
@my_ivar = { result: "real" }
callback.call @my_ivar
end
end
end
end
describe "Application 'rm_mocking_issue'" do
before do
@my_obj = MyObj.new
# Removing this line allows the spec to pass.
# Adding it causes the spec to hang.
@my_obj.instance_variable_set("@my_ivar", { result: "fake" })
end
it "hangs" do
@my_obj.now do |response|
response.should.be.kind_of(Hash)
resume
end
wait {}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment