reek 4.4.0 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/CONTRIBUTING.md +41 -4
  4. data/README.md +15 -3
  5. data/defaults.reek +1 -1
  6. data/docs/Basic-Smell-Options.md +2 -2
  7. data/docs/Code-Smells.md +4 -0
  8. data/docs/How-To-Write-New-Detectors.md +116 -0
  9. data/docs/How-reek-works-internally.md +3 -4
  10. data/docs/Instance-Variable-Assumption.md +134 -0
  11. data/docs/Simulated-Polymorphism.md +1 -1
  12. data/docs/Smell-Suppression.md +6 -6
  13. data/docs/{style-guide.md → Style-Guide.md} +0 -0
  14. data/docs/Unused-Private-Method.md +1 -1
  15. data/docs/YAML-Reports.md +0 -18
  16. data/features/configuration_files/directory_specific_directives.feature +4 -4
  17. data/features/configuration_files/unused_private_method.feature +2 -2
  18. data/features/samples.feature +122 -117
  19. data/features/smells/subclassed_from_core_class.feature +1 -1
  20. data/lib/reek/code_comment.rb +13 -4
  21. data/lib/reek/context/code_context.rb +1 -0
  22. data/lib/reek/examiner.rb +24 -27
  23. data/lib/reek/smells/class_variable.rb +1 -1
  24. data/lib/reek/smells/control_parameter.rb +1 -1
  25. data/lib/reek/smells/data_clump.rb +1 -1
  26. data/lib/reek/smells/duplicate_method_call.rb +1 -1
  27. data/lib/reek/smells/feature_envy.rb +1 -1
  28. data/lib/reek/smells/instance_variable_assumption.rb +1 -1
  29. data/lib/reek/smells/prima_donna_method.rb +1 -1
  30. data/lib/reek/smells/repeated_conditional.rb +1 -1
  31. data/lib/reek/smells/smell_detector.rb +5 -14
  32. data/lib/reek/smells/smell_repository.rb +1 -5
  33. data/lib/reek/smells/smell_warning.rb +6 -8
  34. data/lib/reek/smells/subclassed_from_core_class.rb +1 -1
  35. data/lib/reek/smells/uncommunicative_variable_name.rb +22 -12
  36. data/lib/reek/smells/unused_private_method.rb +1 -1
  37. data/lib/reek/spec.rb +2 -2
  38. data/lib/reek/spec/should_reek_of.rb +12 -8
  39. data/lib/reek/version.rb +1 -1
  40. data/spec/reek/code_comment_spec.rb +13 -5
  41. data/spec/reek/examiner_spec.rb +2 -2
  42. data/spec/reek/smells/attribute_spec.rb +91 -78
  43. data/spec/reek/smells/boolean_parameter_spec.rb +72 -64
  44. data/spec/reek/smells/class_variable_spec.rb +81 -68
  45. data/spec/reek/smells/control_parameter_spec.rb +101 -141
  46. data/spec/reek/smells/data_clump_spec.rb +94 -149
  47. data/spec/reek/smells/duplicate_method_call_spec.rb +98 -85
  48. data/spec/reek/smells/feature_envy_spec.rb +164 -183
  49. data/spec/reek/smells/instance_variable_assumption_spec.rb +51 -147
  50. data/spec/reek/smells/irresponsible_module_spec.rb +153 -170
  51. data/spec/reek/smells/long_parameter_list_spec.rb +44 -88
  52. data/spec/reek/smells/long_yield_list_spec.rb +41 -41
  53. data/spec/reek/smells/manual_dispatch_spec.rb +36 -18
  54. data/spec/reek/smells/module_initialize_spec.rb +31 -33
  55. data/spec/reek/smells/nested_iterators_spec.rb +189 -183
  56. data/spec/reek/smells/nil_check_spec.rb +48 -37
  57. data/spec/reek/smells/prima_donna_method_spec.rb +41 -26
  58. data/spec/reek/smells/repeated_conditional_spec.rb +75 -87
  59. data/spec/reek/smells/smell_warning_spec.rb +7 -0
  60. data/spec/reek/smells/subclassed_from_core_class_spec.rb +37 -112
  61. data/spec/reek/smells/too_many_constants_spec.rb +109 -199
  62. data/spec/reek/smells/too_many_instance_variables_spec.rb +105 -128
  63. data/spec/reek/smells/too_many_methods_spec.rb +38 -62
  64. data/spec/reek/smells/too_many_statements_spec.rb +69 -45
  65. data/spec/reek/smells/uncommunicative_method_name_spec.rb +16 -29
  66. data/spec/reek/smells/uncommunicative_module_name_spec.rb +24 -37
  67. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +55 -60
  68. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +108 -95
  69. data/spec/reek/smells/unused_parameters_spec.rb +73 -49
  70. data/spec/reek/smells/unused_private_method_spec.rb +97 -50
  71. data/spec/reek/smells/utility_function_spec.rb +130 -188
  72. data/spec/reek/spec/should_reek_of_spec.rb +2 -2
  73. metadata +6 -7
  74. data/lib/reek/cli/warning_collector.rb +0 -27
  75. data/spec/reek/cli/warning_collector_spec.rb +0 -25
  76. data/spec/reek/smells/smell_detector_shared.rb +0 -29
@@ -1,250 +1,231 @@
1
1
  require_relative '../../spec_helper'
2
2
  require_lib 'reek/smells/feature_envy'
3
- require_lib 'reek/examiner'
4
- require_relative 'smell_detector_shared'
5
3
 
6
- # TODO: Bring specs in line with specs for other detectors
7
4
  RSpec.describe Reek::Smells::FeatureEnvy do
8
- context 'with no smell' do
9
- it 'should not report use of self' do
10
- expect('def simple() self.to_s + self.to_i end').not_to reek_of(:FeatureEnvy)
11
- end
12
-
13
- it 'should not report vcall with no argument' do
14
- expect('def simple() func; end').not_to reek_of(:FeatureEnvy)
15
- end
16
-
17
- it 'should not report single use' do
18
- expect('def no_envy(arga) arga.barg(@item) end').not_to reek_of(:FeatureEnvy)
19
- end
20
-
21
- it 'should not report return value' do
22
- expect('def no_envy(arga) arga.barg(@item); arga end').not_to reek_of(:FeatureEnvy)
23
- end
24
-
25
- it 'should ignore global variables' do
26
- expect('def no_envy() $s2.to_a; $s2[@item] end').not_to reek_of(:FeatureEnvy)
27
- end
28
-
29
- it 'should not report class methods' do
30
- expect('def simple() self.class.new.flatten_merge(self) end').
31
- not_to reek_of(:FeatureEnvy)
32
- end
33
-
34
- it 'should not report single use of an ivar' do
35
- expect('def no_envy() @item.to_a end').not_to reek_of(:FeatureEnvy)
36
- end
37
-
38
- it 'should not report returning an ivar' do
39
- expect('def no_envy() @item.to_a; @item end').not_to reek_of(:FeatureEnvy)
40
- end
41
-
42
- it 'should not report ivar usage in a parameter' do
43
- expect('def no_envy() @item.price + tax(@item) - savings(@item) end').
44
- not_to reek_of(:FeatureEnvy)
45
- end
46
-
47
- it 'should not report single use of an lvar' do
48
- expect('def no_envy() lv = @item; lv.to_a end').not_to reek_of(:FeatureEnvy)
49
- end
50
-
51
- it 'should not report returning an lvar' do
52
- expect('def no_envy() lv = @item; lv.to_a; lv end').not_to reek_of(:FeatureEnvy)
53
- end
54
-
55
- it 'ignores lvar usage in a parameter' do
56
- expect('def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end').
57
- not_to reek_of(:FeatureEnvy)
58
- end
59
-
60
- it 'ignores multiple ivars' do
61
- src = <<-EOS
62
- def func
63
- @other.a
64
- @other.b
65
- @nother.c
66
- @nother.d
5
+ it 'reports the right values' do
6
+ src = <<-EOS
7
+ class Alfa
8
+ def bravo(charlie)
9
+ (charlie.delta - charlie.echo) * foxtrot
67
10
  end
68
- EOS
69
- expect(src).not_to reek_of(:FeatureEnvy)
70
- end
11
+ end
12
+ EOS
13
+
14
+ expect(src).to reek_of(:FeatureEnvy,
15
+ lines: [3, 3],
16
+ context: 'Alfa#bravo',
17
+ message: "refers to 'charlie' more than self (maybe move it to another class?)",
18
+ source: 'string',
19
+ name: 'charlie')
71
20
  end
72
21
 
73
- context 'with 2 calls to a parameter' do
74
- it 'reports the smell' do
75
- expect('
76
- def envy(arga)
77
- arga.b(arga) + arga.c(@fred)
22
+ it 'does count all occurences' do
23
+ src = <<-EOS
24
+ class Alfa
25
+ def bravo(charlie)
26
+ (charlie.delta - charlie.echo) * foxtrot
78
27
  end
79
- ').to reek_of(:FeatureEnvy, name: 'arga')
80
- end
28
+
29
+ def golf(hotel)
30
+ (hotel.india + hotel.juliett) * kilo
31
+ end
32
+ end
33
+ EOS
34
+
35
+ expect(src).to reek_of(:FeatureEnvy,
36
+ lines: [3, 3],
37
+ name: 'charlie')
38
+ expect(src).to reek_of(:FeatureEnvy,
39
+ lines: [7, 7],
40
+ name: 'hotel')
41
+ end
42
+
43
+ it 'does not report use of self' do
44
+ expect('def alfa; self.to_s + self.to_i; end').not_to reek_of(:FeatureEnvy)
45
+ end
46
+
47
+ it 'does not report vcall with no argument' do
48
+ expect('def alfa; bravo; end').not_to reek_of(:FeatureEnvy)
49
+ end
50
+
51
+ it 'does not report single use' do
52
+ expect('def alfa(bravo); bravo.charlie(@delta); end').not_to reek_of(:FeatureEnvy)
53
+ end
54
+
55
+ it 'does not report return value' do
56
+ expect('def alfa(bravo); bravo.charlie(@delta); bravo; end').not_to reek_of(:FeatureEnvy)
57
+ end
58
+
59
+ it 'does ignore global variables' do
60
+ expect('def alfa; $bravo.to_a; $bravo[@charlie]; end').not_to reek_of(:FeatureEnvy)
81
61
  end
82
62
 
83
- it 'should report highest affinity' do
63
+ it 'does not report class methods' do
64
+ expect('def alfa; self.class.bravo(self); end').not_to reek_of(:FeatureEnvy)
65
+ end
66
+
67
+ it 'does not report single use of an ivar' do
68
+ expect('def alfa; @bravo.to_a; end').not_to reek_of(:FeatureEnvy)
69
+ end
70
+
71
+ it 'does not report returning an ivar' do
72
+ expect('def alfa; @bravo.to_a; @bravo; end').not_to reek_of(:FeatureEnvy)
73
+ end
74
+
75
+ it 'does not report ivar usage in a parameter' do
76
+ expect('def alfa; @bravo.charlie + delta(@bravo) - echo(@bravo) end').
77
+ not_to reek_of(:FeatureEnvy)
78
+ end
79
+
80
+ it 'does not report single use of an lvar' do
81
+ expect('def alfa; bravo = @charlie; bravo.to_a; end').not_to reek_of(:FeatureEnvy)
82
+ end
83
+
84
+ it 'does not report returning an lvar' do
85
+ expect('def alfa; bravo = @charlie; bravo.to_a; lv end').not_to reek_of(:FeatureEnvy)
86
+ end
87
+
88
+ it 'ignores lvar usage in a parameter' do
89
+ expect('def alfa; bravo = @item; bravo.charlie + delta(bravo) - echo(bravo); end').
90
+ not_to reek_of(:FeatureEnvy)
91
+ end
92
+
93
+ it 'ignores multiple ivars' do
84
94
  src = <<-EOS
85
- def total_envy
86
- fred = @item
87
- total = 0
88
- total += fred.price
89
- total += fred.tax
90
- total *= 1.15
95
+ def func
96
+ @alfa.charlie
97
+ @alfa.delta
98
+
99
+ @bravo.echo
100
+ @bravo.foxtrot
101
+ end
102
+ EOS
103
+
104
+ expect(src).not_to reek_of(:FeatureEnvy)
105
+ end
106
+
107
+ it 'report highest affinity' do
108
+ src = <<-EOS
109
+ def alfa
110
+ bravo = @charlie
111
+ delta = 0
112
+ delta += bravo.echo
113
+ delta += bravo.foxtrot
114
+ delta *= 1.15
91
115
  end
92
116
  EOS
93
- expect(src).to reek_of(:FeatureEnvy, name: 'total')
94
- expect(src).not_to reek_of(:FeatureEnvy, name: 'fred')
117
+
118
+ expect(src).to reek_of(:FeatureEnvy, name: 'delta')
119
+ expect(src).not_to reek_of(:FeatureEnvy, name: 'bravo')
95
120
  end
96
121
 
97
122
  it 'should report multiple affinities' do
98
123
  src = <<-EOS
99
- def total_envy
100
- fred = @item
101
- total = 0
102
- total += fred.price
103
- total += fred.tax
124
+ def alfa
125
+ bravo = @charlie
126
+ delta = 0
127
+ delta += bravo.echo
128
+ delta += bravo.foxtrot
104
129
  end
105
130
  EOS
106
- expect(src).to reek_of(:FeatureEnvy, name: 'total')
107
- expect(src).to reek_of(:FeatureEnvy, name: 'fred')
131
+
132
+ expect(src).to reek_of(:FeatureEnvy, name: 'delta')
133
+ expect(src).to reek_of(:FeatureEnvy, name: 'bravo')
108
134
  end
109
135
 
110
- it 'should not be fooled by duplication' do
111
- expect('
112
- def feed(thing)
113
- @cow.feed_to(thing.pig)
114
- @duck.feed_to(thing.pig)
136
+ it 'is not be fooled by duplication' do
137
+ src = <<-EOS
138
+ def alfa(bravo)
139
+ @charlie.delta(bravo.echo)
140
+ @foxtrot.delta(bravo.echo)
115
141
  end
116
- ').to reek_only_of(:DuplicateMethodCall)
142
+ EOS
143
+
144
+ expect(src).to reek_only_of(:DuplicateMethodCall)
117
145
  end
118
146
 
119
- it 'should count local calls' do
120
- expect('
121
- def feed(thing)
122
- cow.feed_to(thing.pig)
123
- duck.feed_to(thing.pig)
147
+ it 'does not count local calls' do
148
+ src = <<-EOS
149
+ def alfa(bravo)
150
+ @charlie.delta(bravo.echo)
151
+ @foxtrot.delta(bravo.echo)
124
152
  end
125
- ').to reek_only_of(:DuplicateMethodCall)
153
+ EOS
154
+
155
+ expect(src).to reek_only_of(:DuplicateMethodCall)
126
156
  end
127
157
 
128
- it 'should report many calls to lvar' do
129
- expect('
130
- def envy()
131
- lv = @item
132
- lv.price + lv.tax
158
+ it 'reports many calls to lvar' do
159
+ src = <<-EOS
160
+ def alfa
161
+ bravo = @charlie
162
+ bravo.delta + bravo.echo
133
163
  end
134
- ').to reek_only_of(:FeatureEnvy)
135
- end
164
+ EOS
136
165
 
137
- it 'ignores frequent use of a call' do
138
- expect('def func() other.a; other.b; nother.c end').not_to reek_of(:FeatureEnvy)
166
+ expect(src).to reek_only_of(:FeatureEnvy)
139
167
  end
140
168
 
141
169
  it 'counts =~ as a call' do
142
170
  src = <<-EOS
143
- def foo arg
144
- bar(arg.baz)
145
- arg =~ /bar/
146
- end
171
+ def alfa(bravo)
172
+ charlie(bravo.delta)
173
+ bravo =~ /charlie/
174
+ end
147
175
  EOS
176
+
148
177
  expect(src).to reek_of :FeatureEnvy
149
178
  end
150
179
 
151
180
  it 'counts += as a call' do
152
181
  src = <<-EOS
153
- def foo arg
154
- bar(arg.baz)
155
- arg += 1
156
- end
182
+ def alfa(bravo)
183
+ charlie(bravo.delta)
184
+ bravo += 1
185
+ end
157
186
  EOS
187
+
158
188
  expect(src).to reek_of :FeatureEnvy
159
189
  end
160
190
 
161
191
  it 'counts ivar assignment as call to self' do
162
192
  src = <<-EOS
163
- def foo
164
- bar = baz(1, 2)
193
+ def foo
194
+ bravo = charlie(1, 2)
165
195
 
166
- @quuz = bar.qux
167
- @zyxy = bar.foobar
168
- end
196
+ @delta = bravo.echo
197
+ @foxtrot = bravo.golf
198
+ end
169
199
  EOS
200
+
170
201
  expect(src).not_to reek_of :FeatureEnvy
171
202
  end
172
203
 
173
204
  it 'counts self references correctly' do
174
205
  src = <<-EOS
175
- def adopt(other)
176
- other.keys.each do |key|
177
- self[key] += 3
178
- self[key] = o4
206
+ def alfa(bravo)
207
+ bravo.keys.each do |charlie|
208
+ self[charlie] += 3
209
+ self[charlie] = 4
179
210
  end
180
211
  self
181
212
  end
182
213
  EOS
183
- expect(src).not_to reek_of(:FeatureEnvy)
184
- end
185
214
 
186
- it 'counts references to self correctly' do
187
- ruby = <<-EOS
188
- def report
189
- unless @report
190
- @report = Report.new
191
- cf = SmellConfig.new
192
- cf = cf.load_local(@dir) if @dir
193
- ContextBuilder.new(@report, cf.smell_listeners).check_source(@source)
194
- end
195
- @report
196
- end
197
- EOS
198
- expect(ruby).not_to reek_of(:FeatureEnvy)
215
+ expect(src).not_to reek_of(:FeatureEnvy)
199
216
  end
200
217
 
201
218
  it 'interprets << correctly' do
202
- ruby = <<-EOS
203
- def report_on(report)
204
- if @is_doubled
205
- report.record_doubled_smell(self)
219
+ src = <<-EOS
220
+ def alfa(bravo)
221
+ if @charlie
222
+ bravo.delta(self)
206
223
  else
207
- report << self
224
+ bravo << self
208
225
  end
209
226
  end
210
227
  EOS
211
228
 
212
- expect(ruby).not_to reek_of(:FeatureEnvy)
213
- end
214
- end
215
-
216
- RSpec.describe Reek::Smells::FeatureEnvy do
217
- let(:detector) { build(:smell_detector, smell_type: :FeatureEnvy) }
218
-
219
- it_should_behave_like 'SmellDetector'
220
-
221
- context 'when a smell is reported' do
222
- let(:receiver) { 'other' }
223
-
224
- let(:warning) do
225
- src = <<-EOS
226
- def envious(other)
227
- #{receiver}.call
228
- self.do_nothing
229
- #{receiver}.other
230
- #{receiver}.fred
231
- end
232
- EOS
233
- Reek::Examiner.new(src, filter_by_smells: ['FeatureEnvy']).smells.first
234
- end
235
-
236
- it_should_behave_like 'common fields set correctly'
237
-
238
- it 'reports the name' do
239
- expect(warning.parameters[:name]).to eq(receiver)
240
- end
241
-
242
- it 'reports the lines' do
243
- expect(warning.lines).to eq([2, 4, 5])
244
- end
245
-
246
- it 'has the right message' do
247
- expect(warning.message).to eq('refers to other more than self (maybe move it to another class?)')
248
- end
229
+ expect(src).not_to reek_of(:FeatureEnvy)
249
230
  end
250
231
  end
@@ -3,104 +3,59 @@ require_relative '../../spec_helper'
3
3
  require_lib 'reek/smells/instance_variable_assumption'
4
4
 
5
5
  RSpec.describe Reek::Smells::InstanceVariableAssumption do
6
- describe 'warning' do
7
- context 'smell line' do
8
- it 'should report the lines' do
9
- src = <<-EOS
10
- class Dummy
11
- def test
12
- @a
13
- end
14
- end
15
- EOS
16
-
17
- expect(src).to reek_of(:InstanceVariableAssumption, lines: [1])
6
+ it 'reports the right values' do
7
+ src = <<-EOS
8
+ class Alfa
9
+ def bravo
10
+ @charlie
11
+ end
18
12
  end
19
- end
20
-
21
- context 'smell parameters' do
22
- it 'should report the lines' do
23
- src = <<-EOS
24
- class Dummy
25
- def test
26
- @a
27
- end
28
- end
29
- EOS
13
+ EOS
30
14
 
31
- expect(src).to reek_of(:InstanceVariableAssumption, assumption: :@a)
32
- end
33
- end
34
-
35
- context 'smell context' do
36
- it 'should report the context' do
37
- src = <<-EOS
38
- class Dummy
39
- def test
40
- @a
41
- end
42
- end
43
- EOS
15
+ expect(src).to reek_of(:InstanceVariableAssumption,
16
+ lines: [1],
17
+ context: 'Alfa',
18
+ message: "assumes too much for instance variable '@charlie'",
19
+ source: 'string',
20
+ assumption: :@charlie)
21
+ end
44
22
 
45
- expect(src).to reek_of(:InstanceVariableAssumption, context: 'Dummy')
46
- end
47
- end
48
-
49
- context 'smell message' do
50
- it 'should report the ivars in the message' do
51
- message_a = 'assumes too much for instance variable @a'
52
- message_b = 'assumes too much for instance variable @b'
53
-
54
- src = <<-EOS
55
- class Dummy
56
- def test
57
- [@a, @b]
58
- end
59
- end
60
- EOS
23
+ it 'does count all occurences' do
24
+ src = <<-EOS
25
+ class Alfa
26
+ def bravo
27
+ @charlie
28
+ end
61
29
 
62
- expect(src).to reek_of(:InstanceVariableAssumption, message: message_a)
63
- expect(src).to reek_of(:InstanceVariableAssumption, message: message_b)
30
+ def delta
31
+ @echo
32
+ end
64
33
  end
65
34
 
66
- it 'should report each ivar once' do
67
- message_a = 'assumes too much for instance variable @a'
68
- message_b = 'assumes too much for instance variable @b'
69
- message_c = 'assumes too much for instance variable @c'
70
-
71
- src = <<-EOS
72
- class Dummy
73
- def test
74
- [@a, @a, @b, @c]
75
- end
76
-
77
- def retest
78
- @c
79
- end
80
- end
81
- EOS
35
+ EOS
82
36
 
83
- expect(src).to reek_of(:InstanceVariableAssumption, message: message_a)
84
- expect(src).to reek_of(:InstanceVariableAssumption, message: message_b)
85
- expect(src).to reek_of(:InstanceVariableAssumption, message: message_c)
86
- end
87
- end
37
+ expect(src).to reek_of(:InstanceVariableAssumption,
38
+ lines: [1],
39
+ assumption: :@charlie)
40
+ expect(src).to reek_of(:InstanceVariableAssumption,
41
+ lines: [1],
42
+ assumption: :@echo)
88
43
  end
89
44
 
90
45
  it 'should not report an empty class' do
91
46
  src = <<-EOS
92
- class Dummy
47
+ class Alfa
93
48
  end
94
49
  EOS
95
50
 
96
51
  expect(src).not_to reek_of(:InstanceVariableAssumption)
97
52
  end
98
53
 
99
- it 'should not report when lazy initializing' do
54
+ it 'does not report when lazy initializing' do
100
55
  src = <<-EOS
101
- class Dummy
102
- def test
103
- @a ||= 1
56
+ class Alfa
57
+ def bravo
58
+ @charlie ||= 1
104
59
  end
105
60
  end
106
61
  EOS
@@ -108,88 +63,37 @@ RSpec.describe Reek::Smells::InstanceVariableAssumption do
108
63
  expect(src).not_to reek_of(:InstanceVariableAssumption)
109
64
  end
110
65
 
111
- it 'should report when making instance variable assumption' do
112
- src = <<-EOS
113
- class Dummy
114
- def test
115
- @a
116
- end
117
- end
118
- EOS
119
-
120
- expect(src).to reek_of(:InstanceVariableAssumption)
121
- end
122
-
123
66
  it 'reports variable even if others are initialized' do
124
67
  src = <<-EOS
125
- class Dummy
68
+ class Alfa
126
69
  def initialize
127
- @a = 1
70
+ @bravo = 1
128
71
  end
129
72
 
130
- def test
131
- [@a, @b]
73
+ def charlie
74
+ [@bravo, @delta]
132
75
  end
133
76
  end
134
77
  EOS
135
78
 
136
- expect(src).to reek_of(:InstanceVariableAssumption)
79
+ expect(src).to reek_of(:InstanceVariableAssumption, assumption: :@delta)
137
80
  end
138
81
 
139
- context 'inner classes' do
140
- it 'should report outter class' do
141
- src = <<-EOS
142
- class Dummy
143
- def test
144
- @a
145
- end
146
-
147
- class Dummiest
148
- end
149
- end
150
- EOS
151
-
152
- expect(src).to reek_of(:InstanceVariableAssumption, context: 'Dummy')
153
- end
154
-
155
- it 'should report even if outer class initialize the variable' do
156
- src = <<-EOS
157
- class Dummy
158
- def initialize
159
- @a = 1
160
- end
161
-
162
- class Dummiest
163
- def test
164
- @a
165
- end
166
- end
82
+ it 'reports inner class even if outer class initializes the variable' do
83
+ src = <<-EOS
84
+ class Alfa
85
+ def initialize
86
+ @bravo = 1
167
87
  end
168
- EOS
169
-
170
- expect(src).to reek_of(:InstanceVariableAssumption, context: 'Dummy::Dummiest')
171
- end
172
88
 
173
- it 'should report inner classes' do
174
- src = <<-EOS
175
- class Dummy
176
- def initialize
177
- @a = 1
178
- end
179
-
180
- class Dummiest
181
- def initialize
182
- @b = 1
183
- end
184
-
185
- def test
186
- @c
187
- end
89
+ class Charlie
90
+ def delta
91
+ @bravo
188
92
  end
189
93
  end
190
- EOS
94
+ end
95
+ EOS
191
96
 
192
- expect(src).to reek_of(:InstanceVariableAssumption, context: 'Dummy::Dummiest')
193
- end
97
+ expect(src).to reek_of(:InstanceVariableAssumption, context: 'Alfa::Charlie')
194
98
  end
195
99
  end