test/wwwjdic/locales/test_locales.rb in wwwjdic-15.0.0 vs test/wwwjdic/locales/test_locales.rb in wwwjdic-16.0.0
- old
+ new
@@ -1,8 +1,12 @@
+# frozen_string_literal: true
+
#--
# wwwjdic
+# rubocop:disable Style/AsciiComments
# © 2014 Marco Bresciani
+# rubocop:enable Style/AsciiComments
#
# This file is part of wwwjdic.
#
# wwwjdic is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
@@ -22,47 +26,59 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#++
require_relative '../../test_helper'
-RELATIVE_PATH = './'.freeze
+RELATIVE_PATH = './'
+def test_one_locale
+ it 'shall return at least one available locale' do
+ _(subject).wont_be_nil
+ _(subject).wont_be_empty
+ end
+end
+
+def test_en_it
+ it 'shall contain at least English and Italiano' do
+ _(subject).must_include :en
+ _(subject).must_include :it
+ end
+end
+
+def test_translation(locale, translation)
+ a_string = I18n.t('test.test')
+ _(a_string).wont_be_nil
+ _(a_string).wont_be_empty
+ _(a_string).wont_include 'translation missing'
+ _(a_string).must_equal translation[locale.to_s]['test']['test']
+end
+
describe WWWJDic::WWWJDic do
describe 'when using I18N' do
before do
I18n.load_path = Dir[File.join(File.dirname(__FILE__), RELATIVE_PATH, '*.yml')]
end
subject { I18n.available_locales }
- it 'shall return at least one available locale' do
- _(subject).wont_be_nil
- _(subject).wont_be_empty
- end
+ test_one_locale
- it 'shall contain at least English and Italiano' do
- _(subject).must_include :en
- _(subject).must_include :it
+ test_en_it
+
+ def load_yaml_file(locale)
+ filename = File.join(File.dirname(__FILE__), RELATIVE_PATH, "#{locale}.yml")
+ filename = File.expand_path filename
+ YAML.safe_load(File.open(filename.to_s))
end
it 'shall contain a test.test signpost for each available locale' do
- def load_yaml_file(locale)
- filename = File.join(File.dirname(__FILE__), RELATIVE_PATH, "#{locale}.yml")
- filename = File.expand_path filename
- YAML.safe_load(File.open(filename.to_s))
- end
-
subject.each do |locale|
I18n.locale = locale
translation = load_yaml_file(locale)
_(translation[locale.to_s]['test']['test']).wont_be_nil
- a_string = I18n.t('test.test')
- _(a_string).wont_be_nil
- _(a_string).wont_be_empty
- _(a_string).wont_include 'translation missing'
- _(a_string).must_equal translation[locale.to_s]['test']['test']
+ test_translation(locale, translation)
end
end
end
end