Sinatra的新手;我正在运行一些rspec测试,但在日志中收到了一堆不必要的噪音。如何摆脱日志中的过度噪音?我已经仔细检查过环境设置为:test,这意味着记录器级别应该设置为WARN而不是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
噪声
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
答案 0 :(得分:5)
关于Ben的答案:我把它放在我的规范助手中:
ActiveRecord::Base.logger = nil unless ENV['LOG'] == true
在一些罕见的情况下,我发现输出很有用,并且包括带有环境变量的条件使得在登录时非常容易,同时默认情况下保持关闭。
答案 1 :(得分:3)
事实证明,噪音来自ActiveRecord记录器。
在规范助手中设置ActiveRecord::Base.logger = nil
可以消除SQL噪声。