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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/rubocop/cop/static_translation_definition_spec.rb
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/rubocop/cop/static_translation_definition_spec.rb')
-rw-r--r--spec/rubocop/cop/static_translation_definition_spec.rb98
1 files changed, 48 insertions, 50 deletions
diff --git a/spec/rubocop/cop/static_translation_definition_spec.rb b/spec/rubocop/cop/static_translation_definition_spec.rb
index 8a38a318999..8656b07a6e4 100644
--- a/spec/rubocop/cop/static_translation_definition_spec.rb
+++ b/spec/rubocop/cop/static_translation_definition_spec.rb
@@ -8,78 +8,76 @@ require 'rspec-parameterized'
require_relative '../../../rubocop/cop/static_translation_definition'
RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
- include CopHelper
-
using RSpec::Parameterized::TableSyntax
+ let(:msg) do
+ "The text you're translating will be already in the translated form when it's assigned to the constant. " \
+ "When a users changes the locale, these texts won't be translated again. " \
+ "Consider moving the translation logic to a method."
+ end
+
subject(:cop) { described_class.new }
- shared_examples 'offense' do |code, highlight, line|
+ shared_examples 'offense' do |code|
it 'registers an offense' do
- inspect_source(code)
-
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([line])
- expect(cop.highlights).to eq([highlight])
+ expect_offense(code)
end
end
shared_examples 'no offense' do |code|
it 'does not register an offense' do
- inspect_source(code)
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses(code)
end
end
describe 'offenses' do
- where(:code, :highlight, :line) do
+ where(:code) do
[
- ['A = _("a")', '_("a")', 1],
- ['B = s_("b")', 's_("b")', 1],
- ['C = n_("c")', 'n_("c")', 1],
- [
- <<~CODE,
- class MyClass
- def self.translations
- @cache ||= { hello: _("hello") }
- end
+ <<~CODE,
+ A = _("a")
+ ^^^^^^ #{msg}
+ CODE
+ <<~CODE,
+ B = s_("b")
+ ^^^^^^^ #{msg}
+ CODE
+ <<~CODE,
+ C = n_("c")
+ ^^^^^^^ #{msg}
+ CODE
+ <<~CODE,
+ class MyClass
+ def self.translations
+ @cache ||= { hello: _("hello") }
+ ^^^^^^^^^^ #{msg}
end
- CODE
- '_("hello")',
- 3
- ],
- [
- <<~CODE,
- module MyModule
- A = {
- b: {
- c: _("a")
- }
+ end
+ CODE
+ <<~CODE,
+ module MyModule
+ A = {
+ b: {
+ c: _("a")
+ ^^^^^^ #{msg}
}
- end
- CODE
- '_("a")',
- 4
- ],
- [
- <<~CODE,
- class MyClass
- B = [
- [
- s_("a")
- ]
+ }
+ end
+ CODE
+ <<~CODE
+ class MyClass
+ B = [
+ [
+ s_("a")
+ ^^^^^^^ #{msg}
]
- end
- CODE
- 's_("a")',
- 4
- ]
+ ]
+ end
+ CODE
]
end
with_them do
- include_examples 'offense', params[:code], params[:highlight], params[:line]
+ include_examples 'offense', params[:code]
end
end