Permalink
Browse files

Add RSpec tests for locales.json

(and apparently locales.json was already in good shape, phew!)
  • Loading branch information...
rmzelle committed Mar 30, 2016
1 parent 8c97640 commit 6525420583b872fb53153cd36071614126b94140
Showing with 80 additions and 22 deletions.
  1. +26 −22 Gemfile.lock
  2. +53 −0 spec/repository_spec.rb
  3. +1 −0 spec/spec_helper.rb
View
@@ -1,34 +1,35 @@
GEM
remote: https://rubygems.org/
specs:
csl (1.2.3)
csl (1.4.3)
namae (~> 0.7)
diff-lcs (1.2.5)
fuubar (2.0.0)
rspec (~> 3.0)
ruby-progressbar (~> 1.4)
mini_portile (0.6.2)
namae (0.9.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nokogiri (1.6.6.2-x64-mingw32)
mini_portile (~> 0.6.0)
nokogiri (1.6.6.2-x86-mingw32)
mini_portile (~> 0.6.0)
rake (10.4.2)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
mini_portile2 (2.0.0)
namae (0.10.1)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.6.7.2-x64-mingw32)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.6.7.2-x86-mingw32)
mini_portile2 (~> 2.0.0.rc2)
rake (11.1.2)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
ruby-progressbar (1.7.1)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
ruby-progressbar (1.7.5)
PLATFORMS
ruby
@@ -41,3 +42,6 @@ DEPENDENCIES
nokogiri
rake
rspec
BUNDLED WITH
1.11.2
View
@@ -0,0 +1,53 @@
describe "The file \"locales.json\"" do
before(:all) do
locales_file_path = File.join("#{LOCALE_ROOT}", "locales.json")
@locales_file_exists = File.exist?(locales_file_path)
@locales_file_validates = false
begin
locales = JSON.parse(File.read(locales_file_path))
@locales_file_validates = true
rescue JSON::ParserError => e
end
@primary_dialects = {}
@language_names = {}
if @locales_file_validates
@primary_dialects = locales["primary-dialects"]
@language_names = locales["language-names"]
end
# Store locales of locale files (based on their file names)
@locale_file_locales = Dir[File.join(LOCALE_ROOT, 'locales-*.xml')].map { |path|
filename = File.basename(path)
locale = filename[8..-5]
}
@locale_file_languages = @locale_file_locales.map { |locale| language = locale[0..1] }
@locale_file_languages.uniq!
end
it "must be present" do
expect(@locales_file_exists).to be true
end
it "must be valid JSON" do
if @locales_file_exists
expect(@locales_file_validates).to be true
end
end
it "must define a primary dialect for every language (e.g. \"de-DE\" for \"de\")" do
expect(@locale_file_languages - @primary_dialects.keys).to eq([])
end
it "must define language names for every locale" do
expect(@locale_file_locales - @language_names.keys).to eq([])
end
it "must define two language names for every locale (in the language itself and in English)" do
incorrect_entries = @language_names.select { |locale, descriptions| descriptions.length != 2 }
expect(incorrect_entries).to eq({})
end
end
View
@@ -1,4 +1,5 @@
require 'csl'
require 'json'
LOCALE_ROOT = File.expand_path('../..', __FILE__)

0 comments on commit 6525420

Please sign in to comment.