gpt4 book ai didi

ruby - Sinatra:运行 rspec 测试时记录噪音

转载 作者:数据小太阳 更新时间:2023-10-29 07:13:36 25 4
gpt4 key购买 nike

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

最佳答案

关于 Ben 的回答:我把它放在我的规范助手中:

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

在一些罕见的情况下,我发现输出很有用,并且包括带有环境变量的条件使得打开日志记录变得非常容易,同时默认情况下保持关闭。

关于ruby - Sinatra:运行 rspec 测试时记录噪音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21177188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com