Sha256: f3e3b23e7cdb198ffdac18b247b980bd8e2f64865a492cdb171974401337f78a

Contents?: true

Size: 1.72 KB

Versions: 34

Compression:

Stored size: 1.72 KB

Contents

module Spec
  module Runner
    class BacktraceTweaker
      def clean_up_double_slashes(line)
        line.gsub!('//','/')
      end
    end

    class NoisyBacktraceTweaker < BacktraceTweaker
      def tweak_backtrace(error)
        return if error.backtrace.nil?
        tweaked = error.backtrace.collect do |line|
          clean_up_double_slashes(line)
          line
        end
        error.set_backtrace(tweaked)
      end
    end

    # Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
    class QuietBacktraceTweaker < BacktraceTweaker
      unless defined?(IGNORE_PATTERNS)
        root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
        spec_files = Dir["#{root_dir}/lib/*"].map do |path| 
          subpath = path[root_dir.length..-1]
          /#{subpath}/
        end
        IGNORE_PATTERNS = spec_files + [
          /\/lib\/ruby\//,
          /bin\/spec:/,
          /bin\/rcov:/,
          /lib\/rspec-rails/,
          /vendor\/rails/,
          # TextMate's Ruby and RSpec plugins
          /Ruby\.tmbundle\/Support\/tmruby.rb:/,
          /RSpec\.tmbundle\/Support\/lib/,
          /temp_textmate\./,
          /mock_frameworks\/rspec/,
          /spec_server/
        ]
      end
      
      def tweak_backtrace(error)
        return if error.backtrace.nil?
        tweaked = error.backtrace.collect do |message|
          clean_up_double_slashes(message)
          kept_lines = message.split("\n").select do |line|
            IGNORE_PATTERNS.each do |ignore|
              break if line =~ ignore
            end
          end
          kept_lines.empty?? nil : kept_lines.join("\n")
        end
        error.set_backtrace(tweaked.select {|line| line})
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 6 rubygems

Version Path
dchelimsky-rspec-1.1.11.4 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.11.5 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.11.6 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.11.7 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.12 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.1 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.13 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.2 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.3 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.4 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.5 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.6 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.7 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.8 lib/spec/runner/backtrace_tweaker.rb
dchelimsky-rspec-1.1.99.9 lib/spec/runner/backtrace_tweaker.rb
newbamboo-evented-rspec-1.1.12 lib/spec/runner/backtrace_tweaker.rb
newbamboo-rspec-1.1.12 lib/spec/runner/backtrace_tweaker.rb
rspec-1.2.7 lib/spec/runner/backtrace_tweaker.rb
rspec-1.2.8 lib/spec/runner/backtrace_tweaker.rb
mack-0.8.3 lib/gems/rspec-1.1.12/lib/spec/runner/backtrace_tweaker.rb