2012-08-28 40 views
30

我在想,是否before(如下所示)與RSpec中的before :all相同。有時候既沒有指定:each也沒有指定:all,並且它使我對before的實際操作感到困惑。:all?

require 'spec_helper' 

describe "this is a description" do 
    before do # vs. before :all or before :each 
    # do something... 
    end 
end 

如果任何人能解釋差異,如果有的話,將不勝感激。謝謝!

回答

47

所以答案是before號相當於before :each,不before :all

Test example