blob: cacf0a1b67d055c4bd6a772a634c0b7220fc176c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../rubocop/cop/ruby_interpolation_in_translation'
# Disabling interpolation check as we deliberately want to have #{} in strings.
# rubocop:disable Lint/InterpolationCheck
RSpec.describe RuboCop::Cop::RubyInterpolationInTranslation do
let(:msg) { "Don't use ruby interpolation \#{} inside translated strings, instead use %{}" }
subject(:cop) { described_class.new }
it 'does not add an offense for a regular messages' do
expect_no_offenses('_("Hello world")')
end
it 'adds the correct offense when using interpolation in a string' do
expect_offense(<<~CODE)
_("Hello \#{world}")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
end
it 'detects when using a ruby interpolation in the first argument of a pluralized string' do
expect_offense(<<~CODE)
n_("Hello \#{world}", "Hello world")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
end
it 'detects when using a ruby interpolation in the second argument of a pluralized string' do
expect_offense(<<~CODE)
n_("Hello world", "Hello \#{world}")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
end
it 'detects when using interpolation in a namespaced translation' do
expect_offense(<<~CODE)
s_("Hello|\#{world}")
^^^^^ #{msg}
^^^^^^^^ #{msg}
CODE
end
end
# rubocop:enable Lint/InterpolationCheck
|