Skip to content
Browse files

Add resilience against Ruby implementations that don't support Proc#t…

…o_s correctly (IronRuby)
  • Loading branch information...
1 parent bd4e9b6 commit 289d93930f5247bb8e73fc763b096799c4afb7a6 @aslakhellesoy aslakhellesoy committed
Showing with 31 additions and 17 deletions.
  1. +31 −16 lib/cucumber/core_ext/proc.rb
  2. +0 −1 lib/cucumber/formatters/ansicolor.rb
View
47 lib/cucumber/core_ext/proc.rb
@@ -6,6 +6,37 @@ module CoreExt
# Proc extension that allows a proc to be called in the context of any object.
# Also makes it possible to tack a name onto a Proc.
module CallIn
+ PROC_PATTERN = /[\d\w]+@(.*):(.*)>/
+
+ if Proc.new{}.to_s =~ PROC_PATTERN
+ def to_backtrace_line
+ "#{file_colon_line}:in `#{name}'"
+ end
+
+ def to_comment_line
+ "# #{file_colon_line}"
+ end
+
+ def file_colon_line
+ path, line = *to_s.match(PROC_PATTERN)[1..2]
+ path = File.expand_path(path)
+ pwd = Dir.pwd
+ path = path[pwd.length+1..-1]
+ "#{path}:#{line}"
+ end
+ else
+ # This Ruby implementation doesn't implement Proc#to_s correctly
+ STDERR.puts "*** THIS RUBY IMPLEMENTATION DOESN'T REPORT FILE AND LINE FOR PROCS ***"
+
+ def to_backtrace_line
+ nil
+ end
+
+ def to_comment_line
+ ""
+ end
+ end
+
attr_accessor :name
def call_in(obj, *args)
@@ -22,22 +53,6 @@ def arity2
arity == -1 ? 0 : arity
end
- def to_backtrace_line
- "#{file_colon_line}:in `#{name}'"
- end
-
- def to_comment_line
- "# #{file_colon_line}"
- end
-
- def file_colon_line
- path, line = *to_s.match(/[\d\w]+@(.*):(.*)>/)[1..2]
- path = File.expand_path(path)
- pwd = Dir.pwd
- path = path[pwd.length+1..-1]
- "#{path}:#{line}"
- end
-
def meth
@meth ||= "__cucumber_#{object_id}"
end
View
1 lib/cucumber/formatters/ansicolor.rb
@@ -3,7 +3,6 @@
jruby = defined?(JRUBY_VERSION)
win = Config::CONFIG['host_os'] =~ /mswin|mingw/
ironruby = Config::CONFIG['sitedir'] =~ /IronRuby/
-wincolour =
gem 'term-ansicolor' unless ironruby # Rubygems don't work here yet.
# Hack to work around Win32/Console, which bundles a licence-violating, outdated

0 comments on commit 289d939

Please sign in to comment.
Something went wrong with that request. Please try again.