Rspec: How to suppress warnings and notices when running tests?

自闭症网瘾萝莉.ら 提交于 2019-12-10 01:56:51

问题


I was using Mysql database before and decided to switch to Postgresql and now, when I run my tests using rspec, I getting a lot of warnings and notices.

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!"

How can I suppress that? Is there a way, right?


回答1:


Did you set: config.use_transactional_examples = true to false and see if that breaks anything?




回答2:


I had config.use_transactional_fixtures = true set. This was default (spec_helper generated with rails g rspec:install). I am using FactoryGirl instead of fixtures, getting rid of this setting removed warnings.




回答3:


Disabling transactions

If you prefer to manage the data yourself, or using another tool like database_cleaner to do it for you, simply tell RSpec to tell Rails not to manage transactions:

RSpec.configure do |config| config.use_transactional_fixtures = false end

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



来源:https://stackoverflow.com/questions/11065328/rspec-how-to-suppress-warnings-and-notices-when-running-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!