显示每个rspec示例的运行时

jpe*_*thy 33 tdd rspec ruby-on-rails rspec-rails

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

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

Pan*_*kos 48

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

spec -p spec/*/*_spec.rb --colour --format profile
Run Code Online (Sandbox Code Playgroud)

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

spec -p spec/models/user_spec.rb --format profile
Run Code Online (Sandbox Code Playgroud)

较新版本的Rspec

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

rspec spec/ --profile         | (shows the 10 slowest examples)
rspec spec/ --profile 2       | (shows the 2  slowest examples)
Run Code Online (Sandbox Code Playgroud)

  • 我认为在较新版本的RSpec中你只需要使用`--profile`选项. (13认同)