[MacRuby-devel] Help with bug from Cucumber codebase

M. Scott Ford scott at vaderpi.com
Wed Feb 11 08:53:39 PST 2009


Hello,

I have been trying to get cucumber working with MacRuby, and I have  
run into a bug. I have tracked the source of it down to a block of  
code in cucumber's code base[BLOCK 1]. I have condensed this down to a  
much smaller example[BLOCK 2]. In ruby 1.9.1 the second block results  
in 'yellow,bold', but in macruby the second block results in nil.

My guess is that there is a bug in the merge implementation or the  
constructor implementation. I am not familiar enough with ruby to know  
which, so I will take a look at both. I feel this should be added as a  
test case, but I am not sure where to put that, since I am new to the  
project. Any tips?

-Scott

----- BLOCK 1 ----------
       ALIASES = Hash.new do |h,k|
         if k.to_s =~ /(.*)_param/
           h[$1] + ',bold'
         end
       end.merge({
         'missing' => 'yellow',
         'pending' => 'yellow',
         'failed'  => 'red',
         'passed'  => 'green',
         'outline' => 'cyan',
         'skipped' => 'cyan',
         'comment' => 'grey',
         'tag'     => 'blue'
       })

       if ENV['CUCUMBER_COLORS'] # Example: export  
CUCUMBER_COLORS="passed=red:failed=yellow"
         ENV['CUCUMBER_COLORS'].split(':').each do |pair|
           a = pair.split('=')
           ALIASES[a[0]] = a[1]
         end
       end

       ALIASES.each do |method, color|
         unless method =~ /.*_param/
           code = <<-EOF
           def #{method}(string=nil, &proc)
             #{ALIASES[method].split(",").join("(") + "(string, &proc"  
+ ")" * ALIASES[method].split(",").length}
           end
           # This resets the colour to the non-param colour
           def #{method}_param(string=nil, &proc)
             #{ALIASES[method+'_param'].split(",").join("(") +  
"(string, &proc" + ")" * ALIASES[method+'_param'].split(",").length} +  
#{ALIASES[method].split(",").join(' + ')}
           end
           EOF
           eval(code)
         end
       end
-------------- END BLOCK 1 --------------

------- BLOCK 2 ------------------

ALIASES = Hash.new do |h,k|
   if k.to_s =~ /(.*)_param/
     h[$1] + ',bold'
   end
end.merge({
   'missing' => 'yellow'
})

puts ALIASES['missing_param']

--------- END BLOCK 2 ---------


More information about the MacRuby-devel mailing list