File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 77require 'rspec/mate/runner'
88require 'rspec/mate/options'
99require 'rspec/mate/switch_command'
10+ require 'rspec/mate/text_mate_formatter'
1011
1112rspec_lib = nil
1213
Original file line number Diff line number Diff line change @@ -35,12 +35,12 @@ def run_focussed(stdout, options={})
3535 end
3636
3737 def run ( stdout , options )
38- formatter = ENV [ 'TM_RSPEC_FORMATTER' ] || 'textmate'
39-
38+ formatter = ENV [ 'TM_RSPEC_FORMATTER' ] || 'RSpec::Mate::Formatters::TextMateFormatter'
4039 stderr = StringIO . new
4140 old_stderr = $stderr
4241 $stderr = stderr
4342
43+
4444 argv = options [ :files ] . dup
4545 argv << '--format' << formatter
4646
Original file line number Diff line number Diff line change 1+ require 'cgi'
2+ require 'rspec/core/formatters/html_formatter'
3+
4+ module RSpec
5+ module Mate
6+ module Formatters
7+ # Formats backtraces so they're clickable by TextMate
8+ class TextMateFormatter < RSpec ::Core ::Formatters ::HtmlFormatter
9+ def backtrace_line ( line , skip_textmate_conversion = false )
10+ if skip_textmate_conversion
11+ super ( line )
12+ else
13+ format_backtrace_line_for_textmate ( super ( line ) )
14+ end
15+ end
16+
17+ def format_backtrace_line_for_textmate ( line )
18+ return nil unless line
19+ CGI . escapeHTML ( line ) . sub ( /([^:]*\. e?rb):(\d *)/ ) do
20+ "<a href=\" txmt://open?url=file://#{ File . expand_path ( $1) } &line=#{ $2} \" >#{ $1} :#{ $2} </a> "
21+ end
22+ end
23+
24+ def extra_failure_content ( exception )
25+ require 'rspec/core/formatters/snippet_extractor'
26+ backtrace = exception . backtrace . map { |line | backtrace_line ( line , :skip_textmate_conversion ) }
27+ backtrace . compact!
28+ @snippet_extractor ||= RSpec ::Core ::Formatters ::SnippetExtractor . new
29+ " <pre class=\" ruby\" ><code>#{ @snippet_extractor . snippet ( backtrace ) } </code></pre>"
30+ end
31+ end
32+ end
33+ end
34+ end
You can’t perform that action at this time.
0 commit comments