Created
December 7, 2022 15:58
-
-
Save francois-ferrandis/0e2de19cd028d407d422e869fc79b5f7 to your computer and use it in GitHub Desktop.
Measure time spent in DB in a RSpec suite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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