Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinatra: Log noise when running rspec tests

New to Sinatra; I'm running some rspec tests but getting a bunch of unwanted noise in the logs. How do I get rid of the excessive noise in the logs? I've double checked that the environment is set to :test, which means logger level should be set to WARN instead of DEBUG.

spec_helper:

require "./app"
require "sinatra"
require "rspec"
require "rack/test"
require "database_cleaner"
require "factory_girl"

set :environment, :test

FactoryGirl.definition_file_paths = %w{./factories ./test/factories ./spec/factories}
FactoryGirl.find_definitions

RSpec.configure do |config|
  config.include Rack::Test::Methods
  config.include FactoryGirl::Syntax::Methods

  # Use color in STDOUT
  config.color_enabled = true

  # Use color not only in STDOUT but also in pagers and files
  config.tty = true

  # Use the specified formatter
  config.formatter = :documentation # :progress, :html, :textmate

  config.order = "random"

  config.before(:suite) do
    DatabaseCleaner.clean_with(:deletion)
  end

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

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

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

def app
  Sinatra::Application
end

app.rb

configure :test do
  set :database, 'sqlite3:///test.sqlite'
  set :logging, Logger::ERROR
end

noise:

D, [2014-01-16T22:14:28.481790 #75797] DEBUG -- :    (0.6ms)  commit transaction
D, [2014-01-16T22:14:28.484622 #75797] DEBUG -- :    (0.1ms)  begin transaction
like image 296
Ben Avatar asked Jan 17 '14 03:01

Ben


2 Answers

With regards to Ben's answer: I put this in my spec helper:

ActiveRecord::Base.logger = nil unless ENV['LOG'] == true

There were some rare cases where I found that output useful, and including the conditional with environment variable made it super easy to turn logging on, while keeping it off by default.

like image 122
Dana Scheider Avatar answered Nov 09 '22 19:11

Dana Scheider


It turns out that the noise is coming from the ActiveRecord logger. Setting ActiveRecord::Base.logger = nil in the spec helper gets rid of the SQL noise.

like image 32
Ben Avatar answered Nov 09 '22 21:11

Ben