-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
variable_definition_spec.rb
59 lines (50 loc) · 1.57 KB
/
variable_definition_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::VariableDefinition, :config do
context 'when EnforcedStyle is `symbols`' do
let(:cop_config) { { 'EnforcedStyle' => 'symbols' } }
it 'registers an offense for string name' do
expect_offense(<<~RUBY)
let("user_name") { 'Adam' }
^^^^^^^^^^^ Use symbols for variable names.
RUBY
end
it 'registers an offense for interpolated string' do
expect_offense(<<~'RUBY')
let("user-#{id}") { 'Adam' }
^^^^^^^^^^^^ Use symbols for variable names.
RUBY
end
it 'registers an offense for multiline string' do
expect_offense(<<~'RUBY')
let("user"\
^^^^^^^ Use symbols for variable names.
"-foo") { 'Adam' }
RUBY
end
it 'does not register offense for symbol names' do
expect_no_offenses(<<~RUBY)
let(:user_name) { 'Adam' }
RUBY
end
end
context 'when EnforcedStyle is `strings`' do
let(:cop_config) { { 'EnforcedStyle' => 'strings' } }
it 'registers an offense for symbol name' do
expect_offense(<<~RUBY)
let(:user_name) { 'Adam' }
^^^^^^^^^^ Use strings for variable names.
RUBY
end
it 'registers an offense for interpolated symbol' do
expect_offense(<<~'RUBY')
let(:"user-#{id}") { 'Adam' }
^^^^^^^^^^^^^ Use strings for variable names.
RUBY
end
it 'does not register offense for string names' do
expect_no_offenses(<<~RUBY)
let("user_name") { 'Adam' }
RUBY
end
end
end