File: backtrace_filter.rb

package info (click to toggle)
ruby-mocha 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,656 kB
  • sloc: ruby: 12,304; javascript: 499; makefile: 14
file content (25 lines) | stat: -rw-r--r-- 567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module Mocha
  class BacktraceFilter
    LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), '..')) + File::SEPARATOR

    def initialize(lib_directory = LIB_DIRECTORY)
      @lib_directory = lib_directory
    end

    def filtered(backtrace)
      backtrace.reject { |line| exclude?(line) }
    end

    def filtered_locations(locations)
      locations.reject { |location| exclude?(location.path) }
    end

    private

    def exclude?(path)
      File.expand_path(path).start_with?(@lib_directory)
    end
  end
end