reek 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +9 -0
  3. data/README.md +54 -5
  4. data/Rakefile +1 -1
  5. data/features/command_line_interface/smell_selection.feature +4 -4
  6. data/features/command_line_interface/smells_count.feature +9 -8
  7. data/features/configuration_files/masking_smells.feature +16 -51
  8. data/features/configuration_files/overrides_defaults.feature +1 -1
  9. data/features/rake_task/rake_task.feature +14 -14
  10. data/features/reports/reports.feature +21 -19
  11. data/features/reports/yaml.feature +35 -63
  12. data/features/samples.feature +55 -54
  13. data/features/support/env.rb +8 -1
  14. data/lib/reek/cli/application.rb +22 -7
  15. data/lib/reek/cli/command.rb +4 -2
  16. data/lib/reek/cli/help_command.rb +1 -1
  17. data/lib/reek/cli/options.rb +3 -3
  18. data/lib/reek/cli/reek_command.rb +4 -8
  19. data/lib/reek/cli/report/formatter.rb +8 -5
  20. data/lib/reek/cli/report/report.rb +6 -5
  21. data/lib/reek/cli/report/strategy.rb +3 -2
  22. data/lib/reek/cli/version_command.rb +1 -1
  23. data/lib/reek/configuration/app_configuration.rb +75 -0
  24. data/lib/reek/configuration/configuration_file_finder.rb +56 -0
  25. data/lib/reek/core/code_context.rb +2 -6
  26. data/lib/reek/core/module_context.rb +4 -0
  27. data/lib/reek/core/smell_repository.rb +5 -3
  28. data/lib/reek/core/sniffer.rb +12 -8
  29. data/lib/reek/examiner.rb +7 -6
  30. data/lib/reek/rake/task.rb +10 -12
  31. data/lib/reek/smell_warning.rb +25 -43
  32. data/lib/reek/smells/attribute.rb +7 -12
  33. data/lib/reek/smells/boolean_parameter.rb +9 -9
  34. data/lib/reek/smells/class_variable.rb +7 -13
  35. data/lib/reek/smells/control_parameter.rb +8 -11
  36. data/lib/reek/smells/data_clump.rb +16 -21
  37. data/lib/reek/smells/duplicate_method_call.rb +11 -18
  38. data/lib/reek/smells/feature_envy.rb +8 -8
  39. data/lib/reek/smells/irresponsible_module.rb +6 -10
  40. data/lib/reek/smells/long_parameter_list.rb +7 -15
  41. data/lib/reek/smells/long_yield_list.rb +13 -15
  42. data/lib/reek/smells/module_initialize.rb +4 -7
  43. data/lib/reek/smells/nested_iterators.rb +6 -13
  44. data/lib/reek/smells/nil_check.rb +9 -7
  45. data/lib/reek/smells/prima_donna_method.rb +5 -7
  46. data/lib/reek/smells/repeated_conditional.rb +19 -15
  47. data/lib/reek/smells/smell_detector.rb +21 -1
  48. data/lib/reek/smells/too_many_instance_variables.rb +9 -16
  49. data/lib/reek/smells/too_many_methods.rb +10 -17
  50. data/lib/reek/smells/too_many_statements.rb +14 -14
  51. data/lib/reek/smells/uncommunicative_method_name.rb +9 -10
  52. data/lib/reek/smells/uncommunicative_module_name.rb +9 -10
  53. data/lib/reek/smells/uncommunicative_parameter_name.rb +9 -9
  54. data/lib/reek/smells/uncommunicative_variable_name.rb +9 -9
  55. data/lib/reek/smells/unused_parameters.rb +8 -20
  56. data/lib/reek/smells/utility_function.rb +12 -10
  57. data/lib/reek/source.rb +0 -1
  58. data/lib/reek/source/code_comment.rb +1 -0
  59. data/lib/reek/source/source_code.rb +3 -13
  60. data/lib/reek/source/source_file.rb +0 -14
  61. data/lib/reek/source/source_repository.rb +7 -0
  62. data/lib/reek/spec/should_reek_of.rb +3 -3
  63. data/lib/reek/spec/should_reek_only_of.rb +2 -2
  64. data/lib/reek/version.rb +1 -1
  65. data/reek.gemspec +4 -2
  66. data/spec/factories/factories.rb +32 -0
  67. data/spec/matchers/smell_of_matcher.rb +3 -2
  68. data/spec/reek/cli/report_spec.rb +2 -1
  69. data/spec/reek/configuration/app_configuration_spec.rb +67 -0
  70. data/spec/reek/configuration/configuration_file_finder_spec.rb +35 -0
  71. data/spec/reek/core/code_context_spec.rb +1 -1
  72. data/spec/reek/core/module_context_spec.rb +5 -1
  73. data/spec/reek/core/smell_configuration_spec.rb +21 -13
  74. data/spec/reek/core/warning_collector_spec.rb +4 -1
  75. data/spec/reek/examiner_spec.rb +19 -1
  76. data/spec/reek/smell_warning_spec.rb +42 -36
  77. data/spec/reek/smells/attribute_spec.rb +6 -2
  78. data/spec/reek/smells/boolean_parameter_spec.rb +11 -12
  79. data/spec/reek/smells/class_variable_spec.rb +16 -6
  80. data/spec/reek/smells/control_parameter_spec.rb +17 -19
  81. data/spec/reek/smells/data_clump_spec.rb +25 -15
  82. data/spec/reek/smells/duplicate_method_call_spec.rb +18 -12
  83. data/spec/reek/smells/feature_envy_spec.rb +29 -10
  84. data/spec/reek/smells/irresponsible_module_spec.rb +7 -7
  85. data/spec/reek/smells/long_parameter_list_spec.rb +16 -10
  86. data/spec/reek/smells/long_yield_list_spec.rb +2 -2
  87. data/spec/reek/smells/module_initialize_spec.rb +26 -0
  88. data/spec/reek/smells/nested_iterators_spec.rb +21 -10
  89. data/spec/reek/smells/nil_check_spec.rb +0 -2
  90. data/spec/reek/smells/prima_donna_method_spec.rb +3 -3
  91. data/spec/reek/smells/repeated_conditional_spec.rb +0 -26
  92. data/spec/reek/smells/smell_detector_shared.rb +4 -4
  93. data/spec/reek/smells/too_many_instance_variables_spec.rb +3 -3
  94. data/spec/reek/smells/too_many_methods_spec.rb +16 -11
  95. data/spec/reek/smells/too_many_statements_spec.rb +55 -18
  96. data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -2
  97. data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
  98. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
  99. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +28 -21
  100. data/spec/reek/smells/unused_parameters_spec.rb +3 -5
  101. data/spec/reek/smells/utility_function_spec.rb +2 -1
  102. data/spec/reek/source/code_comment_spec.rb +7 -2
  103. data/spec/reek/source/reference_collector_spec.rb +0 -1
  104. data/spec/reek/source/sexp_extensions_spec.rb +0 -15
  105. data/spec/reek/source/source_code_spec.rb +13 -1
  106. data/spec/reek/spec/should_reek_only_of_spec.rb +22 -10
  107. data/spec/reek/spec/should_reek_spec.rb +6 -2
  108. data/spec/samples/minimal_smelly_and_masked/config.reek +7 -0
  109. data/spec/samples/minimal_smelly_and_masked/minimal_dirty.rb +4 -0
  110. data/spec/samples/simple_configuration.reek +5 -0
  111. data/spec/samples/standard_smelly/dirty.rb +8 -0
  112. data/spec/samples/standard_smelly/minimal_dirty.rb +4 -0
  113. data/spec/spec_helper.rb +20 -0
  114. data/tasks/develop.rake +1 -1
  115. data/tasks/rubocop.rake +5 -0
  116. metadata +41 -6
  117. data/lib/reek/config_file_exception.rb +0 -7
  118. data/lib/reek/smell_description.rb +0 -26
  119. data/lib/reek/source/config_file.rb +0 -88
  120. data/spec/reek/smell_description_spec.rb +0 -43
@@ -12,7 +12,6 @@ describe ControlParameter do
12
12
 
13
13
  it_should_behave_like 'SmellDetector'
14
14
 
15
-
16
15
  context 'parameter not used to determine code path' do
17
16
  it 'does not report a ternary check on an ivar' do
18
17
  src = 'def simple(arga) @ivar ? arga : 3 end'
@@ -35,76 +34,75 @@ describe ControlParameter do
35
34
  end
36
35
  end
37
36
 
38
-
39
37
  context 'parameter only used to determine code path' do
40
38
  it 'reports a ternary check on a parameter' do
41
39
  src = 'def simple(arga) arga ? @ivar : 3 end'
42
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arga')
40
+ expect(src).to smell_of(ControlParameter, name: 'arga')
43
41
  end
44
42
 
45
43
  it 'reports a couple inside a block' do
46
44
  src = 'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end'
47
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
45
+ expect(src).to smell_of(ControlParameter, name: 'arg')
48
46
  end
49
47
 
50
48
  it 'reports on an if statement modifier' do
51
49
  src = 'def simple(arg) args = {}; args.merge(\'a\' => \'A\') if arg end'
52
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
50
+ expect(src).to smell_of(ControlParameter, name: 'arg')
53
51
  end
54
52
 
55
53
  it 'reports on an unless statement modifier' do
56
54
  src = 'def simple(arg) args = {}; args.merge(\'a\' => \'A\') unless arg end'
57
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
55
+ expect(src).to smell_of(ControlParameter, name: 'arg')
58
56
  end
59
57
 
60
58
  it 'reports on if control expression' do
61
59
  src = 'def simple(arg) args = {}; if arg then args.merge(\'a\' => \'A\') end end'
62
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
60
+ expect(src).to smell_of(ControlParameter, name: 'arg')
63
61
  end
64
62
 
65
63
  it 'reports on if control expression with &&' do
66
64
  src = 'def simple(arg) if arg && true then puts "arg" end end'
67
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
65
+ expect(src).to smell_of(ControlParameter, name: 'arg')
68
66
  end
69
67
 
70
68
  it 'reports on if control expression with preceding &&' do
71
69
  src = 'def simple(arg) if true && arg then puts "arg" end end'
72
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
70
+ expect(src).to smell_of(ControlParameter, name: 'arg')
73
71
  end
74
72
 
75
73
  it 'reports on if control expression with two && conditions' do
76
74
  src = 'def simple(a) ag = {}; if a && true && true then puts "2" end end'
77
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'a')
75
+ expect(src).to smell_of(ControlParameter, name: 'a')
78
76
  end
79
77
 
80
78
  it 'reports on if control expression with ||' do
81
79
  src = 'def simple(arg) args = {}; if arg || true then puts "arg" end end'
82
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
80
+ expect(src).to smell_of(ControlParameter, name: 'arg')
83
81
  end
84
82
 
85
83
  it 'reports on if control expression with or' do
86
84
  src = 'def simple(arg) args = {}; if arg or true then puts "arg" end end'
87
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
85
+ expect(src).to smell_of(ControlParameter, name: 'arg')
88
86
  end
89
87
 
90
88
  it 'reports on if control expression with if' do
91
89
  src = 'def simple(arg) args = {}; if (arg if true) then puts "arg" end end'
92
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
90
+ expect(src).to smell_of(ControlParameter, name: 'arg')
93
91
  end
94
92
 
95
93
  it 'reports on && notation' do
96
94
  src = 'def simple(arg) args = {}; arg && args.merge(\'a\' => \'A\') end'
97
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
95
+ expect(src).to smell_of(ControlParameter, name: 'arg')
98
96
  end
99
97
 
100
98
  it 'reports on || notation' do
101
99
  src = 'def simple(arg) args = {}; arg || args.merge(\'a\' => \'A\') end'
102
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
100
+ expect(src).to smell_of(ControlParameter, name: 'arg')
103
101
  end
104
102
 
105
103
  it 'reports on case statement' do
106
104
  src = 'def simple(arg) case arg when nil; nil when false; nil else nil end end'
107
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
105
+ expect(src).to smell_of(ControlParameter, name: 'arg')
108
106
  end
109
107
 
110
108
  it 'reports on nested if statements that are both control parameters' do
@@ -116,7 +114,7 @@ describe ControlParameter do
116
114
  end
117
115
  end
118
116
  EOS
119
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
117
+ expect(src).to smell_of(ControlParameter, name: 'arg')
120
118
  end
121
119
 
122
120
  it 'reports on nested if statements where the inner if is a control parameter' do
@@ -128,7 +126,7 @@ describe ControlParameter do
128
126
  end
129
127
  end
130
128
  EOS
131
- expect(src).to smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
129
+ expect(src).to smell_of(ControlParameter, name: 'arg')
132
130
  end
133
131
 
134
132
  it 'reports on explicit comparison in the condition' do
@@ -285,7 +283,7 @@ describe ControlParameter do
285
283
  it_should_behave_like 'common fields set correctly'
286
284
 
287
285
  it 'has the correct fields' do
288
- expect(@warning.smell[ControlParameter::PARAMETER_KEY]).to eq('arg')
286
+ expect(@warning.parameters[:name]).to eq('arg')
289
287
  expect(@warning.lines).to eq([3, 5])
290
288
  end
291
289
  end
@@ -27,29 +27,27 @@ EOS
27
27
  def third(pa, pb) pa - pb + @fred; end
28
28
  end
29
29
  EOS
30
- ctx = CodeContext.new(nil, @src.to_reek_source.syntax_tree)
30
+ ctx = ModuleContext.new(nil, @src.to_reek_source.syntax_tree)
31
31
  detector = DataClump.new('newt')
32
32
  @smells = detector.examine_context(ctx)
33
- @warning = @smells[0] # SMELL: too cumbersome!
34
- @yaml = @warning.to_yaml
35
33
  end
36
34
  it 'records only the one smell' do
37
35
  expect(@smells.length).to eq(1)
38
36
  end
39
37
  it 'reports all parameters' do
40
- expect(@smells[0].smell[DataClump::PARAMETERS_KEY]).to eq(['pa', 'pb'])
38
+ expect(@smells[0].parameters[:parameters]).to eq(['pa', 'pb'])
41
39
  end
42
40
  it 'reports the number of occurrences' do
43
- expect(@smells[0].smell[DataClump::OCCURRENCES_KEY]).to eq(3)
41
+ expect(@smells[0].parameters[:count]).to eq(3)
44
42
  end
45
43
  it 'reports all methods' do
46
- expect(@smells[0].smell[DataClump::METHODS_KEY]).to eq(['first', 'second', 'third'])
44
+ expect(@smells[0].parameters[:methods]).to eq(['first', 'second', 'third'])
47
45
  end
48
46
  it 'reports the declaration line numbers' do
49
47
  expect(@smells[0].lines).to eq([2, 3, 4])
50
48
  end
51
49
  it 'reports the correct smell class' do
52
- expect(@smells[0].smell_class).to eq(DataClump::SMELL_CLASS)
50
+ expect(@smells[0].smell_category).to eq(DataClump.smell_category)
53
51
  end
54
52
  it 'reports the context fq name' do
55
53
  expect(@smells[0].context).to eq(@module_name)
@@ -65,8 +63,8 @@ EOS
65
63
  end
66
64
  EOS
67
65
  expect(src).to smell_of(DataClump,
68
- DataClump::OCCURRENCES_KEY => 3,
69
- DataClump::PARAMETERS_KEY => ['pa', 'pb'])
66
+ count: 3,
67
+ parameters: ['pa', 'pb'])
70
68
  end
71
69
 
72
70
  it 'reports 3 identical parameter sets' do
@@ -78,8 +76,8 @@ EOS
78
76
  end
79
77
  EOS
80
78
  expect(src).to smell_of(DataClump,
81
- DataClump::OCCURRENCES_KEY => 3,
82
- DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc'])
79
+ count: 3,
80
+ parameters: ['pa', 'pb', 'pc'])
83
81
  end
84
82
 
85
83
  it 'reports re-ordered identical parameter sets' do
@@ -91,8 +89,8 @@ EOS
91
89
  end
92
90
  EOS
93
91
  expect(src).to smell_of(DataClump,
94
- DataClump::OCCURRENCES_KEY => 3,
95
- DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc'])
92
+ count: 3,
93
+ parameters: ['pa', 'pb', 'pc'])
96
94
  end
97
95
 
98
96
  it 'counts only identical parameter sets' do
@@ -116,7 +114,7 @@ EOS
116
114
  def c_raw_singleton (src, options) end
117
115
  end
118
116
  EOS
119
- expect(src).to smell_of(DataClump, DataClump::OCCURRENCES_KEY => 5)
117
+ expect(src).to smell_of(DataClump, count: 5)
120
118
  end
121
119
 
122
120
  it 'correctly checks number of occurences' do
@@ -141,7 +139,19 @@ EOS
141
139
  end
142
140
  EOS
143
141
  expect(src).to smell_of(DataClump,
144
- DataClump::PARAMETERS_KEY => %w(p1 p2))
142
+ parameters: %w(p1 p2))
143
+ end
144
+
145
+ it 'ignores anonymous parameters' do
146
+ src = <<-EOS
147
+ #{@context} Smelly
148
+ def fa(p1, p2, *) end
149
+ def fb(p1, p2, *) end
150
+ def fc(p1, p2, *) end
151
+ end
152
+ EOS
153
+ expect(src).to smell_of(DataClump,
154
+ parameters: %w(p1 p2))
145
155
  end
146
156
  end
147
157
 
@@ -8,7 +8,6 @@ include Reek
8
8
  include Reek::Smells
9
9
 
10
10
  describe DuplicateMethodCall do
11
-
12
11
  context 'when a smell is reported' do
13
12
  before :each do
14
13
  @source_name = 'copy-cat'
@@ -30,7 +29,7 @@ EOS
30
29
  it_should_behave_like 'common fields set correctly'
31
30
 
32
31
  it 'reports the call' do
33
- expect(@warning.smell[DuplicateMethodCall::CALL_KEY]).to eq('other[@thing]')
32
+ expect(@warning.parameters[:name]).to eq('other[@thing]')
34
33
  end
35
34
  it 'reports the correct lines' do
36
35
  expect(@warning.lines).to eq([2, 4])
@@ -40,20 +39,20 @@ EOS
40
39
  context 'with repeated method calls' do
41
40
  it 'reports repeated call' do
42
41
  src = 'def double_thing() @other.thing + @other.thing end'
43
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing')
42
+ expect(src).to smell_of(DuplicateMethodCall, name: '@other.thing')
44
43
  end
45
44
  it 'reports repeated call to lvar' do
46
45
  src = 'def double_thing(other) other[@thing] + other[@thing] end'
47
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => 'other[@thing]')
46
+ expect(src).to smell_of(DuplicateMethodCall, name: 'other[@thing]')
48
47
  end
49
48
  it 'reports call parameters' do
50
49
  src = 'def double_thing() @other.thing(2,3) + @other.thing(2,3) end'
51
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing(2, 3)')
50
+ expect(src).to smell_of(DuplicateMethodCall, name: '@other.thing(2, 3)')
52
51
  end
53
52
  it 'should report nested calls' do
54
53
  src = 'def double_thing() @other.thing.foo + @other.thing.foo end'
55
- expect(src).to smell_of(DuplicateMethodCall, { DuplicateMethodCall::CALL_KEY => '@other.thing' },
56
- DuplicateMethodCall::CALL_KEY => '@other.thing.foo')
54
+ expect(src).to smell_of(DuplicateMethodCall, { name: '@other.thing' },
55
+ { name: '@other.thing.foo' })
57
56
  end
58
57
  it 'should ignore calls to new' do
59
58
  src = 'def double_thing() @other.new + @other.new end'
@@ -124,7 +123,7 @@ EOS
124
123
  context 'with repeated attribute assignment' do
125
124
  it 'reports repeated assignment' do
126
125
  src = 'def double_thing(thing) @other[thing] = true; @other[thing] = true; end'
127
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other[thing] = true')
126
+ expect(src).to smell_of(DuplicateMethodCall, name: '@other[thing] = true')
128
127
  end
129
128
  it 'does not report multi-assignments' do
130
129
  src = <<EOS
@@ -161,8 +160,13 @@ EOS
161
160
  expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
162
161
  end
163
162
  it 'reports quadruple calls' do
164
- src = 'def double_thing() @other.thing + @other.thing + @other.thing + @other.thing end'
165
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing', DuplicateMethodCall::OCCURRENCES_KEY => 4).with_config(@config)
163
+ src = '
164
+ def double_thing()
165
+ @other.thing + @other.thing + @other.thing + @other.thing
166
+ end
167
+ '
168
+ expect(src).to smell_of(DuplicateMethodCall, name: '@other.thing', count: 4).
169
+ with_config(@config)
166
170
  end
167
171
  end
168
172
 
@@ -176,11 +180,13 @@ EOS
176
180
  end
177
181
  it 'reports calls to other methods' do
178
182
  src = 'def double_other_thing() @other.thing + @other.thing end'
179
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing').with_config(@config)
183
+ expect(src).to smell_of(DuplicateMethodCall, name: '@other.thing').
184
+ with_config(@config)
180
185
  end
181
186
  it 'does not report calls to methods specifed with a regular expression' do
182
187
  src = 'def double_puts() puts @other.thing; puts @other.thing end'
183
- expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing').with_config(@config)
188
+ expect(src).to smell_of(DuplicateMethodCall, name: '@other.thing').
189
+ with_config(@config)
184
190
  end
185
191
  end
186
192
  end
@@ -69,7 +69,11 @@ EOS
69
69
 
70
70
  context 'with 2 calls to a parameter' do
71
71
  it 'reports the smell' do
72
- expect('def envy(arga) arga.b(arga) + arga.c(@fred) end').to reek_only_of(:FeatureEnvy, /arga/)
72
+ expect('
73
+ def envy(arga)
74
+ arga.b(arga) + arga.c(@fred)
75
+ end
76
+ ').to reek_only_of(:FeatureEnvy, /arga/)
73
77
  end
74
78
  end
75
79
 
@@ -100,15 +104,30 @@ EOS
100
104
  end
101
105
 
102
106
  it 'should not be fooled by duplication' do
103
- expect('def feed(thing) @cow.feed_to(thing.pig); @duck.feed_to(thing.pig) end').to reek_only_of(:Duplication, /thing.pig/)
107
+ expect('
108
+ def feed(thing)
109
+ @cow.feed_to(thing.pig)
110
+ @duck.feed_to(thing.pig)
111
+ end
112
+ ').to reek_only_of(:Duplication, /thing.pig/)
104
113
  end
105
114
 
106
115
  it 'should count local calls' do
107
- expect('def feed(thing) cow.feed_to(thing.pig); duck.feed_to(thing.pig) end').to reek_only_of(:Duplication, /thing.pig/)
116
+ expect('
117
+ def feed(thing)
118
+ cow.feed_to(thing.pig)
119
+ duck.feed_to(thing.pig)
120
+ end
121
+ ').to reek_only_of(:Duplication, /thing.pig/)
108
122
  end
109
123
 
110
124
  it 'should report many calls to lvar' do
111
- expect('def envy() lv = @item; lv.price + lv.tax; end').to reek_only_of(:FeatureEnvy, /lv/)
125
+ expect('
126
+ def envy()
127
+ lv = @item
128
+ lv.price + lv.tax
129
+ end
130
+ ').to reek_only_of(:FeatureEnvy, /lv/)
112
131
  #
113
132
  # def moved_version
114
133
  # price + tax
@@ -228,17 +247,17 @@ EOS
228
247
  it 'reports the source' do
229
248
  expect(@smells[0].source).to eq(@source_name)
230
249
  end
231
- it 'reports the class' do
232
- expect(@smells[0].smell_class).to eq(FeatureEnvy::SMELL_CLASS)
250
+ it 'reports the smell class' do
251
+ expect(@smells[0].smell_category).to eq(FeatureEnvy.smell_category)
233
252
  end
234
- it 'reports the subclass' do
235
- expect(@smells[0].subclass).to eq(FeatureEnvy::SMELL_SUBCLASS)
253
+ it 'reports the smell sub class' do
254
+ expect(@smells[0].smell_type).to eq(FeatureEnvy.smell_type)
236
255
  end
237
256
  it 'reports the envious receiver' do
238
- expect(@smells[0].smell[FeatureEnvy::RECEIVER_KEY]).to eq(@receiver)
257
+ expect(@smells[0].parameters[:name]).to eq(@receiver)
239
258
  end
240
259
  it 'reports the number of references' do
241
- expect(@smells[0].smell[FeatureEnvy::REFERENCES_KEY]).to eq(3)
260
+ expect(@smells[0].parameters[:count]).to eq(3)
242
261
  end
243
262
  it 'reports the referring lines' do
244
263
  skip
@@ -35,10 +35,10 @@ describe IrresponsibleModule do
35
35
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
36
36
  smells = @detector.examine_context(ctx)
37
37
  expect(smells.length).to eq(1)
38
- expect(smells[0].smell_class).to eq(IrresponsibleModule::SMELL_CLASS)
39
- expect(smells[0].subclass).to eq(IrresponsibleModule::SMELL_SUBCLASS)
38
+ expect(smells[0].smell_category).to eq(IrresponsibleModule.smell_category)
39
+ expect(smells[0].smell_type).to eq(IrresponsibleModule.smell_type)
40
40
  expect(smells[0].lines).to eq([1])
41
- expect(smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]).to eq(@bad_module_name)
41
+ expect(smells[0].parameters[:name]).to eq(@bad_module_name)
42
42
  end
43
43
 
44
44
  it 'reports a class with an empty comment' do
@@ -67,9 +67,9 @@ describe IrresponsibleModule do
67
67
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
68
68
  smells = @detector.examine_context(ctx)
69
69
  expect(smells.length).to eq(1)
70
- expect(smells[0].smell_class).to eq(IrresponsibleModule::SMELL_CLASS)
71
- expect(smells[0].subclass).to eq(IrresponsibleModule::SMELL_SUBCLASS)
72
- expect(smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]).to eq('Foo::Bar')
73
- expect(smells[0].context).to match(/#{smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]}/)
70
+ expect(smells[0].smell_category).to eq(IrresponsibleModule.smell_category)
71
+ expect(smells[0].smell_type).to eq(IrresponsibleModule.smell_type)
72
+ expect(smells[0].parameters[:name]).to eq('Foo::Bar')
73
+ expect(smells[0].context).to match(/#{smells[0].parameters['name']}/)
74
74
  end
75
75
  end
@@ -6,7 +6,6 @@ include Reek
6
6
  include Reek::Smells
7
7
 
8
8
  describe LongParameterList do
9
-
10
9
  context 'for methods with few parameters' do
11
10
  it 'should report nothing for no parameters' do
12
11
  expect('def simple; f(3);true; end').not_to smell_of(LongParameterList)
@@ -18,10 +17,15 @@ describe LongParameterList do
18
17
  expect('def simple(yep,zero) f(3);true end').not_to smell_of(LongParameterList)
19
18
  end
20
19
  it 'should not count an optional block' do
21
- expect('def simple(alpha, yep, zero, &opt) f(3);true end').not_to smell_of(LongParameterList)
20
+ src = 'def simple(alpha, yep, zero, &opt) f(3); true end'
21
+ expect(src).not_to smell_of(LongParameterList)
22
22
  end
23
23
  it 'should not report inner block with too many parameters' do
24
- src = 'def simple(yep,zero); m[3]; rand(34); f.each { |arga, argb, argc, argd| true}; end'
24
+ src = '
25
+ def simple(yep,zero)
26
+ m[3]; rand(34); f.each { |arga, argb, argc, argd| true}
27
+ end
28
+ '
25
29
  expect(src).not_to smell_of(LongParameterList)
26
30
  end
27
31
 
@@ -30,10 +34,12 @@ describe LongParameterList do
30
34
  expect('def simple(zero=nil) f(3);false end').not_to smell_of(LongParameterList)
31
35
  end
32
36
  it 'should report nothing for 2 parameters with 1 default' do
33
- expect('def simple(yep, zero=nil) f(3);false end').not_to smell_of(LongParameterList)
37
+ source = 'def simple(yep, zero=nil) f(3); false end'
38
+ expect(source).not_to smell_of(LongParameterList)
34
39
  end
35
40
  it 'should report nothing for 2 defaulted parameters' do
36
- expect('def simple(yep=4, zero=nil) f(3);false end').not_to smell_of(LongParameterList)
41
+ source = 'def simple(yep=4, zero=nil) f(3); false end'
42
+ expect(source).not_to smell_of(LongParameterList)
37
43
  end
38
44
  end
39
45
  end
@@ -41,21 +47,21 @@ describe LongParameterList do
41
47
  describe 'for methods with too many parameters' do
42
48
  it 'should report 4 parameters' do
43
49
  src = 'def simple(arga, argb, argc, argd) f(3);true end'
44
- expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 4)
50
+ expect(src).to smell_of(LongParameterList, count: 4)
45
51
  end
46
52
  it 'should report 8 parameters' do
47
53
  src = 'def simple(arga, argb, argc, argd,arge, argf, argg, argh) f(3);true end'
48
- expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 8)
54
+ expect(src).to smell_of(LongParameterList, count: 8)
49
55
  end
50
56
 
51
57
  describe 'and default values' do
52
58
  it 'should report 3 with 1 defaulted' do
53
59
  src = 'def simple(polly, queue, yep, zero=nil) f(3);false end'
54
- expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 4)
60
+ expect(src).to smell_of(LongParameterList, count: 4)
55
61
  end
56
62
  it 'should report with 3 defaulted' do
57
63
  src = 'def simple(aarg, polly=2, yep=:truth, zero=nil) f(3);false end'
58
- expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 4)
64
+ expect(src).to smell_of(LongParameterList, count: 4)
59
65
  end
60
66
  end
61
67
  end
@@ -85,7 +91,7 @@ EOS
85
91
  it_should_behave_like 'common fields set correctly'
86
92
 
87
93
  it 'reports the number of parameters' do
88
- expect(@warning.smell[LongParameterList::PARAMETER_COUNT_KEY]).to eq(4)
94
+ expect(@warning.parameters[:count]).to eq(4)
89
95
  end
90
96
  it 'reports the line number of the method' do
91
97
  expect(@warning.lines).to eq([1])