← Back to Upcase

Disable logging of database queries when using rspec


(Charlieanna) #1

This is what I am getting on running rspec

rspec spec/integration/user_login_spec.rb
No DRb server is running. Running in local process instead ...
  ActiveRecord::SchemaMigration Load (0.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"
   (2.3ms)  DELETE FROM "activities";
   (0.2ms)  SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
   (0.1ms)  DELETE FROM sqlite_sequence where name = 'activities';
   (1.0ms)  DELETE FROM "challenges";
   (0.1ms)  SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
   (0.1ms)  DELETE FROM sqlite_sequence where name = 'challenges';
   (0.7ms)  DELETE FROM "daily_activities";
   (0.1ms)  SELECT name FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';
   (0.1ms)  DELETE FROM sqlite_sequence where name = 'daily_activities';
   (0.8ms)  DELETE FROM "identities";

How can I disable this logging?

This is my spec_helper.rb

require 'rubygems'
require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

  RSpec.configure do |config|
    
    # config.include AuthenticationHelpers
    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    # config.fixture_path = "#{::Rails.root}/spec/fixtures"

    config.include Features::SessionHelpers, type: :feature
    config.include Devise::TestHelpers, :type => :controller
    config.use_transactional_fixtures = true
    config.include FactoryGirl::Syntax::Methods
    config.infer_base_class_for_anonymous_controllers = false
    config.order = "random"
    config.include Capybara::DSL
    config.before(:suite) do
      DatabaseCleaner.clean_with(:truncation)
    end

    config.before(:each) do
      DatabaseCleaner.strategy = :transaction
    end

    config.before(:each, :js => true) do
      DatabaseCleaner.strategy = :truncation
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
end
end

Spork.each_run do
  # This code will be run each time you run your specs.

end

(Raul Murciano) #2

Have you tried disabling ActiveRecord’s logging?


(Charlieanna) #3

Yes that is what made it work for me. But I have no idea what made it to get enabled. I never faced that problem before.