在使用 Rails 3.1 进行测试期间禁用终端中的 SQL 日志记录?(RSPEC/黄瓜) [英] Disable SQL logging in terminal during testing with Rails 3.1? (RSPEC/Cucumber)

查看:31
本文介绍了在使用 Rails 3.1 进行测试期间禁用终端中的 SQL 日志记录?(RSPEC/黄瓜)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的应用升级到 rails 3.1,现在每当我运行测试时,我的终端都会得到大量 SQL 输出.

I just upgraded my app to rails 3.1 and now whenever I run tests I get a ton of SQL output in my terminal.

例如:

   (1.0ms)  TRUNCATE TABLE `users`;
   (0.1ms)  SET FOREIGN_KEY_CHECKS = 1
.  Company Load (0.3ms)  SELECT `companies`.* FROM `companies` LIMIT 1
  Sector Load (0.3ms)  SELECT `sectors`.* FROM `sectors` WHERE `sectors`.`name` = 'General' LIMIT 1
   (0.1ms)  BEGIN
   (0.3ms)  SELECT 1 FROM `sectors` WHERE `sectors`.`name` = BINARY 'General 63' LIMIT 1
  SQL (0.2ms)  INSERT INTO `sectors` (`created_at`, `name`, `price_in_cents`, `updated_at`) VALUES ('2011-09-13 20:46:48', 'General 63', 0, '2011-09-13 20:46:48')
   (0.3ms)  COMMIT

有什么办法可以禁用它吗?

Is there any way to disable this?

我正在使用 rspec instafail,但我看不到它们了,因为它充斥着 SQL 输出.

I'm using rspec instafail and I can't seem them anymore because its flooded with SQL output.

我尝试添加本文中的内容,但没有帮助:http://tesoriere.com/2011/05/28/rails-3.1---sql-logging-to-stdout-during-testing--with-rspec--test-unit--or-cucumber-/

I tried adding what was in this article but it didnt help: http://tesoriere.com/2011/05/28/rails-3.1---sql-logging-to-stdout-during-testing--with-rspec--test-unit--or-cucumber-/

推荐答案

您是否尝试过在您的环境/test.rb 中设置 config.log_level?

Have you tried setting the config.log_level in your environments/test.rb?

config.log_level = :error

这将是最简单的解决方案,除非有其不工作的原因.

That would be the easiest solution, unless there's a reason it's not working.

这篇关于在使用 Rails 3.1 进行测试期间禁用终端中的 SQL 日志记录?(RSPEC/黄瓜)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆