rails_parallel 使您的 Rails 测试能够根据可用的 CPU 核心数进行扩展。它还通过大量使用 fork 来仅加载一次 Rails 环境,从而总体上加快了测试过程。
要加载 rails_parallel,请在您的 Rakefile 中尽早 require “rails_parallel/rake”。 一种可能的方法是根据环境变量有条件地加载它
require 'rails_parallel/rake' if ENV['PARALLEL']
您需要添加一个 lib/tasks/rails_parallel.rake 文件,其中至少包含以下内容
# RailsParallel handles the DB schema.
Rake::Task['test:prepare'].clear_prerequisites if Object.const_get(:RailsParallel)
namespace :parallel do
# Run this task if you have non-test tasks to run first and you want the
# RailsParallel worker to start loading your environment earlier.
task :launch do
RailsParallel::Rake.launch
end
namespace :db do
# RailsParallel runs this if it needs to reload the DB.
task :setup => ['db:drop', 'db:create', 'db:schema:load']
# RailsParallel normally doesn't mess with your current DB,
# only the 'test' env DB. Run this to load it if required.
task :load => :environment do
RailsParallel::Rake.load_current_db
end
end
end
此 gem 最初是作为一个内部项目设计的,目前对您的项目设置做了一些假设,例如使用 MySQL 和单独的版本化 schema (而不是 db/schema.rb)。 这些将在未来的版本中变得更加通用。
版权所有 (c) 2011 Shopify。 根据 MIT 许可证发布。