Reputation: 10018
My specs:
it "has empty thread" do
Thread.current[:foo].should be_nil
Thread.current[:foo] = "bar"
end
it "has empty thread" do
Thread.current[:foo].should be_nil
end
Second spec fails because thread was changed by previous spec. How can I run specs in different threads or 'nullify' thread's keys before each spec or something else to pass second spec?
Upvotes: 1
Views: 788
Reputation: 35816
You can create the Thread
in the spec ; don't' forget to join
it to get the results of the should
's from the thread re-evaluated:
it "has empty thread" do
Thread.new {
Thread.current[:foo].should be_nil
Thread.current[:foo] = "bar"
}.join
end
it "has empty thread" do
Thread.new {
Thread.current[:foo].should be_nil
}.join
end
Upvotes: 1