Rspec极慢 [英] Rspec extremely slow

查看:90
本文介绍了Rspec极慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使使用后卫&,我的rspec测试似乎也运行得非常慢.孢子.

My rspec tests seem to run extremely slow even with guard & spork.

Finished in 5.36 seconds
13 examples, 2 failures

我知道我可以做一些优化我的测试的事情.减少与数据库的交互,但是我强烈怀疑spec_helper的设置不正确.我在与3.2版的Mongoid混在一起.每次运行后,数据库清理器都会清理.

I understand that there are several things I can do to optimize my tests & reduce interaction with the database, but I strongly suspect that the spec_helper has been improperly setup. I'm on rails 3.2.11 with mongoid. Database cleaner cleans up after every run.

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

更新:问题出在我的一项测试中.这花了3秒钟.请检查@Sam Peacey的答案以获取我用来获得以下结果的命令

UPDATE: The problem was with one of my tests. It was taking 3 seconds. Please check @Sam Peacey's answer for the command I used to get the below result

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

推荐答案

您可以通过使用-p/--profile标志运行rspec来配置您的规格:

You can profile your specs by running rspec with the -p / --profile flag:

rspec spec -p [-drb, and whatever else]

这将列出10个最慢的示例及其执行时间.您可以通过为-p标志提供可选计数来更改默认值10.使用rspec --help

This will list the 10 slowest examples with their execution time. You can change the default of 10 by providing an optional count to the -p flag. More info by using rspec --help

这篇关于Rspec极慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆