Created
March 24, 2009 12:59
-
-
Save s-andringa/84069 to your computer and use it in GitHub Desktop.
Comparing language YML files.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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