简体   繁体   English

Rails4:减少Rspec和Capybara错误输出

[英]Rails4: reduce Rspec and Capybara error output

Is there a way to disable Rspce&Capybara's error output? 有没有办法禁用Rspce&Capybara的错误输出? I just want to see the main errors 我只想看看主要错误

   Delete an Article User Delete an Article
             Failure/Error: click_link "Delete Article"
             ActiveRecord::RecordNotFound:
               Couldn't find Article with 'id'=315

Instead of full error log. 而不是完整的错误日志。

 Delete an Article User Delete an Article
         Failure/Error: click_link "Delete Article"
         ActiveRecord::RecordNotFound:
           Couldn't find Article with 'id'=315
         # /usr/local/rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/core.rb:155:in `find'
         # ./app/controllers/articles_controller.rb:29:in `show'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/abstract_controller/base.rb:198:in `process_action'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:117:in `call'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:117:in `call'
         # /usr/local/rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
        ....

My gem file 我的宝石文件

group :development, :test do
  gem 'byebug'
  gem 'rspec-rails','3.2.3'
  gem 'guard-rspec',require: false
  gem 'spring-commands-rspec'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

group :test do

  gem 'capybara','2.4.4'

end

I want to disable it as I need to scroll a lot to see the real errors. 我想禁用它,因为我需要滚动很多才能看到真正的错误。 Hope it is clear. 希望清楚。

I just tried it and it works just fine with Rspec 3.4.0, it blocked out the backtrace that extended into the gems: 我刚刚尝试过,它在Rspec 3.4.0中可以正常工作,它阻止了延伸到gems中的回溯:

# spec_helper.rb
RSpec.configure do |config|
  config.backtrace_exclusion_patterns = [
    /\/lib\d*\/ruby\//,
    /bin\//,
    /gems/,
    /spec\/spec_helper\.rb/,
    /lib\/rspec\/(core|expectations|matchers|mocks)/
  ]
end

Make sure you're using config.backtrace_exclusion_patterns and not config.backtrace_clean_patterns since you're using Rspec 3.x. 确保您使用的是config.backtrace_exclusion_patterns而不是config.backtrace_clean_patterns因为您使用的是Rspec3.x。

An alternate approach also exists, you can explicitly list the gems to ignore: 还存在另一种方法 ,您可以显式列出要忽略的gem:

config.filter_gems_from_backtrace "ignored_gem", "another_ignored_gem"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM