Skip to content

Commit

Permalink
Output timinig info for slowest scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Jun 15, 2019
1 parent 70e7df3 commit 0ce4b7b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions features/support/timing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# From https://itshouldbeuseful.wordpress.com/2010/11/10/find-your-slowest-running-cucumber-features/

scenario_times = {}

Around do |scenario, block|
name = "#{scenario.feature.file}::#{scenario.name}"
start = Time.now
block.call
end_time = Time.now
scenario_times[name] = end_time - start
end

at_exit do
max_scenarios = scenario_times.size > 20 ? 20 : scenario_times.size
puts "------------- Top #{max_scenarios} slowest scenarios -------------"
sorted_times = scenario_times.sort { |a, b| b[1] <=> a[1] }
sorted_times[0..max_scenarios - 1].each do |key, value|
puts format("%.2f %s", value, key)
end
end

0 comments on commit 0ce4b7b

Please sign in to comment.