显示每个rspec示例的运行时

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

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

您可以使用分析列出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)