Skip to content

Instantly share code, notes, and snippets.

@s-andringa
Created March 24, 2009 12:59
Show Gist options
  • Save s-andringa/84069 to your computer and use it in GitHub Desktop.
Save s-andringa/84069 to your computer and use it in GitHub Desktop.
Comparing language YML files.rb
class Hash
# Compares two hashes bases on only their keys.
# Recursively matches nested hashes too.
#
# (Used for comparing translations hashes in test.)
def =~(other, _raise = false)
if _raise
raise "Unmatched key: #{self.keys.inspect} / #{other.keys.inspect}" unless self.keys == other.keys
end
(self.keys == other.keys) && all?{ |k, v| !v.is_a?(Hash) || other[k].=~(v, _raise) }
end
end
class LanguageTest < ActiveSupport::TestCase
context "The language files" do
setup do
@en = YAML.load_file(File.join(RAILS_ROOT, 'lib', 'languages', 'en.yml'))['en']
@nl = YAML.load_file(File.join(RAILS_ROOT, 'lib', 'languages', 'nl.yml'))['nl']
end
should "contain the same keys" do
assert_nothing_raised do
assert @en.=~(@nl, true)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment