debian-mirror-gitlab/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_spec_helper'
2018-11-20 20:47:30 +05:30
require_relative '../../../rubocop/cop/ruby_interpolation_in_translation'
# Disabling interpolation check as we deliberately want to have #{} in strings.
# rubocop:disable Lint/InterpolationCheck
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::RubyInterpolationInTranslation do
2021-03-11 19:13:27 +05:30
let(:msg) { "Don't use ruby interpolation \#{} inside translated strings, instead use %{}" }
2018-11-20 20:47:30 +05:30
2021-03-11 19:13:27 +05:30
it 'does not add an offense for a regular messages' do
expect_no_offenses('_("Hello world")')
2018-11-20 20:47:30 +05:30
end
2021-03-11 19:13:27 +05:30
it 'adds the correct offense when using interpolation in a string' do
expect_offense(<<~CODE)
_("Hello \#{world}")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
2018-11-20 20:47:30 +05:30
end
it 'detects when using a ruby interpolation in the first argument of a pluralized string' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
n_("Hello \#{world}", "Hello world")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
2018-11-20 20:47:30 +05:30
end
it 'detects when using a ruby interpolation in the second argument of a pluralized string' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
n_("Hello world", "Hello \#{world}")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
2018-11-20 20:47:30 +05:30
end
it 'detects when using interpolation in a namespaced translation' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
s_("Hello|\#{world}")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
2018-11-20 20:47:30 +05:30
end
end
# rubocop:enable Lint/InterpolationCheck