[rspec-users] patch for html display

Tim Harper timcharper at gmail.com
Fri Jan 4 01:15:48 EST 2008


All,

I've found that the html view for the rspec formatter falls to pieces with
Rails 2.02 and rspec 1.10.  Has anyone else run into this trouble?

Here's a monkey patch that fixes the problem.  A more elegant fix would be
in order, but this gets the job done:

Index:
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb
===================================================================
---
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb
(revision 906)
+++
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb
(working copy)
@@ -6,8 +6,9 @@
       # Formats backtraces so they're clickable by TextMate
       class TextMateFormatter < HtmlFormatter
         def backtrace_line(line)
-          line.gsub(/([^:]*\.rb):(\d*)/) do
-            "<a
href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2}</a>
"
+          line.gsub!(/^(On line #([0-9]+) of )(.+)$/) {
"app/views/#{$3}:#{$2}"}
+          line.gsub(/([^:]*\.(rb|rhtml|erb)):(\d*)/) do
+            "<a
href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$3}\">#{$1}:#{$3}</a>
"
           end
         end
       end
Index:
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb
===================================================================
---
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb
(revision 906)
+++
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb
(working copy)
@@ -88,6 +88,7 @@

         def format_backtrace(backtrace)
           return "" if backtrace.nil?
+          backtrace = backtrace.first.split("\n").map { |l| h(l).strip }
           backtrace.map { |line| backtrace_line(line) }.join("\n")
         end



Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080103/8c03be19/attachment.html 


More information about the rspec-users mailing list