Suppress backtrace for Rspec 3

2019-05-21 18:12发布

问题:

I am using rspec 3.2.0 and capybara 2.4.4 and have in my spec_helper.rb file as below

config.full_backtrace=false

On most errors, I am getting a backtrace, e.g.

Failure/Error: check 'un_student_3'
 Capybara::ElementNotFound:
   Unable to find checkbox "un_student_3"
 # /Users/115698/.rvm/gems/ruby-2.1.1@match_maker/gems/capybara-2.4.4/lib/capybara/node/finders.rb:41:in `block in find'
 # /Users/115698/.rvm/gems/ruby-2.1.1@match_maker/gems/capybara-2.4.4/lib/capybara/node/base.rb:84:in `synchronize'
 # /Users/115698/.rvm/gems/ruby-2.1.1@match_maker/gems/capybara-2.4.4/lib/capybara/node/finders.rb:30:in `find'
 # /Users/115698/.rvm/gems/ruby-2.1.1@match_maker/gems/capybara-2.4.4/lib/capybara/node/actions.rb:82:in `check'
 # /Users/115698/.rvm/gems/ruby-2.1.1@match_maker/gems/capybara-2.4.4/lib/capybara/session.rb:676:in `block (2 levels) in <class:Session>'
 # /Users/115698/.rvm/gems/ruby-2.1.1@match_maker/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
 # ./spec/features/students/student_spec.rb:56:in `block (2 levels) in <top (required)>'

How can I turn this off?

回答1:

Based in a reading between the lines (or comments) of this question: How do I shorten the backtrace for a test failure in RSpec 2?, the way to do this is put in your spec_helper.rb file

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