简体   繁体   中英

Rails4: reduce Rspec and Capybara error output

Is there a way to disable Rspce&Capybara's error output? 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:

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

An alternate approach also exists, you can explicitly list the gems to ignore:

config.filter_gems_from_backtrace "ignored_gem", "another_ignored_gem"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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