Permalink
Browse files

Fix rspec hangs after String.alias :to_int :to_i

- Closes #195.
- Closes #295.
  • Loading branch information...
1 parent 1a66ce9 commit 95456c6b8a2b65096927154a59a3c84b13bd6ada @dnurzynski dnurzynski committed with dchelimsky Feb 1, 2011
@@ -121,7 +121,7 @@ def read_failed_line(exception, example)
file_path, line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/)[1..2]
if File.exist?(file_path)
- open(file_path, 'r') { |f| f.readlines[line_number.to_i - 1] }
+ File.readlines(file_path)[line_number.to_i - 1]
else
"Unable to find #{file_path} to read failed line"
end
@@ -25,7 +25,7 @@ def snippet_for(error_line)
def lines_around(file, line)
if File.file?(file)
- lines = File.open(file).read.split("\n")
+ lines = File.read(file).split("\n")
min = [0, line-3].max
max = [line+1, lines.length-1].min
selected_lines = []
@@ -31,6 +31,29 @@
formatter.send(:read_failed_line, exception, example)
}.should_not raise_error
end
+
+ context "when String alias to_int to_i" do
+ before do
+ class String
+ alias :to_int :to_i
+ end
+ end
+
+ after do
+ class String
+ undef to_int
+ end
+ end
+
+ it "doesn't hang when file exists" do
+ exception = mock(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
+
+ example = mock(:Example, :file_path => __FILE__)
+ formatter.send(:read_failed_line, exception, example).should
+ eql %Q{ exception = mock(:Exception, :backtrace => [ "\#{__FILE__}:\#{__LINE__}"])\n}
+ end
+
+ end
end
end

0 comments on commit 95456c6

Please sign in to comment.