]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/runner/backtrace_tweaker.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / runner / backtrace_tweaker.rb
1 module Spec
2   module Runner
3     class BacktraceTweaker
4       def clean_up_double_slashes(line)
5         line.gsub!('//','/')
6       end
7     end
8
9     class NoisyBacktraceTweaker < BacktraceTweaker
10       def tweak_backtrace(error)
11         return if error.backtrace.nil?
12         error.backtrace.each do |line|
13           clean_up_double_slashes(line)
14         end
15       end
16     end
17
18     # Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
19     class QuietBacktraceTweaker < BacktraceTweaker
20       unless defined?(IGNORE_PATTERNS)
21         root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
22         spec_files = Dir["#{root_dir}/lib/*"].map do |path| 
23           subpath = path[root_dir.length..-1]
24           /#{subpath}/
25         end
26         IGNORE_PATTERNS = spec_files + [
27           /\/lib\/ruby\//,
28           /bin\/spec:/,
29           /bin\/rcov:/,
30           /lib\/rspec_on_rails/,
31           /vendor\/rails/,
32           # TextMate's Ruby and RSpec plugins
33           /Ruby\.tmbundle\/Support\/tmruby.rb:/,
34           /RSpec\.tmbundle\/Support\/lib/,
35           /temp_textmate\./,
36           /mock_frameworks\/rspec/,
37           /spec_server/
38         ]
39       end
40       
41       def tweak_backtrace(error)
42         return if error.backtrace.nil?
43         error.backtrace.collect! do |line|
44           clean_up_double_slashes(line)
45           IGNORE_PATTERNS.each do |ignore|
46             if line =~ ignore
47               line = nil
48               break
49             end
50           end
51           line
52         end
53         error.backtrace.compact!
54       end
55     end
56   end
57 end