2011-07-24 31 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 
相关问题