Permalink
Browse files

Make sure textmate formatter doesn't try to get snippet from textmate…

…-formatted URL.

- Closes #214.
  • Loading branch information...
1 parent 89530e6 commit 68d51bbaa15348bebb436de92966a518f4ea3cfc @dchelimsky dchelimsky committed Oct 1, 2011
@@ -6,16 +6,28 @@ module Core
module Formatters
# Formats backtraces so they're clickable by TextMate
class TextMateFormatter < HtmlFormatter
- def backtrace_line(line)
- if line = super(line)
- line = CGI.escapeHTML(line)
- line.sub!(/([^:]*\.e?rb):(\d*)/) do
- "<a href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2}</a> "
- end
+ def backtrace_line(line, skip_textmate_conversion=false)
+ if skip_textmate_conversion
+ super(line)
+ else
+ format_backtrace_line_for_textmate(super(line))
+ end
+ end
- line
+ def format_backtrace_line_for_textmate(line)
+ return nil unless line
+ CGI.escapeHTML(line).sub(/([^:]*\.e?rb):(\d*)/) do
+ "<a href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2}</a> "
end
end
+
+ def extra_failure_content(exception)
+ require 'rspec/core/formatters/snippet_extractor'
+ backtrace = exception.backtrace.map {|line| backtrace_line(line, :skip_textmate_conversion)}
+ backtrace.compact!
+ @snippet_extractor ||= SnippetExtractor.new
+ " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
+ end
end
end
end
@@ -338,7 +338,11 @@
org/jruby/RubyArray.java:2336:in `collect'
org/jruby/RubyProc.java:274:in `call'
org/jruby/RubyProc.java:233:in `call'</pre></div>
- <pre class="ruby"><code><span class="linenum">16</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=18&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">16</span> <span class="ident">context</span> <span class="punct">&quot;</span><span class="string">with content that would pass</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">17</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">18</span> <span class="ident">pending</span> <span class="keyword">do</span></span>
+<span class="linenum">19</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">1</span><span class="punct">)</span>
+<span class="linenum">20</span> <span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -390,7 +394,11 @@
org/jruby/RubyArray.java:2336:in `collect'
org/jruby/RubyProc.java:274:in `call'
org/jruby/RubyProc.java:233:in `call'</pre></div>
- <pre class="ruby"><code><span class="linenum">31</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=33&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">31</span><span class="ident">describe</span> <span class="punct">&quot;</span><span class="string">failing spec</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">32</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">33</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">2</span><span class="punct">)</span></span>
+<span class="linenum">34</span> <span class="keyword">end</span>
+<span class="linenum">35</span><span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -441,7 +449,7 @@
<div class="failure" id="failure_4">
<div class="message"><pre>Exception</pre></div>
<div class="backtrace"><pre><a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `&lt;main&gt;': foo (RuntimeError)</pre></div>
- <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///foo.html.erb&amp;line=1&quot;&gt;/foo.html.erb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for /foo.html.erb</span></code></pre>
</div>
</dd>
</dl>
@@ -319,7 +319,11 @@
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a>
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> </pre></div>
- <pre class="ruby"><code><span class="linenum">16</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=18&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">16</span> <span class="ident">context</span> <span class="punct">&quot;</span><span class="string">with content that would pass</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">17</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">18</span> <span class="ident">pending</span> <span class="keyword">do</span></span>
+<span class="linenum">19</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">1</span><span class="punct">)</span>
+<span class="linenum">20</span> <span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -353,7 +357,11 @@
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a>
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> </pre></div>
- <pre class="ruby"><code><span class="linenum">31</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=33&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">31</span><span class="ident">describe</span> <span class="punct">&quot;</span><span class="string">failing spec</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">32</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">33</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">2</span><span class="punct">)</span></span>
+<span class="linenum">34</span> <span class="keyword">end</span>
+<span class="linenum">35</span><span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -378,7 +386,7 @@
<div class="failure" id="failure_4">
<div class="message"><pre>Exception</pre></div>
<div class="backtrace"><pre><a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `&lt;main&gt;': foo (RuntimeError)</pre></div>
- <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///foo.html.erb&amp;line=1&quot;&gt;/foo.html.erb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for /foo.html.erb</span></code></pre>
</div>
</dd>
</dl>
@@ -319,7 +319,11 @@
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in &lt;module:Formatters&gt;'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in &lt;module:Formatters&gt;'</pre></div>
- <pre class="ruby"><code><span class="linenum">16</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=18&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">16</span> <span class="ident">context</span> <span class="punct">&quot;</span><span class="string">with content that would pass</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">17</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">18</span> <span class="ident">pending</span> <span class="keyword">do</span></span>
+<span class="linenum">19</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">1</span><span class="punct">)</span>
+<span class="linenum">20</span> <span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -353,7 +357,11 @@
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in &lt;module:Formatters&gt;'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in &lt;module:Formatters&gt;'</pre></div>
- <pre class="ruby"><code><span class="linenum">31</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=33&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">31</span><span class="ident">describe</span> <span class="punct">&quot;</span><span class="string">failing spec</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">32</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">33</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">2</span><span class="punct">)</span></span>
+<span class="linenum">34</span> <span class="keyword">end</span>
+<span class="linenum">35</span><span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -385,7 +393,7 @@
<div class="failure" id="failure_4">
<div class="message"><pre>Exception</pre></div>
<div class="backtrace"><pre><a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `&lt;main&gt;': foo (RuntimeError)</pre></div>
- <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///foo.html.erb&amp;line=1&quot;&gt;/foo.html.erb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for /foo.html.erb</span></code></pre>
</div>
</dd>
</dl>
@@ -319,7 +319,11 @@
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in &lt;module:Formatters&gt;'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in &lt;module:Formatters&gt;'</pre></div>
- <pre class="ruby"><code><span class="linenum">16</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=18&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">16</span> <span class="ident">context</span> <span class="punct">&quot;</span><span class="string">with content that would pass</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">17</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">18</span> <span class="ident">pending</span> <span class="keyword">do</span></span>
+<span class="linenum">19</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">1</span><span class="punct">)</span>
+<span class="linenum">20</span> <span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -353,7 +357,11 @@
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in &lt;module:Formatters&gt;'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
<a href="txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in &lt;module:Formatters&gt;'</pre></div>
- <pre class="ruby"><code><span class="linenum">31</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///Users/david/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&amp;line=33&quot;&gt;./spec/rspec/core/resources/formatter_specs.rb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">31</span><span class="ident">describe</span> <span class="punct">&quot;</span><span class="string">failing spec</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="linenum">32</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
+<span class="offending"><span class="linenum">33</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">2</span><span class="punct">)</span></span>
+<span class="linenum">34</span> <span class="keyword">end</span>
+<span class="linenum">35</span><span class="keyword">end</span></code></pre>
</div>
</dd>
</dl>
@@ -385,7 +393,7 @@
<div class="failure" id="failure_4">
<div class="message"><pre>Exception</pre></div>
<div class="backtrace"><pre><a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `&lt;main&gt;': foo (RuntimeError)</pre></div>
- <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for &lt;a href=&quot;txmt://open?url=file:///foo.html.erb&amp;line=1&quot;&gt;/foo.html.erb</span></code></pre>
+ <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for /foo.html.erb</span></code></pre>
</div>
</dd>
</dl>

0 comments on commit 68d51bb

Please sign in to comment.