Skip to content

Commit

Permalink
Add resilience against Ruby implementations that don't support Proc#t…
Browse files Browse the repository at this point in the history
…o_s correctly (IronRuby)
  • Loading branch information
aslakhellesoy committed Nov 19, 2008
1 parent bd4e9b6 commit 289d939
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
47 changes: 31 additions & 16 deletions lib/cucumber/core_ext/proc.rb
Expand Up @@ -6,6 +6,37 @@ module CoreExt
# Proc extension that allows a proc to be called in the context of any object. # 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. # Also makes it possible to tack a name onto a Proc.
module CallIn 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 attr_accessor :name


def call_in(obj, *args) def call_in(obj, *args)
Expand All @@ -22,22 +53,6 @@ def arity2
arity == -1 ? 0 : arity arity == -1 ? 0 : arity
end 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 def meth
@meth ||= "__cucumber_#{object_id}" @meth ||= "__cucumber_#{object_id}"
end end
Expand Down
1 change: 0 additions & 1 deletion lib/cucumber/formatters/ansicolor.rb
Expand Up @@ -3,7 +3,6 @@
jruby = defined?(JRUBY_VERSION) jruby = defined?(JRUBY_VERSION)
win = Config::CONFIG['host_os'] =~ /mswin|mingw/ win = Config::CONFIG['host_os'] =~ /mswin|mingw/
ironruby = Config::CONFIG['sitedir'] =~ /IronRuby/ ironruby = Config::CONFIG['sitedir'] =~ /IronRuby/
wincolour =


gem 'term-ansicolor' unless ironruby # Rubygems don't work here yet. gem 'term-ansicolor' unless ironruby # Rubygems don't work here yet.
# Hack to work around Win32/Console, which bundles a licence-violating, outdated # Hack to work around Win32/Console, which bundles a licence-violating, outdated
Expand Down

0 comments on commit 289d939

Please sign in to comment.