2011-07-07 61 views
4

我使用RSpec進行Rails 3測試並嘗試使用Spork。Spork沒有加速我的測試

我跟着幾個教程,Spork似乎沒有錯誤地運行,但我的測試仍然花費相同的時間用Spork打開和關閉運行(43秒)。

我怎樣才能弄清楚發生了什麼事?

的Gemfile

gem 'spork', '>=0.9.0.rc9' 

spec_helper.rb

require 'rubygems' 
require 'spork' 
require 'factory_girl' 
require 'cover_me' 

Spork.prefork do 
    # Loading more in this block will cause your tests to run faster. However, 
    # if you change any configuration or code from libraries loaded here, you'll 
    # need to restart spork for it take effect. 
    # This file is copied to spec/ when you run 'rails generate rspec:install' 
    ENV["RAILS_ENV"] ||= 'test' 
    require File.expand_path("../../config/environment", __FILE__) 
    require 'rspec/rails' 

    # Force find of factory girl definitions. Tests started failing without this, and the factories could not be found 
    Factory.find_definitions 

    # Requires supporting ruby files with custom matchers and macros, etc, 
    # in spec/support/ and its subdirectories. 
    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

    RSpec.configure do |config| 
    # == Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 
    config.mock_with :rspec 

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    # If you're not using ActiveRecord, or you'd prefer not to run each of your 
    # examples within a transaction, remove the following line or assign false 
    # instead of true. 
    config.use_transactional_fixtures = true 

    # Needed for Spork 
    ActiveSupport::Dependencies.clear 
    end 
end 

Spork.each_run do 
    # This code will be run each time you run your specs. 

end 

當我運行→叉勺啓動服務器,一切都看起來不錯:

→叉勺 使用RSpec的 預加載Rails環境 加載Spork.prefork塊... Spork準備就緒並正在收聽8989!

我也已經在.rspec文件

+0

你如何測量執行時間?從調用命令執行測試還是從測試執行開始? Spork緩存加速旋轉時間的軌道環境,但我不認爲它會加快實際執行時間。 – JoshReedSchramm

+0

啊,這很有道理!謝謝 – 99miles

+0

酷我會重新發布評論作爲解決方案,以便人們可以找到它。 – JoshReedSchramm

回答

4

這取決於你如何衡量執行時間--drb。如果你包括花費的時間應該更快,但實際的測試運行時間不會改變。

Spork緩存rails加速時間的軌道環境,但不會加快實際執行時間。