Skip to content

Instantly share code, notes, and snippets.

@amiel
Last active December 18, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiel/5776777 to your computer and use it in GitHub Desktop.
Save amiel/5776777 to your computer and use it in GitHub Desktop.
ARC vs GC gotcha example
describe WebService
def test_request(t, path, params, &block)
# Local variable t persists in both callbacks
# However, `block` doesn't make it
@result = nil
WebService.post(path, params) do |result|
@result = result
t.resume
end
t.wait_max 0.2 do
# `block` is `nil`
block.call(@result)
end
end
it 'test example' do
test_request(self, 'path', 'pin' => '123456') do |result
result.should.be.success
end
end
end
describe WebService
# This example works as expected. See notes
def test_request(t, path, params, block)
# Local variables t, and block persist in both callbacks
# @request persists in both callbacks
@result = nil
WebService.post(path, params) do |result|
@result = result
t.resume
end
t.wait_max 0.2 do
block.call(@result)
end
end
it 'test example' do
test_request(self, 'path', 'pin' => '123456', ->(result) {
result.should.be.success
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment