【问题标题】:Rspec: How to suppress warnings and notices when running tests?Rspec:如何在运行测试时抑制警告和通知?
【发布时间】:2012-06-16 16:53:06
【问题描述】:

我之前使用的是 Mysql 数据库并决定切换到 Postgresql,现在,当我使用 rspec 运行测试时,我收到了很多警告和通知。

WARNING:  there is already a transaction in progress
NOTICE:  there is no transaction in progress
      should has link "Suspender"
WARNING:  there is already a transaction in progress
NOTICE:  there is no transaction in progress
      should has css "title" with text "Suspensão de anúncio"
WARNING:  there is already a transaction in progress
NOTICE:  there is no transaction in progress
      should has css "h1" with text "Awesome job!"

我怎样才能抑制它?有没有办法对吧?

【问题讨论】:

  • 你是用标志--format progress 调用它吗?也许在你的 .rspec 文件中?
  • 不,我的 .rspec 文件中只有 --colour--drb--format d
  • 请参阅:github.com/rspec/rspec-rails/issues/58 并考虑按照问题中的建议使用 DB 清理器。
  • 您是否将:config.use_transactional_examples = true 设置为 false 并查看是否会破坏任何内容?
  • 哦,设置config.use_transaction_fixtures = false 会停止警告和通知。谢谢。

标签: ruby-on-rails-3 postgresql rspec2 rails-postgresql


【解决方案1】:

您是否将:config.use_transactional_examples = true 设置为 false 并查看是否会破坏任何内容?

【讨论】:

  • 我们需要把这条线放在哪里?我在 config/environments/test.rb 和 config/application.rb 中都试过了。仍然收到警告消息
  • 嘿,知道了。在 spec/spec_helper.rb 文件中更新了
  • 终于,看那些丑陋的消息太久了。谢谢!
【解决方案2】:

我设置了config.use_transactional_fixtures = true。这是默认设置(使用rails g rspec:install 生成的spec_helper)。我使用的是 FactoryGirl 而不是固定装置,摆脱了这个设置删除了警告。

【讨论】:

    【解决方案3】:

    禁用事务

    如果您更喜欢自己管理数据,或者使用其他工具,例如 database_cleaner 为你做这件事,只需告诉 RSpec 告诉 Rails 不要管理事务:

    RSpec.configure 做 |config| config.use_transactional_fixtures = false 结束

    https://www.relishapp.com/rspec/rspec-rails/docs/transactions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-15
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      • 2017-06-23
      • 2019-05-06
      • 1970-01-01
      相关资源
      最近更新 更多