Problems with Bundler and the Ruby 1.9.2 Yaml parser

As pointed out by Cyril Rohr here, there are issues with the default YAML parser for Bundler, Psych. So:
defaults: &defaults
  adapter: yaml
 
development:
  <<: *defaults
 
test:
  <<: *defaults
 
production:
  <<: *defaults

Even though you’d expect the different environments to inherit the defaults they will not, so ‘adapter’ will never be defined. This is because of an issue with merging YAML keys in Psych, apparently.

Cyril suggests using an initializer and switching the parser to Syck, but that didn’t work for me. According to this closed issue on bundler, the correct place to put it is right after the require for bundler (which is in boot.rb).

require 'rubygems'
  
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
  ENV['BUNDLE_GEMFILE'] = gemfile 
  require 'bundler'
    
  STDERR.puts "Temporarily changing yaml engine to syck"
  YAML::ENGINE.yamler = "syck"
  Bundler.setup 
rescue Bundler::GemNotFound => e 
  STDERR.puts e.message
  STDERR.puts "Try running `bundle install`."
  exit!
end if File.exist?(gemfile)

And all is well. Hopefully this Psych issue will be fixed soon!

Update:

Apparently the Psych issue with merge keys has been fixed, but because Psych is a part of the actual Ruby distribution, you either have to build your own Ruby from head, or wait until the next patch of Ruby 1.9.2.