如何让rspec不显示数据库查询,只显示带有rails_12factor的点?

时间:2014-07-12 13:53:07

标签: ruby rspec

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

rspec spec过去只输出点数。

当我推送到Heroku时,我收到了弃用警告,并且最近添加了rails_12factor宝石来绕过它。但是现在我在本地运行规范时为每个事务获得了这个详细的db输出 当我需要它时,这是一个很好的选择 否则会产生很多不必要的和分散注意力的输出。

所以我想要一个将它用于Heroku而不是本地的选项。

请注意,这是使用格式化程序解决的,例如

rspec spec -fd

此外,如果出现错误,具有此级别的详细程度,错误几乎总是滚动离开当前页面...

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
...

1 个答案:

答案 0 :(得分:22)

我们也看到了这一点,它是由rails_12factor宝石生成的,它可以被抑制,通常只是确保gem只在生产组中,如下所示:

group :production do
  gem 'rails_12factor'
end

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