Skip to content

Instantly share code, notes, and snippets.

@francois-ferrandis
Created December 7, 2022 15:58
Show Gist options
  • Save francois-ferrandis/0e2de19cd028d407d422e869fc79b5f7 to your computer and use it in GitHub Desktop.
Save francois-ferrandis/0e2de19cd028d407d422e869fc79b5f7 to your computer and use it in GitHub Desktop.
Measure time spent in DB in a RSpec suite
RSpec.configure do |config|
config.before(:suite) do
$_events = []
end
config.around do |example|
callback = lambda do |*args|
$_events << ActiveSupport::Notifications::Event.new(*args)
end
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
example.run
end
end
config.after(:suite) do
p $_events.sum(&:duration)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment