Skip to content

Commit 2d85738

Browse files
committed
Merge pull request #50 from rspec/move-textmate-formatter
2 parents decddb9 + bbeb1bd commit 2d85738

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Support/lib/rspec/mate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require 'rspec/mate/runner'
88
require 'rspec/mate/options'
99
require 'rspec/mate/switch_command'
10+
require 'rspec/mate/text_mate_formatter'
1011

1112
rspec_lib = nil
1213

Support/lib/rspec/mate/runner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

0 commit comments

Comments
 (0)