Skip to content

Instantly share code, notes, and snippets.

@jmgarnier
Created September 8, 2014 09:06
Show Gist options
  • Save jmgarnier/0573eb9fadaf6027c3c1 to your computer and use it in GitHub Desktop.
Save jmgarnier/0573eb9fadaf6027c3c1 to your computer and use it in GitHub Desktop.
Use FactoryGirl AR instrumentation to track how much time is spent creating test data
# https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#activesupport-instrumentation
RSpec.configure do |config|
test_data_setup_time = 0
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
execution_time_in_seconds = finish - start
test_data_setup_time += execution_time_in_seconds
if execution_time_in_seconds >= 1
$stderr.puts "Slow factory: #{payload[:name]} using strategy #{payload[:strategy]}"
end
end
config.after(:suite) do
puts "Time spent creating test data: #{test_data_setup_time} seconds"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment