gpt4 book ai didi

ruby-on-rails - 防止 rspec 输出服务器和数据库日志

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

当我运行 rspec 时,我将其包含在控制台中:

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

这是我的 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

如果有帮助,我也在使用 rbenv、sqlite 和 Ubuntu。我正在使用 rails 4.1.0beta1 并使用 spring 命令 bin/rspec 运行 rspec。

最佳答案

我也在使用 rbenv,要使日志静音,您可以在控制台中执行以下命令(可能有助于设置快捷方式):

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

关于ruby-on-rails - 防止 rspec 输出服务器和数据库日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21412918/

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