2013-12-10 34 views
1

我有很多食譜,他們嚴格測試ChefSpec。我有超過800個規格,並且在提交代碼之前每次運行它都成爲一個問題,因爲在我的機器上運行它們需要大約20分鐘的時間。這使得每個規格約爲0.(6)s,這並不多,但加起來需要很長的時間。加速Chefspec運行

是否有任何可能並行運行ChefSpec/RSpec測試或以某種方式提高速度?

回答

2

更新2014年1月4日:ChefSpec(> = 3.1.2)中現在實現了以下想法。見更快的規格部分Readme

================================

這是從blogpost一個摘錄用更多的細節涵蓋了這個話題。

RSpec allows to extend modules with your own methods並且這個想法是寫出類似於的方法讓,但是它也會將結果緩存在示例中。在你的廚師項目的地方創建一個* spec_helper.rb *文件,並添加以下行有:從@@緩存

module SpecHelper 
    @@cache = {} 
    def shared(name, &block) 
    location = ancestors.first.metadata[:example_group][:location] 
    define_method(name) do 
     @@cache[location + name.to_s] ||= instance_eval(&block) 
    end 
    end 

    def shared!(name, &block) 
    shared name, &block 
    before { __send__ name } 
    end 
end 

RSpec.configure do |config| 
    config.extend SpecHelper 
end 

值永遠都不會刪除,你可以用這個塊使用相同的名稱,所以我也使用使用位置,如下所示:「./cookbooks/my_cookbook/spec/default_spec.rb:3」。現在改變成let(:chef_run)shared(:chef_run)您的規格:

describe "example::default" do 
    shared(:chef_run) { ChefSpec::ChefRunner.new.converge described_recipe } 
    [...] 
end 

和運行測試時,你現在必須包括spec_helper.rb太:

rspec --include ./relative/path/spec_helper.rb cookbooks/*/spec/*_spec.rb