查找慢速rspec测试列表

时间:2012-06-07 18:07:59

标签: ruby-on-rails-3 testing rspec

如何找到最慢的rspec测试列表?我想重构那些运行得更快。我试图寻找宝石,但找不到任何宝石。我在考虑把东西放在

Rspec.before(:each)

Rspec.after(:each)

阻止生成此列表。但我不知道如何访问规范的名称。

2 个答案:

答案 0 :(得分:55)

这实际上是建立在rspec命令之上的。在运行所有rspec测试时,只需使用-p--profile标志。

答案 1 :(得分:11)

正如丹先生所说, - 伙伴旗帜。您还可以在项目的根目录中创建.rspec文件,以便始终获得计时信息,如下所示:

$ cat .rspec 
--colour
--profile
--format nested
--backtrace

您还可以通过关闭垃圾收集来加速所有测试,如下所示:

# turn off garbage collection when running tests, place this in spec_helper.rb
RSpec.configure do |config|
  config.before(:all) do
     DeferredGarbageCollection.start
  end

  config.after(:all) do
     DeferredGarbageCollection.reconsider
  end
end