spec/i18n_tasks_spec.rb in i18n-tasks-0.5.4 vs spec/i18n_tasks_spec.rb in i18n-tasks-0.6.0

- old
+ new

@@ -7,29 +7,38 @@ delegate :run_cmd, :i18n_task, :in_test_app_dir, to: :TestCodebase describe 'missing' do let (:expected_missing_keys) { %w( en.used_but_missing.key en.relative.index.missing - es.missing_in_es.a es.same_in_es.a + es.missing_in_es.a + en.present_in_es_but_not_en.a en.hash.pattern_missing.a en.hash.pattern_missing.b en.missing_symbol_key en.missing_symbol.key_two en.missing_symbol.key_three es.missing_in_es_plural_1.a es.missing_in_es_plural_2.a en.missing-key-with-a-dash.key - en.fn_comment + en.fn_comment en.only_in_es ) } - it 'detects missing or identical' do + it 'detects missing' do capture_stderr do expect(run_cmd :missing).to be_i18n_keys expected_missing_keys es_keys = expected_missing_keys.grep(/^es\./) # locale argument expect(run_cmd :missing, locales: %w(es)).to be_i18n_keys es_keys expect(run_cmd :missing, arguments: %w(es)).to be_i18n_keys es_keys end end end + describe 'eq_base' do + it 'detects eq_base' do + capture_stderr do + expect(run_cmd :eq_base).to be_i18n_keys %w(es.same_in_es.a) + end + end + end + let(:expected_unused_keys) { %w(unused.a unused.numeric unused.plural).map { |k| %w(en es).map { |l| "#{l}.#{k}" } }.reduce(:+) } describe 'unused' do it 'detects unused' do capture_stderr do expect(run_cmd :unused).to be_i18n_keys expected_unused_keys @@ -39,11 +48,11 @@ describe 'remove_unused' do it 'removes unused' do in_test_app_dir do t = i18n_task - unused = expected_unused_keys.map { |k| k.split('.', 2)[1] } + unused = expected_unused_keys.map { |k| SplitKey.split_key(k, 2)[1] } unused.each do |key| expect(t.key_value?(key, :en)).to be true expect(t.key_value?(key, :es)).to be true end ENV['CONFIRM'] = '1' @@ -86,10 +95,11 @@ expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']).to be_nil } run_cmd :add_missing, locales: 'base' in_test_app_dir { expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['key']).to eq 'Key' + expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'A' } end it 'default placeholder: base_value for non-base locale' do in_test_app_dir { @@ -109,20 +119,22 @@ run_cmd :normalize, pattern_router: true run_cmd :add_missing, locales: 'all', placeholder: 'TRME' in_test_app_dir { expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'TRME' expect(YAML.load_file('config/locales/devise.es.yml')['es']['devise']['a']).to eq 'ES_TEXT' + expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'TRME' } end it 'placeholder: value with base_value' do in_test_app_dir { expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']).to be_nil } run_cmd :add_missing, locales: 'all', placeholder: 'TRME %{base_value}' in_test_app_dir { expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'TRME EN_TEXT' + expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'TRME ES_TEXT' } end end describe 'config' do @@ -146,11 +158,11 @@ end end # --- setup --- - BENCH_KEYS = 100 + BENCH_KEYS = 10 before(:each) do gen_data = ->(v) { v_num = v.chars.map(&:ord).join('').to_i { 'ca' => {'a' => v, 'b' => v, 'c' => v, 'd' => v, 'e' => "#{v}%{i}", 'f' => "#{v}%{i}"}, @@ -192,9 +204,11 @@ 'missing_in_es', 'missing_in_es_plural_1', 'missing_in_es_plural_2') es_data['same_in_es']['a'] = 'EN_TEXT' es_data['blank_in_es']['a'] = '' es_data['ignore_eq_base_all']['a'] = 'EN_TEXT' es_data['ignore_eq_base_es']['a'] = 'EN_TEXT' + es_data['only_in_es'] = 1 + es_data['present_in_es_but_not_en'] = {'a' => 'ES_TEXT'} fs = fixtures_contents.merge( 'config/locales/en.yml' => {'en' => en_data}.to_yaml, 'config/locales/es.yml' => {'es' => es_data}.to_yaml, # test that our algorithms can scale to the order of {BENCH_KEYS} keys.