一些个人测试对Zeus来说是闪电般快速的,而其他测试则相当缓慢。
如果我这样做:
time rspec spec/
结果是:
Finished in 35.36 seconds
220 examples, 0 failures
real 0m59.018s
user 0m43.723s
sys 0m2.495s
但如果我使用宙斯:
time zeus rspec spec/
结果是:
Finished in 7 minutes 9 seconds
220 examples, 0 failures
real 7m13.053s
user 0m0.279s
sys 0m0.047s
注意两者中的“用户”和“系统”时间,这些符合我的预期。然而,与“真实”时代的显示存在重大脱节。
这是怎么回事?
编辑:下面是我的spec_helper.rb文件:
require File.expand_path("../../config/environment", __FILE__)
require 'rubygems'
require 'shoulda-matchers'
require 'capybara/rspec'
require 'capybara/rails'
require 'sidekiq/testing'
require "paperclip/matchers"
require 'rspec/rails'
require 'database_cleaner'
require 'selenium-webdriver'
require 'sunspot/rails/spec_helper'
require 'timecop'
# require 'webmock/rspec'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
def spork?
defined?(Spork) && Spork.using_spork?
end
def setup_environment
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
if spork?
ENV['DRB'] = 'true'
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
end
Rails.backtrace_cleaner.remove_silencers!
DatabaseCleaner.strategy = :transaction
RSpec.configure do |config|
Warden.test_mode!
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:transaction)
end
# Use transactions by default
config.before :each do
DatabaseCleaner.strategy = :transaction
end
config.before(:each) do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
config.mock_with :rspec
config.after(:each) do
Warden.test_reset!
end
config.include Rails.application.routes.url_helpers
config.include Capybara::DSL
config.include Devise::TestHelpers, :type => :controller
config.include Warden::Test::Helpers
config.include FactoryGirl::Syntax::Methods
config.include Paperclip::Shoulda::Matchers
config.before(:each) do
::Sunspot.session = ::Sunspot::Rails::StubSessionProxy.new(::Sunspot.session)
end
config.after(:each) do
::Sunspot.session = ::Sunspot.session.original_session
end
end
OmniAuth.config.test_mode = true
end
prefork = lambda {
setup_environment
}
each_run = lambda {
if spork?
ActiveSupport::Dependencies.clear
FactoryGirl.reload
end
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
}
# If zeus is available in the Gemfile it'll be used but we don't force it.
if defined?(Zeus)
prefork.call
$each_run = each_run
class << Zeus.plan
def after_fork_with_test
after_fork_without_test
$each_run.call
end
alias_method_chain :after_fork, :test
end
# Same with spork.
elsif ENV['spork'] || $0 =~ /\bspork$/
require 'spork'
Spork.prefork(&prefork)
Spork.each_run(&each_run)
else
prefork.call
each_run.call
end
答案 0 :(得分:0)
spec_helper.rb中的“要求”太多了。你应该把它们放在你的Gemfile中:
group :test do
gem 'shoulda-matchers'
gem 'database_cleaner'
gem 'selenium-webdriver'
gem 'timecop'
# and so on
end