Skip to content

Instantly share code, notes, and snippets.

@bkempner
Created September 20, 2011 18:47
Show Gist options
  • Save bkempner/1229943 to your computer and use it in GitHub Desktop.
Save bkempner/1229943 to your computer and use it in GitHub Desktop.
Strange let behavior with threads
class Foo; end
describe Foo do
# expected behavior
context 'when not testing with let' do
it "uses the same Foo object inside threads" do
foo = Foo.new
obj_id = @foo.object_id
Thread.new do
foo.object_id.should eql(obj_id)
end
end
end
# unexpected behavior
context 'when testing with let' do
let(:foo) { Foo.new }
it 'creates a new Foo object inside threads' do
obj_id = foo.object_id
Thread.new do
foo.object_id.should_not eql(obj_id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment