Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2022 12:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Silencing ActiveRecord SQL logs when loading Rails fixtures
# By default, ActiveRecord logs SQL statements during tests – including when
# creating fixtures.
# When a Rails app has many fixtures, those logs can clobber test logs with
# a lot of logged SQL statements.
# We could disable ActiveRecord SQL logs entirely during tests, but having
# SQL queries displayed during tests is useful. Instead this snippet disables
# the ActiveRecord SQL logs just when loading fixtures.
# Usage: add this to the bottom of your tests/test_helper.rb file.
module FixturesLogSilencer
extend ActiveSupport::Concern
class_methods do
# Remove fixtures creation queries from test logs, even when config.log_level = :debug
def create_fixtures(fixtures_directory, fixture_set_names, *args)
ActiveRecord::Base.logger.silence(:info) do
Rails.benchmark 'Loading fixtures', level: :info do
class ActiveRecord::FixtureSet
prepend FixturesLogSilencer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment