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

前端 未结 2 1095
别跟我提以往
别跟我提以往 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
    
    0 讨论(0)
  • 2021-01-01 16:20

    I updated it to work with with Rspec 3.2.3. In spec_helper.rb put:

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

    This is pure gold. Thank you luacassus!

    0 讨论(0)
提交回复
热议问题