spec/i18n_tasks_spec.rb in i18n-tasks-0.3.5 vs spec/i18n_tasks_spec.rb in i18n-tasks-0.3.6
- old
+ new
@@ -2,15 +2,11 @@
require 'spec_helper'
require 'i18n/tasks/commands'
require 'fileutils'
describe 'i18n-tasks' do
- def run_cmd(name, *args, &block)
- TestCodebase.in_test_app_dir do
- capture_stdout { ::I18n::Tasks::Commands.new.send(name, *args, &block) }
- end
- end
+ delegate :run_cmd, :i18n_task, :in_test_app_dir, to: :TestCodebase
describe 'missing' do
let (:expected_missing_keys) {
%w( en.used_but_missing.a en.relative.index.missing
es.missing_in_es.a es.blank_in_es.a es.same_in_es.a
@@ -37,12 +33,12 @@
end
end
describe 'remove_unused' do
it 'removes unused' do
- TestCodebase.in_test_app_dir do
- t = I18n::Tasks::BaseTask.new
+ in_test_app_dir do
+ t = i18n_task
expected_unused_keys.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'
@@ -58,57 +54,57 @@
end
end
describe 'normalize' do
it 'moves keys to the corresponding files as per data.write' do
- TestCodebase.in_test_app_dir {
+ in_test_app_dir {
expect(File).to_not exist 'config/locales/devise.en.yml'
run_cmd :normalize
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
- TestCodebase.in_test_app_dir {
+ in_test_app_dir {
capture_stderr { run_cmd :xlsx_report }
expect(File).to exist 'tmp/i18n-report.xlsx'
FileUtils.cp('tmp/i18n-report.xlsx', '..')
}
end
end
describe 'add_missing' do
it 'default placeholder' do
- TestCodebase.in_test_app_dir {
+ 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'
- TestCodebase.in_test_app_dir {
+ in_test_app_dir {
expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['a']).to eq 'A'
}
end
it 'placeholder: value' do
- TestCodebase.in_test_app_dir {
+ 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'
- TestCodebase.in_test_app_dir {
+ in_test_app_dir {
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'TRME'
# does not touch existing, but moves to the right file:
expect(YAML.load_file('config/locales/devise.es.yml')['es']['devise']['a']).to eq 'ES_TEXT'
}
end
end
describe 'config' do
it 'prints config' do
expect(YAML.load(run_cmd :config)).to(
- eq TestCodebase.in_test_app_dir { I18n::Tasks::BaseTask.new.config_for_inspect }
+ eq(in_test_app_dir { i18n_task.config_for_inspect })
)
end
end
describe 'find' do
@@ -124,10 +120,10 @@
end
# --- setup ---
BENCH_KEYS = 100
- before do
+ 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}"},
'cb' => {'a' => v, 'b' => "#{v}%{i}"},