Skip to content

Loading…

Fix issue 195 #295

Closed
wants to merge 1 commit into from

3 participants

@dnurzynski

Issue 195: fix RSpec hangs after alias String to_int to_i

@dchelimsky
RSpec member

Wow. Thanks for figuring out the source of this. Coincidence that #295 is the fix for #195 :)

@dnurzynski

Fix rspec hangs after String.alias :to_int :to_i

@dnurzynski

I was waiting 2x issues for that ... bug was so weird that I didn't realized when I started working on it ;)

@kaiwren

This is still happening (or happening again) on JRuby 1.6.0.

@kaiwren

So this seems to be a JRuby issue - a ticket has been created by headius: http://jira.codehaus.org/browse/JRUBY-5634

I'm not sure if there is a good work-around for this, but I'll dig a little and see what I can find.

@andreastt andreastt pushed a commit that referenced this pull request
@dnurzynski dnurzynski Fix rspec hangs after String.alias :to_int :to_i
- Closes #195.
- Closes #295.
95456c6
@kaiwren

This spec is now running on JRuby too, so it's no longer needs to be marked pending. See #418

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2011
  1. @dnurzynski
This page is out of date. Refresh to see the latest.
View
2 lib/rspec/core/formatters/base_formatter.rb
@@ -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
View
2 lib/rspec/core/formatters/snippet_extractor.rb
@@ -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 = []
View
23 spec/rspec/core/formatters/base_formatter_spec.rb
@@ -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
Something went wrong with that request. Please try again.