Reputation: 2268
After you run rspec file from terminal - you can see execution duration of all tests from terminal output. It looks like something like this:
3 examples, 0 failures, 3 passed
Finished in 65.007918085 seconds
Is there any way to save that duration to variable (for example - to send test time statistic to database)?
Upvotes: 0
Views: 182
Reputation: 27227
I believe you can use an rspec custom formatter to access this data, and control how the output appears. If you are lucky, someone else may have already written one you can re-use. Alternatively, you probably only need to sub-class the formatter you already use, and extend the method start_dump to do something interesting with the duration data, then call super.
To invoke a custom formatter, you simply do
rspec -f MyFormatter name_of_test_spec.rb
More information on rspec custom formatters:
https://www.relishapp.com/rspec/rspec-core/docs/formatters/custom-formatters
http://rubydoc.info/gems/rspec-core/2.6.4/RSpec/Core/Formatters/BaseFormatter
Upvotes: 1
Reputation: 11096
Pipe the output to the shell and use a regex to extract the duration.
Upvotes: 1