spec/i18n_tasks_spec.rb in i18n-tasks-0.7.13 vs spec/i18n_tasks_spec.rb in i18n-tasks-0.8.0
- old
+ new
@@ -1,18 +1,40 @@
# coding: utf-8
require 'spec_helper'
require 'fileutils'
+require 'open3'
+# Integration tests
describe 'i18n-tasks' do
- delegate :run_cmd, :i18n_task, :in_test_app_dir, :i18n_cmd, to: :TestCodebase
+ delegate :run_cmd, :run_cmd_capture_stderr, :i18n_task, :in_test_app_dir, to: :TestCodebase
+ describe 'bin/i18n-tasks' do
+ it 'shows help when invoked with no arguments, shows version on --version' do
+ # These bin/i18n-tasks tests are executed in parallel for performance
+ [
+ proc {
+ out, err, status = Open3.capture3('bin/i18n-tasks')
+ expect(status).to be_success
+ expect(out).to be_empty
+ expect(err).to start_with('Usage: i18n-tasks [command] [options]')
+ expect(err).to include('Available commands', 'add-missing')
+ },
+ proc {
+ expect(%x[bin/i18n-tasks --version].chomp).to eq(I18n::Tasks::VERSION)
+ }
+ ].map { |test| Thread.start(&test) }.each(&:join)
+ end
+ end
+
+ # Tests execute i18n-tasks using I18n::Tasks::CLI directly, via #run_cmd(task, *arguments).
+ # This avoid launching a process for each command.
+
describe 'health' do
it 'outputs stats' do
t = i18n_task
- stats = in_test_app_dir { t.forest_stats(t.data_forest t.locales) }
- out = in_test_app_dir { capture_stderr { capture_stdout { i18n_cmd.run(:health) } } }
- stats.values.each do |v|
+ out = run_cmd_capture_stderr('health')
+ in_test_app_dir { t.forest_stats(t.data_forest t.locales) }.values.each do |v|
expect(out).to include(v.to_s)
end
end
end
@@ -36,20 +58,20 @@
en.events.show.success
)
}
it 'detects missing' do
es_keys = expected_missing_keys.grep(/^es\./)
- expect(run_cmd :missing).to be_i18n_keys expected_missing_keys
+ expect(run_cmd 'missing').to be_i18n_keys expected_missing_keys
# 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
+ expect(run_cmd 'missing', '-les').to be_i18n_keys es_keys
+ expect(run_cmd 'missing', 'es').to be_i18n_keys es_keys
end
end
describe 'eq_base' do
- it 'detects eq_base' do
- expect(run_cmd :eq_base).to be_i18n_keys %w(es.same_in_es.a)
+ it 'detects eq-base' do
+ expect(run_cmd 'eq-base').to be_i18n_keys %w(es.same_in_es.a)
end
end
let(:expected_unused_keys) do
%w(unused.a unused.numeric unused.plural).map do |k|
@@ -63,15 +85,15 @@
end.reduce(:+)
end
describe 'unused' do
it 'detects unused' do
- expect(run_cmd :unused).to be_i18n_keys expected_unused_keys
+ expect(run_cmd 'unused').to be_i18n_keys expected_unused_keys
end
it 'detects unused (--strict)' do
- expect(run_cmd :unused, strict: true).to be_i18n_keys expected_unused_keys_strict
+ expect(run_cmd 'unused', '--strict').to be_i18n_keys expected_unused_keys_strict
end
end
describe 'remove_unused' do
it 'removes unused' do
@@ -81,11 +103,11 @@
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'
- run_cmd :remove_unused
+ run_cmd 'remove-unused'
t.data.reload
unused.each do |key|
expect(t.key_value?(key, :en)).to be false
expect(t.key_value?(key, :es)).to be false
end
@@ -94,11 +116,11 @@
end
describe 'normalize' do
it 'sorts the keys' do
in_test_app_dir do
- run_cmd :normalize
+ run_cmd 'normalize'
en_yml_data = i18n_task.data.reload['en'].select_keys { |_k, node|
node.data[:path] == 'config/locales/en.yml'
}
expect(en_yml_data).to be_present
en_yml_data.nodes { |nodes|
@@ -110,20 +132,20 @@
end
it 'moves keys to the corresponding files as per data.write' do
in_test_app_dir {
expect(File).to_not exist 'config/locales/devise.en.yml'
- run_cmd :normalize, pattern_router: true
+ run_cmd 'normalize', '--pattern_router'
expect(YAML.load_file('config/locales/devise.en.yml')['en']['devise']['a']).to eq 'EN_TEXT'
}
end
end
describe 'xlsx_report' do
it 'saves' do
in_test_app_dir {
- run_cmd :xlsx_report
+ run_cmd 'xlsx-report'
expect(File).to exist 'tmp/i18n-report.xlsx'
FileUtils.cp('tmp/i18n-report.xlsx', '..')
}
end
@@ -132,34 +154,34 @@
describe 'add_missing' do
it 'default placeholder: key.humanize for base_locale' do
in_test_app_dir {
expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']).to be_nil
}
- run_cmd :add_missing, locales: 'base'
+ run_cmd 'add-missing', 'base'
in_test_app_dir {
expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['key']).to eq I18n.t('i18n_tasks.common.key')
expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'ES_TEXT'
}
end
it 'default value: base_value for non-base locale' 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: 'es'
+ run_cmd 'add-missing', 'es'
in_test_app_dir {
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'EN_TEXT'
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es_plural_1']['a']['one']).to eq 'EN_TEXT'
}
end
it '--value' do
in_test_app_dir {
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']).to be_nil
}
- run_cmd :normalize, pattern_router: true
- run_cmd :add_missing, locales: 'all', value: 'TRME'
+ run_cmd 'normalize', '--pattern_router'
+ run_cmd 'add-missing', '-v', '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'
}
@@ -167,36 +189,35 @@
it '--value with %{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', value: 'TRME %{value}'
+ run_cmd 'add-missing', '-v', 'TRME %{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
it 'prints config' do
- expect(YAML.load(Term::ANSIColor.uncolor(run_cmd :config))).to(
+ expect(YAML.load(Term::ANSIColor.uncolor(run_cmd 'config'))).to(
eq(in_test_app_dir { i18n_task.config_for_inspect })
)
end
end
describe 'find' do
it 'prints usages' do
- result = Term::ANSIColor.uncolor(run_cmd :find, arguments: ['used.*'])
+ result = Term::ANSIColor.uncolor(run_cmd 'find', 'used.*')
expect(result).to eq(<<-TXT)
used.a 2
app/views/usages.html.slim:1 p = t 'used.a'
app/views/usages.html.slim:2 b = t 'used.a'
TXT
end
end
-
# --- setup ---
BENCH_KEYS = ENV['BENCH_KEYS'].to_i
before(:each) do
gen_data = ->(v) {