Created
September 20, 2011 18:47
-
-
Save bkempner/1229943 to your computer and use it in GitHub Desktop.
Strange let behavior with threads
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
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