5
5
it 'registers an offense and corrects a symbol' do
6
6
expect_offense ( <<~RUBY )
7
7
res = read_attribute(:test)
8
- ^^^^^^^^^^^^^^ Prefer `self[:attr]` over `read_attribute(:attr) `.
8
+ ^^^^^^^^^^^^^^^^^^^^^ Prefer `self[:test] `.
9
9
RUBY
10
10
11
11
expect_correction ( <<~RUBY )
16
16
it 'register an offense and corrects a string' do
17
17
expect_offense ( <<~RUBY )
18
18
res = read_attribute('test')
19
- ^^^^^^^^^^^^^^ Prefer `self[:attr]` over `read_attribute(:attr) `.
19
+ ^^^^^^^^^^^^^^^^^^^^^^ Prefer `self['test'] `.
20
20
RUBY
21
21
22
22
expect_correction ( <<~RUBY )
@@ -36,7 +36,7 @@ def foo
36
36
expect_offense ( <<~RUBY )
37
37
def foo
38
38
bar || read_attribute(:baz)
39
- ^^^^^^^^^^^^^^ Prefer `self[:attr]` over `read_attribute(:attr) `.
39
+ ^^^^^^^^^^^^^^^^^^^^ Prefer `self[:baz] `.
40
40
end
41
41
RUBY
42
42
@@ -50,7 +50,7 @@ def foo
50
50
it 'autocorrects without parentheses' do
51
51
expect_offense ( <<~RUBY )
52
52
res = read_attribute 'test'
53
- ^^^^^^^^^^^^^^ Prefer `self[:attr]` over `read_attribute(:attr) `.
53
+ ^^^^^^^^^^^^^^^^^^^^^ Prefer `self['test'] `.
54
54
RUBY
55
55
56
56
expect_correction ( <<~RUBY )
@@ -61,7 +61,7 @@ def foo
61
61
it 'corrects an expression' do
62
62
expect_offense ( <<~RUBY )
63
63
res = read_attribute('test_' + postfix)
64
- ^^^^^^^^^^^^^^ Prefer `self[:attr]` over `read_attribute(:attr) `.
64
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `self['test_' + postfix] `.
65
65
RUBY
66
66
67
67
expect_correction ( <<~RUBY )
@@ -72,7 +72,7 @@ def foo
72
72
it 'corrects multiline' do
73
73
expect_offense ( <<~RUBY )
74
74
res = read_attribute(
75
- ^^^^^^^^^^^^^^ Prefer `self[:attr]` over `read_attribute(:attr) `.
75
+ ^^^^^^^^^^^^^^^ Prefer `self[:attr]`.
76
76
(
77
77
'test_' + postfix
78
78
).to_sym
@@ -96,7 +96,7 @@ def foo
96
96
it 'registers an offense and corrects' do
97
97
expect_offense ( <<~RUBY )
98
98
write_attribute(:test, val)
99
- ^^^^^^^^^^^^^^^ Prefer `self[:attr ] = val` over `write_attribute(:attr, val) `.
99
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `self[:test ] = val`.
100
100
RUBY
101
101
102
102
expect_correction ( <<~RUBY )
@@ -109,7 +109,7 @@ def foo
109
109
it 'registers an offense and corrects' do
110
110
expect_offense ( <<~RUBY )
111
111
write_attribute('attr', 'test')
112
- ^^^^^^^^^^^^^^^ Prefer `self[: attr] = val` over `write_attribute(:attr, val) `.
112
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `self[' attr' ] = 'test' `.
113
113
RUBY
114
114
115
115
expect_correction ( <<~RUBY )
@@ -121,7 +121,7 @@ def foo
121
121
it 'registers an offense and corrects without parentheses' do
122
122
expect_offense ( <<~RUBY )
123
123
write_attribute 'attr', 'test'
124
- ^^^^^^^^^^^^^^^ Prefer `self[: attr] = val` over `write_attribute(:attr, val) `.
124
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `self[' attr' ] = 'test' `.
125
125
RUBY
126
126
127
127
expect_correction ( <<~RUBY )
@@ -141,7 +141,7 @@ def foo=(value)
141
141
expect_offense ( <<~RUBY )
142
142
def foo=(value)
143
143
bar(value) || write_attribute(:baz, "baz")
144
- ^^^^^^^^^^^^^^^ Prefer `self[:attr ] = val` over `write_attribute(:attr, val) `.
144
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `self[:baz ] = "baz" `.
145
145
end
146
146
RUBY
147
147
@@ -155,7 +155,7 @@ def foo=(value)
155
155
it 'corrects assignment with chained methods' do
156
156
expect_offense ( <<~RUBY )
157
157
write_attribute(:attr, 'test_' + postfix)
158
- ^^^^^^^^^^^^^^^ Prefer `self[:attr] = val` over `write_attribute(:attr, val) `.
158
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `self[:attr] = 'test_' + postfix `.
159
159
RUBY
160
160
161
161
expect_correction ( <<~RUBY )
@@ -166,7 +166,7 @@ def foo=(value)
166
166
it 'autocorrects multiline' do
167
167
expect_offense ( <<~RUBY )
168
168
write_attribute(
169
- ^^^^^^^^^^^^^^^ Prefer `self[:attr] = val` over `write_attribute(:attr, val) `.
169
+ ^^^^^^^^^^^^^^^^ Prefer `self[:attr] = val`.
170
170
:attr,
171
171
(
172
172
'test_' + postfix
0 commit comments