Prevent rspec from outputting server and database logs

rspec, ruby, ruby-on-rails

Solution

I'm using rbenv as well, and to silence the logs you can execute the following in console (might be helpful to setup a shortcut):

ActiveRecord::Base.logger.level = Logger::INFO
ActionController::Base.logger.level = Logger::ERROR
Rails.logger.level = Logger::ERROR

Problem

When I run rspec, I get this included in the console: ``` ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" (0.1ms) begin transaction (0.0ms) commit transaction (0.0ms) begin transaction Started GET "/" for 127.0.0.1 at 2014-01-28 11:44:06 -0600 Processing by HomeController#index as HTML Rendered home/index.html.haml within layouts/application (28.1ms) Completed 200 OK in 54ms (Views: 52.0ms | ActiveRecord: 0.0ms) (0.1ms) rollback transaction ``` Here is my spec_helper.rb: ``` ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rails' require 'capybara/rspec' Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = false config.order = "random" config.use_transactional_fixtures = false config.before(:each) do DatabaseCleaner.strategy = if example.metadata[:js] :truncation else :transaction end DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end end ``` I am also using rbenv, sqlite and Ubuntu if that helps. I am using rails 4.1.0beta1 and I run rspec using the spring command `bin/rspec`.

Original source