Sinatra: log noise when running rspec tests

New in Sinatra; I run some rspec tests but get a bunch of unwanted noise in the logs. How to get rid of excessive noise in magazines? I double checked that the environment is set to: test, which means that the registrar 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
+4
source share
2 answers

As for Ben's answer: I put this in the spec helper:

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

There were some rare cases when I found that the output is useful and includes a conditional value with an environment variable, which simplifies logging, keeping it by default.

+3
source

, ActiveRecord. ActiveRecord::Base.logger = nil spec- SQL.

+3

All Articles