显示每个rspec示例的运行时

时间:2011-01-31 21:46:40

标签: ruby-on-rails tdd rspec rspec-rails

目前我正在运行超过1k的示例,并且需要很长时间才能完成(超过 20分钟!!! )。

我想确定哪些示例需要花费更多时间才能完成,有没有办法运行rspec并返回每个示例完成(单独)所需的时间?我正在使用 rspec 1.3.0 rspec-rails 1.2.3

1 个答案:

答案 0 :(得分:45)

您可以使用分析列出10个最慢的示例:

spec -p spec/*/*_spec.rb --colour --format profile

如果您在特定测试套件上运行此操作,您可以从较小的示例子集中获取10个最慢的示例:

spec -p spec/models/user_spec.rb --format profile

Rspec的新版本

对于较新版本的rspec,您应该使用--profile选项:

rspec spec/ --profile         | (shows the 10 slowest examples)
rspec spec/ --profile 2       | (shows the 2  slowest examples)