Some thoughts (no promises that they'll help):
1. Rails messes with stuff, and has historically messed with
serialization (json, yaml, etc.) in ways that do stuff like this.
2. If you have a way that works reliably (f << x.to_yaml) hold on to
that, but be sure to check that the serialized output is correct (and
can be reloaded).
3. You may want to play with the options to open, specifically
external_encoding, as that seems to be most directly applicable to the
error you're getting, e.g. something like:
- File.open("test.yml", "w") do |f|
+ File.open("test.yml", "w", external_encoding: 'utf-8') do |f|
4. Good luck, and please let us know what you discover.
-- M