如何让 rspec 不显示数据库查询而只显示带有 rails_12factor 的点? [英] How to get rspec to not show db queries and just dots with rails_12factor?

查看:27
本文介绍了如何让 rspec 不显示数据库查询而只显示带有 rails_12factor 的点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ruby: 2.0
rails: 3.2.17
rspec: 2.14.8
Database: mysql

rspec spec 用于只输出点.

当我推送到 Heroku 并最近添加了 rails_12factor gem 来解决它时,我收到了弃用警告.但是,现在我在本地运行规范时为每个事务获得了这个详细的数据库输出.
当我需要它时,这是一个很好的选择,否则它会产生大量不需要且分散注意力的输出.

I was getting a deprecation warning when I pushed to Heroku and recently added the rails_12factor gem to get around it. Now however I get this verbose db output for each transaction when running specs locally.
That is a great option when I need it otherwise it is a lot of unneeded and distracting output.

所以我想要一个将它用于 Heroku 但不在本地的选项.

So I would like an option that will use it for Heroku but not locally.

注意这是没有通过使用格式化程序来解决的,例如

Note this is not addressed by using the formatter, e.g.

rspec spec -fd

此外,如果出现错误,以这种级别的详细程度,错误几乎总是从当前页面滚出...

Also, if there is an error, with this level of verbosity, the error nearly always scrolls off the current page...

09:50:39 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker 74093480_wire_up_verify_code
$ rspec spec/models/link_spec.rb -fd
Connecting to database specified by database.yml
...
Link
   (0.2ms)  BEGIN
   (0.2ms)  SAVEPOINT active_record_1
  SQL (0.6ms)  INSERT INTO `groups` (`created_at`, `group_description`, `group_name`, `updated_at`) VALUES ('2014-07-12 13:50:49', 'Various jQuery examples of common situa
tions amnd solutions', 'jQuery Examples', '2014-07-12 13:50:49')
   (0.2ms)  RELEASE SAVEPOINT active_record_1
   (0.2ms)  SAVEPOINT active_record_1
  Link Load (0.6ms)  SELECT `links`.* FROM `links` WHERE (links.position IS NOT NULL) AND (1 = 1) ORDER BY links.position DESC LIMIT 1
  SQL (0.4ms)  INSERT INTO `links` (`alt_text`, `content_date`, `created_at`, `group_id`, `position`, `updated_at`, `url_address`, `verified_date`, `version_number`) VALUE
S ('examples of common situations amnd solutions', NULL, '2014-07-12 13:50:49', 141, 1, '2014-07-12 13:50:49', 'http://test.com', NULL, NULL)
   (0.1ms)  RELEASE SAVEPOINT active_record_1
   (68.4ms)  ROLLBACK
  should be valid
   (0.2ms)  BEGIN
   (0.2ms)  SAVEPOINT active_record_1
  SQL (0.3ms)  INSERT INTO `groups` (`created_at`, `group_description`, `group_name`, `updated_at`) VALUES ('2014-07-12 13:50:49', 'Various jQuery examples of common situa
tions amnd solutions', 'jQuery Examples', '2014-07-12 13:50:49')
   (0.1ms)  RELEASE SAVEPOINT active_record_1
   (0.2ms)  SAVEPOINT active_record_1
  Link Load (0.7ms)  SELECT `links`.* FROM `links` WHERE (links.position IS NOT NULL) AND (1 = 1) ORDER BY links.position DESC LIMIT 1
  SQL (0.5ms)  INSERT INTO `links` (`alt_text`, `content_date`, `created_at`, `group_id`, `position`, `updated_at`, `url_address`, `verified_date`, `version_number`) VALUE
S ('examples of common situations amnd solutions', NULL, '2014-07-12 13:50:49', 142, 1, '2014-07-12 13:50:49', 'http://test.com', NULL, NULL)
   (0.2ms)  RELEASE SAVEPOINT active_record_1
   (67.6ms)  ROLLBACK
  should have attribute :group_id
   (0.3ms)  BEGIN
   (0.2ms)  SAVEPOINT active_record_1
  SQL (0.4ms)  INSERT INTO `groups` (`created_at`, `group_description`, `group_name`, `updated_at`) VALUES ('2014-07-12 13:50:49', 'Various jQuery examples of common situa
tions amnd solutions', 'jQuery Examples', '2014-07-12 13:50:49')
   (0.1ms)  RELEASE SAVEPOINT active_record_1
   (0.2ms)  SAVEPOINT active_record_1
  Link Load (0.5ms)  SELECT `links`.* FROM `links` WHERE (links.position IS NOT NULL) AND (1 = 1) ORDER BY links.position DESC LIMIT 1
  SQL (0.4ms)  INSERT INTO `links` (`alt_text`, `content_date`, `created_at`, `group_id`, `position`, `updated_at`, `url_address`, `verified_date`, `version_number`) VALUE
S ('examples of common situations amnd solutions', NULL, '2014-07-12 13:50:49', 143, 1, '2014-07-12 13:50:49', 'http://test.com', NULL, NULL)
   (0.1ms)  RELEASE SAVEPOINT active_record_1
   (68.7ms)  ROLLBACK
  should have attribute :url_address
...

推荐答案

我们也看到了这个,它是由 rails_12factor gem 生成的,它可以被抑制,通常只需确保 gem 是唯一的在生产组中,像这样:

We saw this too, it's generated by the rails_12factor gem and it can be surpressed, typically by just making sure that gem is only in the production group, like so:

group :production do
  gem 'rails_12factor'
end

rails_12factor 的一个依赖项是另一个名为 rails_stdout_logging 的 gem,它导致您看到的输出.

One of the dependencies of rails_12factor is another gem called rails_stdout_logging which is causing the output you're seeing.

这篇关于如何让 rspec 不显示数据库查询而只显示带有 rails_12factor 的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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