1
即使有後衛& spork,我的rspec測試似乎也運行得非常緩慢。Rspec極其緩慢
Finished in 5.36 seconds
13 examples, 2 failures
據我所知,有幾件事情我可以做優化我的測試&減少與數據庫的交互,但我強烈懷疑spec_helper已經設置不當。我在使用mongoid的rails 3.2.11上。數據庫清理程序在每次運行後清理。
spec_helper.rb
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
DatabaseCleaner[:mongoid].strategy = :truncation
RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.filter_run focus: true
config.filter_run_excluding :remove => true
config.run_all_when_everything_filtered = true
config.include Mongoid::Matchers
config.include Capybara::DSL
ActiveSupport::Dependencies.clear
end
end
Spork.each_run do
Fabrication.clear_definitions
RSpec.configure do |config|
config.before(:each) do
DatabaseCleaner.clean
end
end
end
UPDATE:問題是與我的測試之一。這需要3秒鐘。請檢查@Sam皮西對命令的回答經常拿下面的結果
Dynamic Model should destroy collection when related source is destroyed
2.46 seconds ./spec/models/dynamic_model_spec.rb:10
Dynamic Model Validations should validate uniqueness
0.66357 seconds ./spec/models/dynamic_model_spec.rb:69
5秒沒那麼糟糕。 Ruby不是C你知道... – tjameson 2013-03-18 07:37:20
13個測試?我已經看到人們在5-6秒內運行200次以上的測試。差異似乎太大。 – Rahul 2013-03-18 07:41:14
我已經有了Ruby虛擬機需要3-4秒才能啓動,這是在最近的硬件。 – tjameson 2013-03-18 07:43:49