Reputation: 449
I'm trying to get some easy-to-read time metrics for how long steps of each scenario take to run.
I have methods that insert rows into a logging table like this:
puts "#{Time.now} - Starting Given"
puts "#{Time.now} - Ending Given"
etc...
And I want them to be called automatically at the start and end of each step, but I can only find ways to run them before or after the entire scenario, rather than each step.
Is there a way to do this?
Upvotes: 0
Views: 391
Reputation: 5732
Ruby comes with a benchmarking module to handle this stuff pretty easily for you.
Edit to address the comments below
In Cucumber, there is a hook called Around
that allows you to wrap your scenario however you wish. For example, straight from the docs:
Around('@fast') do |scenario, block|
Timeout.timeout(0.5) do
block.call #actually runs the scenario
end
end
Upvotes: 2