Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tasks/gettext_rake_spec.rb')
-rw-r--r--spec/tasks/gettext_rake_spec.rb90
1 files changed, 27 insertions, 63 deletions
diff --git a/spec/tasks/gettext_rake_spec.rb b/spec/tasks/gettext_rake_spec.rb
index 29caa363f7b..c44c1734432 100644
--- a/spec/tasks/gettext_rake_spec.rb
+++ b/spec/tasks/gettext_rake_spec.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true
require 'rake_helper'
+require_relative '../../tooling/lib/tooling/gettext_extractor'
+require_relative '../support/matchers/abort_matcher'
-RSpec.describe 'gettext', :silence_stdout do
+RSpec.describe 'gettext', :silence_stdout, feature_category: :internationalization do
let(:locale_path) { Rails.root.join('tmp/gettext_spec') }
let(:pot_file_path) { File.join(locale_path, 'gitlab.pot') }
@@ -21,28 +23,43 @@ RSpec.describe 'gettext', :silence_stdout do
end
describe ':compile' do
- before do
- allow(Rake::Task).to receive(:[]).and_call_original
+ let(:compile_command) do
+ [
+ "node", "./scripts/frontend/po_to_json.js",
+ "--locale-root", Rails.root.join('locale').to_s,
+ "--output-dir", Rails.root.join('app/assets/javascripts/locale').to_s
+ ]
end
- it 'creates a pot file and invokes the \'gettext:po_to_json\' task' do
- expect(Rake::Task).to receive(:[]).with('gettext:po_to_json').and_return(double(invoke: true))
+ it 'creates a pot file and runs po-to-json conversion via node script' do
+ expect(Kernel).to receive(:system).with(*compile_command).and_return(true)
expect { run_rake_task('gettext:compile') }
.to change { File.exist?(pot_file_path) }
.to be_truthy
end
+
+ it 'aborts with non-successful po-to-json conversion via node script' do
+ expect(Kernel).to receive(:system).with(*compile_command).and_return(false)
+
+ expect { run_rake_task('gettext:compile') }.to abort_execution
+ end
end
describe ':regenerate' do
+ let(:locale_nz_path) { File.join(locale_path, 'en_NZ') }
+ let(:po_file_path) { File.join(locale_nz_path, 'gitlab.po') }
+ let(:extractor) { instance_double(Tooling::GettextExtractor, generate_pot: '') }
+
before do
+ FileUtils.mkdir(locale_nz_path)
+ File.write(po_file_path, fixture_file('valid.po'))
+
# this task takes a *really* long time to complete, so stub it for the spec
- allow(Rake::Task['gettext:find']).to receive(:invoke) { invoke_find.call }
+ allow(Tooling::GettextExtractor).to receive(:new).and_return(extractor)
end
context 'when the locale folder is not found' do
- let(:invoke_find) { -> { true } }
-
before do
FileUtils.rm_r(locale_path) if Dir.exist?(locale_path)
end
@@ -53,67 +70,14 @@ RSpec.describe 'gettext', :silence_stdout do
end
end
- context 'where there are existing /**/gitlab.po files' do
- let(:locale_nz_path) { File.join(locale_path, 'en_NZ') }
- let(:po_file_path) { File.join(locale_nz_path, 'gitlab.po') }
-
- let(:invoke_find) { -> { File.write pot_file_path, 'pot file test updates' } }
-
- before do
- FileUtils.mkdir(locale_nz_path)
- File.write(po_file_path, fixture_file('valid.po'))
- end
-
- it 'does not remove that locale' do
- expect { run_rake_task('gettext:regenerate') }
- .not_to change { Dir.exist?(locale_nz_path) }
- end
- end
-
- context 'when there are locale folders without a gitlab.po file' do
- let(:empty_locale_path) { File.join(locale_path, 'en_NZ') }
-
- let(:invoke_find) { -> { File.write pot_file_path, 'pot file test updates' } }
-
- before do
- FileUtils.mkdir(empty_locale_path)
- end
-
- it 'removes those folders' do
- expect { run_rake_task('gettext:regenerate') }
- .to change { Dir.exist?(empty_locale_path) }
- .to eq false
- end
- end
-
context 'when the gitlab.pot file cannot be generated' do
- let(:invoke_find) { -> { true } }
-
it 'prints an error' do
+ allow(File).to receive(:exist?).and_return(false)
+
expect { run_rake_task('gettext:regenerate') }
.to raise_error(/gitlab.pot file not generated/)
end
end
-
- context 'when gettext:find changes the revision dates' do
- let(:invoke_find) { -> { File.write pot_file_path, fixture_file('valid.po') } }
-
- before do
- File.write pot_file_path, fixture_file('valid.po')
- end
-
- it 'resets the changes' do
- pot_file = File.read(pot_file_path)
- expect(pot_file).to include('PO-Revision-Date: 2017-07-13 12:10-0500')
- expect(pot_file).to include('PO-Creation-Date: 2016-07-13 12:11-0500')
-
- run_rake_task('gettext:regenerate')
-
- pot_file = File.read(pot_file_path)
- expect(pot_file).not_to include('PO-Revision-Date: 2017-07-13 12:10-0500')
- expect(pot_file).not_to include('PO-Creation-Date: 2016-07-13 12:11-0500')
- end
- end
end
describe ':lint' do