How do I shorten the backtrace for a test failure in RSpec 2?

前端 未结 2 1114
别跟我提以往
别跟我提以往 2021-01-01 15:57

When my specs hit an error, I get a message like this:

Vendor should reject duplicate names
     Failure/Error: user_with_duplicate_email.should_not be_valid         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 16:14

    In spec_helper.rb you can filter backtrace using the following code snippet:

    RSpec.configure do |config|
      # RSpec automatically cleans stuff out of backtraces;
      # sometimes this is annoying when trying to debug something e.g. a gem
    
      # RSpec 3:
      # config.backtrace_exclusion_patterns = [
      # RSpec 2:
      config.backtrace_clean_patterns = [
        /\/lib\d*\/ruby\//,
        /bin\//,
        /gems/,
        /spec\/spec_helper\.rb/,
        /lib\/rspec\/(core|expectations|matchers|mocks)/
      ]
    end
    

提交回复
热议问题