2011-07-24 32 views
1

我的規格:因爲線程被前面的規格改變如何在單個線程中運行單個特殊字符?

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 

其次規格失敗。 如何在不同線程中運行規格或在每個規格之前'取消'線程的鍵或其他要傳遞第二個規格的東西?

回答

1

您可以在規範中創建Thread;不要'忘記join它從線程得到should的結果重新評估:

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 
相關問題