Skip to content

Instantly share code, notes, and snippets.

@luiscronicl
Created February 1, 2013 13:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luiscronicl/4691356 to your computer and use it in GitHub Desktop.
Save luiscronicl/4691356 to your computer and use it in GitHub Desktop.
Spec for compare i18next libraries. Loads every library in "dev" and "en" languages. After it, checks if the file keys (both files are json at the end) are equals. It uses AsyncSpec libraries for asyncronous specs with Jasmine.
files = [
'a.json',
'b.json',
'c.json'
]
last = 'c.json'
loadFileDev = (name, holder, callback) ->
$.get("locales/dev/#{name}", (data) =>
holder[name] = data
callback() if callback?
, 'json')
loadFileLocale = (name, holder, lang, callback) ->
$.get("locales/#{lang}/#{name}", (data) =>
holder[name] = data
callback() if callback?
, 'json')
compareObject = (comparer, compared, comparedName) ->
for key,value of comparer
if typeof value != 'string'
compareObject(comparer[key], compared[key], "#{comparedName}/#{key}")
else if typeof compared[key] == 'undefined'
expect("Does not exists \"#{key}\" in compared file #{comparedName}").toBe ''
return
compare = (comparer, compared, lang, done) ->
for fileKey,file of comparer
compareObject(comparer[fileKey], compared[fileKey], "#{lang}/#{fileKey}")
describe 'File compare', ->
async = new AsyncSpec @
async.beforeEach (done)->
if (!@dev)
@dev = []
for file in files
if file != last
loadFileDev(file, @dev, null)
else
loadFileDev(file, @dev, () -> done() )
else
done()
async.it 'Load en', (done) =>
en = []
for file in files
if file != last
loadFileLocale(file, en, 'en', null)
else
loadFileLocale(file, en, 'en', () ->
compare(@dev, en, 'en')
compare(en, @dev, 'dev')
done()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment