forked from rubocop/rubocop-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_separated_keys_spec.rb
71 lines (63 loc) · 2.51 KB
/
dot_separated_keys_spec.rb
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Rails::DotSeparatedKeys, :config do
it 'registers an offense and corrects when translating keys with convertible scopes' do
expect_offense(<<~RUBY)
I18n.t :key, scope: [:one, :two]
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
I18n.translate :key, scope: [:one, :two]
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
t :key, scope: [:one, :two]
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
translate :key, scope: [:one, :two]
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
t :key, scope: [:one, :two], default: 'Not here'
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
I18n.t :key, scope: ['one', :two]
^^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
I18n.t 'key', scope: [:one, :two]
^^^^^^^^^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
I18n.t :key, scope: :one
^^^^^^^^^^^ Use the dot-separated keys instead of specifying the `:scope` option.
RUBY
expect_correction(<<~RUBY)
I18n.t 'one.two.key'
I18n.translate 'one.two.key'
t 'one.two.key'
translate 'one.two.key'
t 'one.two.key', default: 'Not here'
I18n.t 'one.two.key'
I18n.t 'one.two.key'
I18n.t 'one.key'
RUBY
end
it 'does not register an offense when key is an array' do
expect_no_offenses(<<~RUBY)
t [:key1, :key2], scope: :one
RUBY
end
it 'does not register an offense when key is not a basic literal' do
expect_no_offenses(<<~RUBY)
t key1, scope: :one
RUBY
end
it 'does not register an offense when `scope` is an array containing non literals' do
expect_no_offenses(<<~RUBY)
t :key, scope: [:one, two]
RUBY
end
it 'does not register an offense when `scope` is a string' do
expect_no_offenses(<<~RUBY)
t :key, scope: 'one'
RUBY
end
it 'does not register an offense when `scope` is not a literal' do
expect_no_offenses(<<~RUBY)
t :key, scope: something
RUBY
end
it 'does not register an offense when there is no `scope`' do
expect_no_offenses(<<~RUBY)
t :key
RUBY
end
end