0

I am quite new to ruby on rails. I can't figure it out on how to show time elapse on every tests. For now I am studying rspecs and cucumber. I ran all the test by running command rake. And when every test is executed, I want it to show a timer. I want to display the time elapsed on every specific test. Can we do it like just a global function that will listen to every test processes?

Please help me.

1 Answers1

1

You have two options, my recommendation would be to use the first one, as it's already provided by Rspec.

1. Use rspec --profile

This is a built-in feature of Rspec and will show you the times for the 10 slowest specs. Read Show runtime for each rspec example for more details.

2. Use global Before/After

You can also create your own solution, in spec/spec_helper (or wherever you configure Rspec), add something like:

Rspec.configure do |config|
 config.before(:each) do
   @start_timer = Time.now
 end

  config.after(:each) {}
    puts "Spec ran in #{Time.now - @start_timer}s"
  end
end
Community
  • 1
  • 1
Ariejan
  • 10,910
  • 6
  • 43
  • 40