How to show longer traces in Rails TestCases

前端 未结 4 2335
走了就别回头了
走了就别回头了 2021-02-15 17:19

Is there a config variable to set, or some other way to get Rails ActiveSupport::TestCase to show more than one trace line? It is really hard to de

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 18:07

    You can customize Minitest stack traces like this for example:

    class MyBacktraceFilter
      def filter bt
        bt.dup.reject{|x| not x.to_s =~ /#{::Rails.root.to_s}/}
      end
    end
    MiniTest.backtrace_filter = MyBacktraceFilter.new
    

    The filter method accepts the full stack trace in the bt parameter as an array and returns the filtered array. If you want the entire stack to show simply pass the input:

    class MyBacktraceFilter
      def filter bt
        bt
      end
    end
    MiniTest.backtrace_filter = MyBacktraceFilter.new
    

提交回复
热议问题