Permalink
Browse files

Fixed backtrace issues on Windows [Issue #57]

  • Loading branch information...
1 parent 92e0fc4 commit 7181494c0d76cfa62ed475d277192011fd28e640 @voxik committed Jul 4, 2010
Showing with 18 additions and 4 deletions.
  1. +13 −3 lib/rspec/core/formatters/base_formatter.rb
  2. +5 −1 lib/rspec/core/metadata.rb
@@ -138,18 +138,28 @@ def backtrace_line(line)
def read_failed_line(exception, example)
original_file = example.file_path.to_s.downcase
- matching_line = exception.backtrace.detect { |line| line.split(':').first.downcase == original_file.downcase }
-
+ matching_line = exception.backtrace.detect { |line| extract_file_path(line).downcase == original_file.downcase }
return "Unable to find matching line from backtrace" if matching_line.nil?
- file_path, line_number = matching_line.split(':')
+ file_path = extract_file_path(matching_line)
if File.exist?(file_path)
+ line_number = extract_line_number(matching_line)
open(file_path, 'r') { |f| f.readlines[line_number.to_i - 1] }
else
"Unable to find #{file_path} to read failed line"
end
end
+ def extract_file_path(line)
+ Pathname.new(line).cleanpath.to_s
+ end
+
+ def extract_line_number(line)
+ path = extract_file_path(line)
+ line.gsub!(/#{path + ':'}/, '')
+ line.split(':').first
+ end
+
def sync_output
begin
old_sync, output.sync = output.sync, true if output_supports_sync
@@ -164,7 +164,11 @@ def location_from(metadata)
def file_and_line_number(metadata)
entry = candidate_entries_from_caller(metadata).first
- entry && entry.split(":")
+ if entry
+ path = Pathname.new(entry).cleanpath.to_s
+ entry = entry.gsub(/#{path + ':'}/, '')
+ end
+ entry && [path, entry.split(":")].flatten
end
def candidate_entries_from_caller(metadata)

0 comments on commit 7181494

Please sign in to comment.