reek 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +6 -0
  4. data/CONTRIBUTING.md +7 -6
  5. data/Gemfile +2 -2
  6. data/README.md +8 -15
  7. data/Rakefile +1 -1
  8. data/defaults.reek +1 -0
  9. data/features/command_line_interface/basic_usage.feature +8 -14
  10. data/features/command_line_interface/smell_selection.feature +4 -4
  11. data/features/command_line_interface/smells_count.feature +12 -14
  12. data/features/configuration_files/masking_smells.feature +31 -24
  13. data/features/configuration_loading.feature +15 -18
  14. data/features/programmatic_access.feature +7 -9
  15. data/features/rake_task/rake_task.feature +20 -24
  16. data/features/reports/json.feature +16 -28
  17. data/features/reports/reports.feature +56 -67
  18. data/features/reports/yaml.feature +13 -26
  19. data/features/samples.feature +3 -3
  20. data/features/step_definitions/sample_file_steps.rb +22 -156
  21. data/features/todo_list.feature +13 -14
  22. data/lib/reek/cli/options.rb +1 -1
  23. data/lib/reek/examiner.rb +45 -10
  24. data/lib/reek/smells/attribute.rb +3 -4
  25. data/lib/reek/smells/boolean_parameter.rb +2 -2
  26. data/lib/reek/smells/class_variable.rb +1 -1
  27. data/lib/reek/smells/control_parameter.rb +4 -4
  28. data/lib/reek/smells/data_clump.rb +2 -3
  29. data/lib/reek/smells/duplicate_method_call.rb +1 -1
  30. data/lib/reek/smells/feature_envy.rb +2 -2
  31. data/lib/reek/smells/irresponsible_module.rb +2 -3
  32. data/lib/reek/smells/long_parameter_list.rb +1 -1
  33. data/lib/reek/smells/long_yield_list.rb +1 -1
  34. data/lib/reek/smells/module_initialize.rb +1 -1
  35. data/lib/reek/smells/nested_iterators.rb +2 -2
  36. data/lib/reek/smells/nil_check.rb +1 -1
  37. data/lib/reek/smells/prima_donna_method.rb +5 -2
  38. data/lib/reek/smells/repeated_conditional.rb +1 -1
  39. data/lib/reek/smells/smell_detector.rb +1 -1
  40. data/lib/reek/smells/smell_warning.rb +6 -5
  41. data/lib/reek/smells/subclassed_from_core_class.rb +3 -3
  42. data/lib/reek/smells/too_many_constants.rb +1 -1
  43. data/lib/reek/smells/too_many_instance_variables.rb +1 -1
  44. data/lib/reek/smells/too_many_methods.rb +1 -1
  45. data/lib/reek/smells/too_many_statements.rb +1 -1
  46. data/lib/reek/smells/uncommunicative_method_name.rb +1 -1
  47. data/lib/reek/smells/uncommunicative_module_name.rb +1 -1
  48. data/lib/reek/smells/uncommunicative_parameter_name.rb +1 -1
  49. data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
  50. data/lib/reek/smells/unused_parameters.rb +1 -1
  51. data/lib/reek/smells/unused_private_method.rb +1 -1
  52. data/lib/reek/smells/utility_function.rb +2 -3
  53. data/lib/reek/spec/should_reek_of.rb +14 -1
  54. data/lib/reek/version.rb +1 -1
  55. data/samples/checkstyle.xml +7 -0
  56. data/samples/clean.rb +6 -0
  57. data/samples/configuration/.reek +0 -0
  58. data/samples/configuration/corrupt.reek +1 -0
  59. data/samples/configuration/empty.reek +0 -0
  60. data/samples/configuration/full_configuration.reek +9 -0
  61. data/{spec/samples/configuration/simple_configuration.reek → samples/configuration/full_mask.reek} +2 -2
  62. data/samples/configuration/non_public_modifiers_mask.reek +3 -0
  63. data/samples/configuration/partial_mask.reek +3 -0
  64. data/samples/configuration/with_excluded_paths.reek +4 -0
  65. data/{spec/samples → samples}/exceptions.reek +0 -0
  66. data/{spec/samples → samples}/inline.rb +0 -0
  67. data/{spec/samples → samples}/optparse.rb +0 -0
  68. data/samples/paths.rb +4 -0
  69. data/{spec/samples → samples}/redcloth.rb +0 -0
  70. data/samples/smelly.rb +7 -0
  71. data/samples/smelly_with_inline_mask.rb +8 -0
  72. data/samples/smelly_with_modifiers.rb +12 -0
  73. data/{spec/samples → samples}/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +0 -0
  74. data/{spec/samples → samples}/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +0 -0
  75. data/{spec/samples → samples}/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +0 -0
  76. data/{spec/samples → samples}/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb +0 -0
  77. data/{spec/samples → samples}/source_with_hidden_directories/uncommunicative_parameter_name.rb +0 -0
  78. data/{spec/samples → samples}/source_with_non_ruby_files/gibberish +0 -0
  79. data/{spec/samples → samples}/source_with_non_ruby_files/python_source.py +0 -0
  80. data/{spec/samples → samples}/source_with_non_ruby_files/uncommunicative_parameter_name.rb +0 -0
  81. data/spec/reek/cli/application_spec.rb +1 -1
  82. data/spec/reek/cli/command/report_command_spec.rb +2 -5
  83. data/spec/reek/configuration/app_configuration_spec.rb +10 -8
  84. data/spec/reek/configuration/configuration_file_finder_spec.rb +24 -17
  85. data/spec/reek/examiner_spec.rb +84 -5
  86. data/spec/reek/report/json_report_spec.rb +1 -3
  87. data/spec/reek/report/xml_report_spec.rb +2 -3
  88. data/spec/reek/report/yaml_report_spec.rb +0 -2
  89. data/spec/reek/smells/attribute_spec.rb +21 -10
  90. data/spec/reek/smells/boolean_parameter_spec.rb +13 -12
  91. data/spec/reek/smells/class_variable_spec.rb +4 -4
  92. data/spec/reek/smells/control_parameter_spec.rb +25 -18
  93. data/spec/reek/smells/data_clump_spec.rb +5 -5
  94. data/spec/reek/smells/duplicate_method_call_spec.rb +1 -1
  95. data/spec/reek/smells/feature_envy_spec.rb +8 -2
  96. data/spec/reek/smells/irresponsible_module_spec.rb +16 -14
  97. data/spec/reek/smells/long_parameter_list_spec.rb +5 -1
  98. data/spec/reek/smells/long_yield_list_spec.rb +5 -2
  99. data/spec/reek/smells/nested_iterators_spec.rb +37 -13
  100. data/spec/reek/smells/nil_check_spec.rb +50 -53
  101. data/spec/reek/smells/prima_donna_method_spec.rb +9 -1
  102. data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
  103. data/spec/reek/smells/too_many_methods_spec.rb +4 -4
  104. data/spec/reek/smells/too_many_statements_spec.rb +1 -1
  105. data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -3
  106. data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
  107. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +3 -3
  108. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -3
  109. data/spec/reek/smells/utility_function_spec.rb +12 -8
  110. data/spec/reek/source/source_locator_spec.rb +5 -1
  111. data/spec/reek/spec/should_reek_of_spec.rb +20 -13
  112. data/spec/reek/spec/should_reek_spec.rb +6 -11
  113. data/spec/spec_helper.rb +2 -2
  114. metadata +28 -36
  115. data/spec/samples/all_but_one_masked/clean_one.rb +0 -7
  116. data/spec/samples/all_but_one_masked/dirty.rb +0 -8
  117. data/spec/samples/all_but_one_masked/masked.reek +0 -9
  118. data/spec/samples/checkstyle.xml +0 -13
  119. data/spec/samples/clean_due_to_masking/clean_one.rb +0 -7
  120. data/spec/samples/clean_due_to_masking/clean_three.rb +0 -7
  121. data/spec/samples/clean_due_to_masking/clean_two.rb +0 -7
  122. data/spec/samples/clean_due_to_masking/dirty_one.rb +0 -7
  123. data/spec/samples/clean_due_to_masking/dirty_two.rb +0 -7
  124. data/spec/samples/clean_due_to_masking/masked.reek +0 -11
  125. data/spec/samples/configuration/full_configuration.reek +0 -9
  126. data/spec/samples/configuration/with_excluded_paths.reek +0 -4
  127. data/spec/samples/masked_by_dotfile/.reek +0 -9
  128. data/spec/samples/masked_by_dotfile/dirty.rb +0 -8
  129. data/spec/samples/no_config_file/dirty.rb +0 -8
  130. data/spec/samples/three_clean_files/clean_one.rb +0 -7
  131. data/spec/samples/three_clean_files/clean_three.rb +0 -7
  132. data/spec/samples/three_clean_files/clean_two.rb +0 -7
  133. data/spec/samples/two_smelly_files/dirty_one.rb +0 -8
  134. data/spec/samples/two_smelly_files/dirty_two.rb +0 -8
@@ -26,7 +26,7 @@ RSpec.shared_examples_for 'a data clump detector' do
26
26
  end
27
27
  EOS
28
28
  ctx = Reek::Context::ModuleContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
29
- build(:smell_detector, smell_type: :DataClump).inspect(ctx)
29
+ build(:smell_detector, smell_type: :DataClump).sniff(ctx)
30
30
  end
31
31
 
32
32
  it 'records only the one smell' do
@@ -41,10 +41,6 @@ RSpec.shared_examples_for 'a data clump detector' do
41
41
  expect(smells[0].parameters[:count]).to eq(3)
42
42
  end
43
43
 
44
- it 'reports all methods' do
45
- expect(smells[0].parameters[:methods]).to eq([:first, :second, :third])
46
- end
47
-
48
44
  it 'reports the declaration line numbers' do
49
45
  expect(smells[0].lines).to eq([2, 3, 4])
50
46
  end
@@ -56,6 +52,10 @@ RSpec.shared_examples_for 'a data clump detector' do
56
52
  it 'reports the context fq name' do
57
53
  expect(smells[0].context).to eq(module_name)
58
54
  end
55
+
56
+ it 'has the right message' do
57
+ expect(smells[0].message).to eq('takes parameters [pa, pb] to 3 methods')
58
+ end
59
59
  end
60
60
 
61
61
  it 'reports 3 swapped pairs' do
@@ -17,7 +17,7 @@ RSpec.describe Reek::Smells::DuplicateMethodCall do
17
17
  end
18
18
  EOS
19
19
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
20
- smells = detector.inspect(ctx)
20
+ smells = detector.sniff(ctx)
21
21
  expect(smells.length).to eq(1)
22
22
  smells.first
23
23
  end
@@ -235,10 +235,16 @@ RSpec.describe Reek::Smells::FeatureEnvy do
235
235
 
236
236
  it_should_behave_like 'common fields set correctly'
237
237
 
238
- it 'reports the correct values' do
238
+ it 'reports the name' do
239
239
  expect(warning.parameters[:name]).to eq(receiver)
240
- expect(warning.parameters[:count]).to eq(3)
240
+ end
241
+
242
+ it 'reports the lines' do
241
243
  expect(warning.lines).to eq([2, 4, 5])
242
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
243
249
  end
244
250
  end
@@ -6,12 +6,14 @@ require_relative 'smell_detector_shared'
6
6
  RSpec.describe Reek::Smells::IrresponsibleModule do
7
7
  it 'reports a class without a comment' do
8
8
  src = 'class BadClass; end'
9
- expect(src).to reek_of :IrresponsibleModule, name: 'BadClass'
9
+ expect(src).to reek_of :IrresponsibleModule,
10
+ lines: [1],
11
+ message: 'has no descriptive comment'
10
12
  end
11
13
 
12
14
  it 'reports a module without a comment' do
13
15
  src = 'module BadClass; end'
14
- expect(src).to reek_of :IrresponsibleModule, name: 'BadClass'
16
+ expect(src).to reek_of(:IrresponsibleModule, context: 'BadClass')
15
17
  end
16
18
 
17
19
  it 'does not report re-opened modules' do
@@ -39,7 +41,7 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
39
41
  #
40
42
  class BadClass; end
41
43
  EOS
42
- expect(src).to reek_of :IrresponsibleModule
44
+ expect(src).to reek_of(:IrresponsibleModule, context: 'BadClass')
43
45
  end
44
46
 
45
47
  it 'reports a class with a preceding comment with intermittent material' do
@@ -50,7 +52,7 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
50
52
 
51
53
  class Bar; end
52
54
  EOS
53
- expect(src).to reek_of(:IrresponsibleModule)
55
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Bar')
54
56
  end
55
57
 
56
58
  it 'reports a class with a trailing comment' do
@@ -58,12 +60,12 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
58
60
  class BadClass
59
61
  end # end BadClass
60
62
  EOS
61
- expect(src).to reek_of(:IrresponsibleModule)
63
+ expect(src).to reek_of(:IrresponsibleModule, context: 'BadClass')
62
64
  end
63
65
 
64
66
  it 'reports a fully qualified class name correctly' do
65
67
  src = 'class Foo::Bar; end'
66
- expect(src).to reek_of :IrresponsibleModule, name: 'Foo::Bar'
68
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo::Bar')
67
69
  end
68
70
 
69
71
  it 'does not report modules used only as namespaces' do
@@ -102,7 +104,7 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
102
104
  end
103
105
  end
104
106
  EOS
105
- expect(src).to reek_of(:IrresponsibleModule)
107
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo')
106
108
  end
107
109
 
108
110
  it 'reports modules that have both nested modules and singleton methods' do
@@ -115,7 +117,7 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
115
117
  end
116
118
  end
117
119
  EOS
118
- expect(src).to reek_of(:IrresponsibleModule)
120
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo')
119
121
  end
120
122
 
121
123
  it 'reports modules that have both nested modules and methods on the singleton class' do
@@ -130,7 +132,7 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
130
132
  end
131
133
  end
132
134
  EOS
133
- expect(src).to reek_of(:IrresponsibleModule)
135
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo')
134
136
  end
135
137
 
136
138
  it 'does not report namespace modules that have a nested class through assignment' do
@@ -149,7 +151,7 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
149
151
  src = <<-EOS
150
152
  class Foo < Bar; end
151
153
  EOS
152
- expect(src).to reek_of(:IrresponsibleModule)
154
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo')
153
155
  end
154
156
 
155
157
  it 'reports classes defined through assignment' do
@@ -159,14 +161,14 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
159
161
  Foo = Class.new Bar
160
162
  end
161
163
  EOS
162
- expect(src).to reek_of(:IrresponsibleModule, name: 'Foo')
164
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Qux::Foo')
163
165
  end
164
166
 
165
167
  it 'reports top level classes defined through assignment' do
166
168
  src = <<-EOS
167
169
  Foo = Class.new Bar
168
170
  EOS
169
- expect(src).to reek_of(:IrresponsibleModule, name: 'Foo')
171
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo')
170
172
  end
171
173
 
172
174
  it 'reports structs defined through assignment' do
@@ -176,14 +178,14 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
176
178
  Foo = Struct.new(:x, :y)
177
179
  end
178
180
  EOS
179
- expect(src).to reek_of(:IrresponsibleModule, name: 'Foo')
181
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Qux::Foo')
180
182
  end
181
183
 
182
184
  it 'reports top level structs defined through assignment' do
183
185
  src = <<-EOS
184
186
  Foo = Struct.new(:x, :y)
185
187
  EOS
186
- expect(src).to reek_of(:IrresponsibleModule, name: 'Foo')
188
+ expect(src).to reek_of(:IrresponsibleModule, context: 'Foo')
187
189
  end
188
190
 
189
191
  it 'does not report constants that are not classes' do
@@ -87,7 +87,7 @@ RSpec.describe Reek::Smells::LongParameterList do
87
87
  end
88
88
  EOS
89
89
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
90
- detector.inspect(ctx).first
90
+ detector.sniff(ctx).first
91
91
  end
92
92
 
93
93
  it_should_behave_like 'common fields set correctly'
@@ -99,5 +99,9 @@ RSpec.describe Reek::Smells::LongParameterList do
99
99
  it 'reports the line number of the method' do
100
100
  expect(warning.lines).to eq([1])
101
101
  end
102
+
103
+ it 'has the right message' do
104
+ expect(warning.message).to eq('has 4 parameters')
105
+ end
102
106
  end
103
107
  end
@@ -13,14 +13,17 @@ RSpec.describe Reek::Smells::LongYieldList do
13
13
  src = 'def simple(arga, argb, &blk) f(3);yield; end'
14
14
  expect(src).not_to reek_of(:LongYieldList)
15
15
  end
16
+
16
17
  it 'should not report yield with few parameters' do
17
18
  src = 'def simple(arga, argb, &blk) f(3);yield a,b; end'
18
19
  expect(src).not_to reek_of(:LongYieldList)
19
20
  end
21
+
20
22
  it 'should report yield with many parameters' do
21
23
  src = 'def simple(arga, argb, &blk) f(3);yield arga,argb,arga,argb; end'
22
24
  expect(src).to reek_of(:LongYieldList, count: 4)
23
25
  end
26
+
24
27
  it 'should not report yield of a long expression' do
25
28
  src = 'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'
26
29
  expect(src).not_to reek_of(:LongYieldList)
@@ -33,10 +36,10 @@ RSpec.describe Reek::Smells::LongYieldList do
33
36
  def simple(arga, argb, &blk)
34
37
  f(3)
35
38
  yield(arga,argb,arga,argb)
36
- end
39
+ end
37
40
  EOS
38
41
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
39
- detector.inspect(ctx).first
42
+ detector.sniff(ctx).first
40
43
  end
41
44
 
42
45
  it_should_behave_like 'common fields set correctly'
@@ -69,7 +69,7 @@ RSpec.describe Reek::Smells::NestedIterators do
69
69
  ) { |qux| qux.quuz }
70
70
  end
71
71
  EOS
72
- expect(src).to reek_of(:NestedIterators, count: 2)
72
+ expect(src).to reek_of(:NestedIterators, depth: 2)
73
73
  end
74
74
 
75
75
  it 'reports the deepest level of nesting only' do
@@ -82,8 +82,8 @@ RSpec.describe Reek::Smells::NestedIterators do
82
82
  }
83
83
  end
84
84
  EOS
85
- expect(src).not_to reek_of(:NestedIterators, count: 2)
86
- expect(src).to reek_of(:NestedIterators, count: 3)
85
+ expect(src).not_to reek_of(:NestedIterators, depth: 2)
86
+ expect(src).to reek_of(:NestedIterators, depth: 3)
87
87
  end
88
88
 
89
89
  it 'handles the case where super receives a block' do
@@ -110,7 +110,7 @@ RSpec.describe Reek::Smells::NestedIterators do
110
110
  expect(src).to reek_of(:NestedIterators)
111
111
  end
112
112
 
113
- describe 'inspect / warnings' do
113
+ describe 'sniff / warnings' do
114
114
  let(:detector) { build(:smell_detector, smell_type: :NestedIterators) }
115
115
 
116
116
  it 'reports a sensible warning message' do
@@ -132,7 +132,7 @@ RSpec.describe Reek::Smells::NestedIterators do
132
132
  end
133
133
  end
134
134
  EOS
135
- expect(source).to reek_of(:NestedIterators, name: 'foo', lines: [3])
135
+ expect(source).to reek_of(:NestedIterators, lines: [3])
136
136
  end
137
137
 
138
138
  it 'reports all lines on which nested iterators occur' do
@@ -143,7 +143,7 @@ RSpec.describe Reek::Smells::NestedIterators do
143
143
  end
144
144
  EOS
145
145
 
146
- expect(source).to reek_of(:NestedIterators, name: 'bad', lines: [2, 3])
146
+ expect(source).to reek_of(:NestedIterators, lines: [2, 3])
147
147
  end
148
148
 
149
149
  it 'reports separete cases of nested iterators if levels are different' do
@@ -153,8 +153,8 @@ RSpec.describe Reek::Smells::NestedIterators do
153
153
  @jim.each {|ting| ting.each {|piece| piece.each {|atom| atom.foo } } }
154
154
  end
155
155
  EOS
156
- expect(source).to reek_of(:NestedIterators, name: 'bad', lines: [2], count: 2)
157
- expect(source).to reek_of(:NestedIterators, name: 'bad', lines: [3], count: 3)
156
+ expect(source).to reek_of(:NestedIterators, lines: [2], depth: 2)
157
+ expect(source).to reek_of(:NestedIterators, lines: [3], depth: 3)
158
158
  end
159
159
  end
160
160
 
@@ -193,6 +193,30 @@ RSpec.describe Reek::Smells::NestedIterators do
193
193
  end
194
194
  end
195
195
 
196
+ it 'reports nested iterators called via safe navigation' do
197
+ source = <<-EOS
198
+ def show_bottles(bars)
199
+ bars&.each do |bar|
200
+ bar&.each do |bottle|
201
+ puts bottle
202
+ end
203
+ end
204
+ end
205
+ EOS
206
+ expect(source).to reek_of(:NestedIterators)
207
+ end
208
+
209
+ it 'does not report unnested iterators called via safe navigation' do
210
+ source = <<-EOS
211
+ def show_bottles(bar)
212
+ bar&.each do |bottle|
213
+ puts bottle
214
+ end
215
+ end
216
+ EOS
217
+ expect(source).not_to reek_of(:NestedIterators)
218
+ end
219
+
196
220
  context 'when the allowed nesting depth is 3' do
197
221
  let(:config) do
198
222
  { Reek::Smells::NestedIterators::MAX_ALLOWED_NESTING_KEY => 3 }
@@ -250,7 +274,7 @@ RSpec.describe Reek::Smells::NestedIterators do
250
274
  @fred.ignore_me {|item| item.each {|ting| ting.each {|other| other.other} } }
251
275
  end
252
276
  '
253
- expect(src).to reek_of(:NestedIterators, count: 2).with_config(config)
277
+ expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
254
278
  end
255
279
 
256
280
  it 'should report nested iterators outside the ignored iterator' do
@@ -259,7 +283,7 @@ RSpec.describe Reek::Smells::NestedIterators do
259
283
  @fred.each {|item| item.each {|ting| ting.ignore_me {|other| other.other} } }
260
284
  end
261
285
  '
262
- expect(src).to reek_of(:NestedIterators, count: 2).with_config(config)
286
+ expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
263
287
  end
264
288
 
265
289
  it 'should report nested iterators with the ignored iterator between them' do
@@ -268,7 +292,7 @@ RSpec.describe Reek::Smells::NestedIterators do
268
292
  @fred.each {|item| item.ignore_me {|ting| ting.ting {|other| other.other} } }
269
293
  end
270
294
  '
271
- expect(src).to reek_of(:NestedIterators, count: 2).with_config(config)
295
+ expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
272
296
  end
273
297
  end
274
298
  end
@@ -288,13 +312,13 @@ RSpec.describe Reek::Smells::NestedIterators do
288
312
  end
289
313
  EOS
290
314
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
291
- detector.inspect(ctx).first
315
+ detector.sniff(ctx).first
292
316
  end
293
317
 
294
318
  it_should_behave_like 'common fields set correctly'
295
319
 
296
320
  it 'reports correct values' do
297
- expect(warning.parameters[:count]).to eq(2)
321
+ expect(warning.parameters[:depth]).to eq(2)
298
322
  expect(warning.lines).to eq([3])
299
323
  end
300
324
  end
@@ -4,73 +4,70 @@ require_lib 'reek/smells/nil_check'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::NilCheck do
7
- context 'for methods' do
8
- it 'reports the correct line number' do
9
- src = <<-EOS
7
+ it 'reports correctly the basic use case' do
8
+ src = <<-EOS
10
9
  def nilcheck foo
11
10
  foo.nil?
12
11
  end
13
- EOS
14
- ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
15
- detector = build(:smell_detector, smell_type: :NilCheck)
16
- smells = detector.inspect(ctx)
17
- expect(smells[0].lines).to eq [2]
18
- end
12
+ EOS
13
+ expect(src).to reek_of :NilCheck,
14
+ lines: [2],
15
+ message: 'performs a nil-check'
16
+ end
19
17
 
20
- it 'reports nothing when scope includes no nil checks' do
21
- expect('def no_nils; end').not_to reek_of(:NilCheck)
22
- end
18
+ it 'reports nothing when scope includes no nil checks' do
19
+ expect('def no_nils; end').not_to reek_of(:NilCheck)
20
+ end
23
21
 
24
- it 'reports when scope uses multiple nil? methods' do
25
- src = <<-EOS
26
- def chk_multi_nil(para)
27
- para.nil?
28
- puts "Hello"
29
- \"\".nil?
30
- end
31
- EOS
32
- expect(src).to reek_of(:NilCheck)
22
+ it 'reports when scope uses multiple nil? methods' do
23
+ src = <<-EOS
24
+ def chk_multi_nil(para)
25
+ para.nil?
26
+ puts "Hello"
27
+ \"\".nil?
33
28
  end
29
+ EOS
30
+ expect(src).to reek_of(:NilCheck)
31
+ end
34
32
 
35
- it 'reports twice when scope uses == nil and === nil' do
36
- src = <<-EOS
37
- def chk_eq_nil(para)
38
- para == nil
39
- para === nil
40
- end
41
- EOS
42
- expect(src).to reek_of(:NilCheck)
33
+ it 'reports twice when scope uses == nil and === nil' do
34
+ src = <<-EOS
35
+ def chk_eq_nil(para)
36
+ para == nil
37
+ para === nil
43
38
  end
39
+ EOS
40
+ expect(src).to reek_of(:NilCheck)
41
+ end
44
42
 
45
- it 'reports when scope uses nil ==' do
46
- expect('def chk_eq_nil_rev(para); nil == para; end').to reek_of(:NilCheck)
47
- end
43
+ it 'reports when scope uses nil ==' do
44
+ expect('def chk_eq_nil_rev(para); nil == para; end').to reek_of(:NilCheck)
45
+ end
48
46
 
49
- it 'reports when scope uses multiple case-clauses checking nil' do
50
- src = <<-EOS
51
- def case_nil
52
- case @inst_var
53
- when nil then puts "Nil"
54
- end
55
- puts "Hello"
56
- case @inst_var2
57
- when 1 then puts 1
58
- when nil then puts nil.inspect
59
- end
47
+ it 'reports when scope uses multiple case-clauses checking nil' do
48
+ src = <<-EOS
49
+ def case_nil
50
+ case @inst_var
51
+ when nil then puts "Nil"
52
+ end
53
+ puts "Hello"
54
+ case @inst_var2
55
+ when 1 then puts 1
56
+ when nil then puts nil.inspect
60
57
  end
61
- EOS
62
- expect(src).to reek_of(:NilCheck)
63
58
  end
59
+ EOS
60
+ expect(src).to reek_of(:NilCheck)
61
+ end
64
62
 
65
- it 'reports a when clause that checks nil and other values' do
66
- src = <<-EOS
67
- def case_nil
68
- case @inst_var
69
- when nil, false then puts "Hello"
70
- end
63
+ it 'reports a when clause that checks nil and other values' do
64
+ src = <<-EOS
65
+ def case_nil
66
+ case @inst_var
67
+ when nil, false then puts "Hello"
71
68
  end
72
- EOS
73
- expect(src).to reek_of(:NilCheck)
74
69
  end
70
+ EOS
71
+ expect(src).to reek_of(:NilCheck)
75
72
  end
76
73
  end