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
@@ -26,7 +26,7 @@ describe LongYieldList do
26
26
  end
27
27
  it 'should report yield with many parameters' do
28
28
  src = 'def simple(arga, argb, &blk) f(3);yield arga,argb,arga,argb; end'
29
- expect(src).to smell_of(LongYieldList, LongYieldList::PARAMETER_COUNT_KEY => 4)
29
+ expect(src).to smell_of(LongYieldList, count: 4)
30
30
  end
31
31
  it 'should not report yield of a long expression' do
32
32
  src = 'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'
@@ -50,7 +50,7 @@ EOS
50
50
  it_should_behave_like 'common fields set correctly'
51
51
 
52
52
  it 'reports the correct values' do
53
- expect(@warning.smell['parameter_count']).to eq(4)
53
+ expect(@warning.parameters[:count]).to eq(4)
54
54
  expect(@warning.lines).to eq([3])
55
55
  end
56
56
  end
@@ -16,5 +16,31 @@ describe ModuleInitialize do
16
16
  expect(src).to smell_of(ModuleInitialize)
17
17
  end
18
18
  end
19
+
20
+ context 'with method named initialize in a nested class' do
21
+ it 'does not smell' do
22
+ src = <<-EOF
23
+ module A
24
+ class B
25
+ def initialize; end
26
+ end
27
+ end
28
+ EOF
29
+ expect(src).not_to smell_of(ModuleInitialize)
30
+ end
31
+ end
32
+
33
+ context 'with method named initialize in a nested struct' do
34
+ it 'does not smell' do
35
+ src = <<-EOF
36
+ module A
37
+ B = Struct.new(:c) do
38
+ def initialize; end
39
+ end
40
+ end
41
+ EOF
42
+ expect(src).not_to smell_of(ModuleInitialize)
43
+ end
44
+ end
19
45
  end
20
46
  end
@@ -5,7 +5,6 @@ require 'reek/smells/smell_detector_shared'
5
5
  include Reek::Smells
6
6
 
7
7
  describe NestedIterators do
8
-
9
8
  context 'with no iterators' do
10
9
  it 'reports no smells' do
11
10
  src = 'def fred() nothing = true; end'
@@ -85,7 +84,7 @@ EOS
85
84
  ) { |qux| qux.quuz }
86
85
  end
87
86
  EOS
88
- expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2)
87
+ expect(src).to smell_of(NestedIterators, count: 2)
89
88
  end
90
89
 
91
90
  it 'reports the deepest level of nesting only' do
@@ -98,7 +97,7 @@ EOS
98
97
  }
99
98
  end
100
99
  EOS
101
- expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 3)
100
+ expect(src).to smell_of(NestedIterators, count: 3)
102
101
  end
103
102
 
104
103
  context 'when the allowed nesting depth is 3' do
@@ -150,18 +149,30 @@ EOS
150
149
  end
151
150
 
152
151
  it 'should report nested iterators inside the ignored iterator' do
153
- src = 'def bad(fred) @fred.ignore_me {|item| item.each {|ting| ting.each {|other| other.other} } } end'
154
- expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
152
+ src = '
153
+ def bad(fred)
154
+ @fred.ignore_me {|item| item.each {|ting| ting.each {|other| other.other} } }
155
+ end
156
+ '
157
+ expect(src).to smell_of(NestedIterators, count: 2).with_config(@config)
155
158
  end
156
159
 
157
160
  it 'should report nested iterators outside the ignored iterator' do
158
- src = 'def bad(fred) @fred.each {|item| item.each {|ting| ting.ignore_me {|other| other.other} } } end'
159
- expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
161
+ src = '
162
+ def bad(fred)
163
+ @fred.each {|item| item.each {|ting| ting.ignore_me {|other| other.other} } }
164
+ end
165
+ '
166
+ expect(src).to smell_of(NestedIterators, count: 2).with_config(@config)
160
167
  end
161
168
 
162
169
  it 'should report nested iterators with the ignored iterator between them' do
163
- src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting {|other| other.other} } } end'
164
- expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
170
+ src = '
171
+ def bad(fred)
172
+ @fred.each {|item| item.ignore_me {|ting| ting.ting {|other| other.other} } }
173
+ end
174
+ '
175
+ expect(src).to smell_of(NestedIterators, count: 2).with_config(@config)
165
176
  end
166
177
  end
167
178
  end
@@ -190,7 +201,7 @@ EOS
190
201
  it_should_behave_like 'common fields set correctly'
191
202
 
192
203
  it 'reports correct values' do
193
- expect(@warning.smell[NestedIterators::NESTING_DEPTH_KEY]).to eq(2)
204
+ expect(@warning.parameters[:count]).to eq(2)
194
205
  expect(@warning.lines).to eq([3])
195
206
  end
196
207
  end
@@ -6,9 +6,7 @@ include Reek
6
6
  include Reek::Smells
7
7
 
8
8
  describe NilCheck do
9
-
10
9
  context 'for methods' do
11
-
12
10
  it 'reports the correct line number' do
13
11
  src = <<-EOS
14
12
  def nilcheck foo
@@ -17,14 +17,14 @@ describe PrimaDonnaMethod do
17
17
  describe 'the right smell' do
18
18
  let(:detector) { PrimaDonnaMethod.new('dummy_source') }
19
19
  let(:src) { 'class C; def m!; end; end' }
20
- let(:ctx) { CodeContext.new(nil, src.to_reek_source.syntax_tree) }
20
+ let(:ctx) { ModuleContext.new(nil, src.to_reek_source.syntax_tree) }
21
21
 
22
22
  it 'should be reported' do
23
23
  smells = detector.examine_context(ctx)
24
24
  warning = smells[0]
25
25
 
26
- expect(warning.smell_class).to eq('PrimaDonnaMethod')
27
- expect(warning.subclass).to eq('PrimaDonnaMethod')
26
+ expect(warning.smell_category).to eq('PrimaDonnaMethod')
27
+ expect(warning.smell_type).to eq('PrimaDonnaMethod')
28
28
  expect(warning.lines).to eq([1])
29
29
  end
30
30
  end
@@ -75,32 +75,6 @@ EOS
75
75
  it 'knows there are three copies' do
76
76
  expect(@conds.values[1].length).to eq(3)
77
77
  end
78
-
79
- context 'looking at the YAML' do
80
- before :each do
81
- @detector.examine(@ctx)
82
- warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
83
- @yaml = warning.to_yaml
84
- end
85
- it 'reports the source' do
86
- expect(@yaml).to match(/source:\s*#{@source_name}/)
87
- end
88
- it 'reports the class' do
89
- expect(@yaml).to match(/class:\s*SimulatedPolymorphism/)
90
- end
91
- it 'reports the subclass' do
92
- expect(@yaml).to match(/subclass:\s*RepeatedConditional/)
93
- end
94
- it 'reports the expression' do
95
- expect(@yaml).to match(/expression:\s*(! )?['"]?#{@cond}["']?/)
96
- end
97
- it 'reports the number of occurrences' do
98
- expect(@yaml).to match(/occurrences:\s*3/)
99
- end
100
- it 'reports the referring lines' do
101
- expect(@yaml).to match(/lines:\s*- 4\s*- 7\s*- 12/)
102
- end
103
- end
104
78
  end
105
79
 
106
80
  context 'with a matching if and case' do
@@ -32,10 +32,10 @@ shared_examples_for 'common fields set correctly' do
32
32
  it 'reports the source' do
33
33
  expect(@warning.source).to eq(@source_name)
34
34
  end
35
- it 'reports the class' do
36
- expect(@warning.smell_class).to eq(@detector.class::SMELL_CLASS)
35
+ it 'reports the smell class' do
36
+ expect(@warning.smell_category).to eq(@detector.smell_category)
37
37
  end
38
- it 'reports the subclass' do
39
- expect(@warning.subclass).to eq(@detector.class::SMELL_SUBCLASS)
38
+ it 'reports the smell sub class' do
39
+ expect(@warning.smell_type).to eq(@detector.smell_type)
40
40
  end
41
41
  end
@@ -80,9 +80,9 @@ describe TooManyInstanceVariables do
80
80
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
81
81
  @warning = @detector.examine_context(ctx)[0]
82
82
  expect(@warning.source).to eq(@source_name)
83
- expect(@warning.smell_class).to eq('LargeClass')
84
- expect(@warning.subclass).to eq(TooManyInstanceVariables::SMELL_SUBCLASS)
85
- expect(@warning.smell[TooManyInstanceVariables::IVAR_COUNT_KEY]).to eq(10)
83
+ expect(@warning.smell_category).to eq(TooManyInstanceVariables.smell_category)
84
+ expect(@warning.smell_type).to eq(TooManyInstanceVariables.smell_type)
85
+ expect(@warning.parameters[:count]).to eq(10)
86
86
  expect(@warning.lines).to eq([2])
87
87
  end
88
88
  end
@@ -16,7 +16,6 @@ describe TooManyMethods do
16
16
  it_should_behave_like 'SmellDetector'
17
17
 
18
18
  context 'counting methods' do
19
-
20
19
  it 'should not report 25 methods' do
21
20
  src = <<EOS
22
21
  # smelly class for testing purposes
@@ -28,7 +27,7 @@ class Full
28
27
  def me41x()3 end;def me42x()3 end;def me43x()3 end;def me44x()3 end;def me45x()3 end
29
28
  end
30
29
  EOS
31
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
30
+ ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
32
31
  expect(@detector.examine_context(ctx)).to be_empty
33
32
  end
34
33
 
@@ -43,11 +42,11 @@ class Full
43
42
  def me51x()3 end
44
43
  end
45
44
  EOS
46
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
45
+ ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
47
46
  smells = @detector.examine_context(ctx)
48
47
  expect(smells.length).to eq(1)
49
- expect(smells[0].subclass).to eq(TooManyMethods::SMELL_SUBCLASS)
50
- expect(smells[0].smell[TooManyMethods::METHOD_COUNT_KEY]).to eq(26)
48
+ expect(smells[0].smell_type).to eq(TooManyMethods.smell_type)
49
+ expect(smells[0].parameters[:count]).to eq(26)
51
50
  end
52
51
  end
53
52
 
@@ -59,11 +58,17 @@ class Full
59
58
  def me11x()3 end;def me12x()3 end;def me13x()3 end;def me14x()3 end;def me15x()3 end
60
59
  def me21x()3 end;def me22x()3 end;def me23x()3 end;def me24x()3 end;def me25x()3 end
61
60
  def me31x()3 end;def me32x()3 end;def me33x()3 end;def me34x()3 end;def me35x()3 end
62
- module Hidden; def me41x()3 end;def me42x()3 end;def me43x()3 end;def me44x()3 end;def me45x()3 end; end
61
+ module Hidden
62
+ def me41x()3 end
63
+ def me42x()3 end
64
+ def me43x()3 end
65
+ def me44x()3 end
66
+ def me45x()3 end
67
+ end
63
68
  def me51x()3 end
64
69
  end
65
70
  EOS
66
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
71
+ ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
67
72
  expect(@detector.examine_context(ctx)).to be_empty
68
73
  end
69
74
  end
@@ -79,12 +84,12 @@ class Full
79
84
  def me51x()3 end
80
85
  end
81
86
  EOS
82
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
87
+ ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
83
88
  @warning = @detector.examine_context(ctx)[0]
84
89
  expect(@warning.source).to eq(@source_name)
85
- expect(@warning.smell_class).to eq('LargeClass')
86
- expect(@warning.subclass).to eq(TooManyMethods::SMELL_SUBCLASS)
87
- expect(@warning.smell[TooManyMethods::METHOD_COUNT_KEY]).to eq(26)
90
+ expect(@warning.smell_category).to eq(TooManyMethods.smell_category)
91
+ expect(@warning.smell_type).to eq(TooManyMethods.smell_type)
92
+ expect(@warning.parameters[:count]).to eq(26)
88
93
  expect(@warning.lines).to eq([1])
89
94
  end
90
95
  end
@@ -31,7 +31,11 @@ describe TooManyStatements do
31
31
  end
32
32
 
33
33
  it 'should not report initialize' do
34
- src = 'def initialize(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'
34
+ src = '
35
+ def initialize(arga)
36
+ alf = f(1); @bet = 2; @cut = 3; @dit = 4; @emp = 5; @fry = 6
37
+ end
38
+ '
35
39
  expect(src).not_to smell_of(TooManyStatements)
36
40
  end
37
41
 
@@ -134,7 +138,15 @@ describe TooManyStatements, 'does not count control statements' do
134
138
  end
135
139
 
136
140
  it 'counts 3 statements in an else' do
137
- method = process_method('def one() if val == 4; callee(); callee(); callee(); else; callee(); callee(); callee(); end; end')
141
+ method = process_method('
142
+ def one()
143
+ if val == 4
144
+ callee(); callee(); callee()
145
+ else
146
+ callee(); callee(); callee()
147
+ end
148
+ end
149
+ ')
138
150
  expect(method.num_statements).to eq(6)
139
151
  end
140
152
 
@@ -159,8 +171,8 @@ describe TooManyStatements, 'does not count control statements' do
159
171
  end
160
172
 
161
173
  it 'counts 3 statements in a while loop' do
162
- method = process_method('def one() while val < 4; callee(); callee(); callee(); end; end')
163
- expect(method.num_statements).to eq(3)
174
+ source = 'def one() while val < 4; callee(); callee(); callee(); end; end'
175
+ expect(process_method(source).num_statements).to eq(3)
164
176
  end
165
177
 
166
178
  it 'counts extra statements in a while condition' do
@@ -174,8 +186,8 @@ describe TooManyStatements, 'does not count control statements' do
174
186
  end
175
187
 
176
188
  it 'counts 3 statements in a until loop' do
177
- method = process_method('def one() until val < 4; callee(); callee(); callee(); end; end')
178
- expect(method.num_statements).to eq(3)
189
+ source = 'def one() until val < 4; callee(); callee(); callee(); end; end'
190
+ expect(process_method(source).num_statements).to eq(3)
179
191
  end
180
192
 
181
193
  it 'counts 1 statement in a for loop' do
@@ -184,8 +196,8 @@ describe TooManyStatements, 'does not count control statements' do
184
196
  end
185
197
 
186
198
  it 'counts 3 statements in a for loop' do
187
- method = process_method('def one() for i in 0..4; callee(); callee(); callee(); end; end')
188
- expect(method.num_statements).to eq(3)
199
+ source = 'def one() for i in 0..4; callee(); callee(); callee(); end; end'
200
+ expect(process_method(source).num_statements).to eq(3)
189
201
  end
190
202
 
191
203
  it 'counts 1 statement in a rescue' do
@@ -194,7 +206,15 @@ describe TooManyStatements, 'does not count control statements' do
194
206
  end
195
207
 
196
208
  it 'counts 3 statements in a rescue' do
197
- method = process_method('def one() begin; callee(); callee(); callee(); rescue; callee(); callee(); callee(); end; end')
209
+ method = process_method('
210
+ def one()
211
+ begin
212
+ callee(); callee(); callee()
213
+ rescue
214
+ callee(); callee(); callee()
215
+ end
216
+ end
217
+ ')
198
218
  expect(method.num_statements).to eq(6)
199
219
  end
200
220
 
@@ -204,17 +224,31 @@ describe TooManyStatements, 'does not count control statements' do
204
224
  end
205
225
 
206
226
  it 'counts 3 statements in a when' do
207
- method = process_method('def one() case fred; when "hi"; callee(); callee(); when "lo"; callee(); end; end')
227
+ method = process_method('
228
+ def one()
229
+ case fred
230
+ when "hi" then callee(); callee()
231
+ when "lo" then callee()
232
+ end
233
+ end
234
+ ')
208
235
  expect(method.num_statements).to eq(3)
209
236
  end
210
237
 
211
238
  it 'counts 1 statement in a case else' do
212
- method = process_method('def one() case fred; when "hi"; callee(); else; callee(); end; end')
213
- expect(method.num_statements).to eq(2)
239
+ source = 'def one() case fred; when "hi"; callee(); else; callee(); end; end'
240
+ expect(process_method(source).num_statements).to eq(2)
214
241
  end
215
242
 
216
243
  it 'counts 3 statements in a case else' do
217
- method = process_method('def one() case fred; when "hi"; callee(); callee(); callee(); else; callee(); callee(); callee(); end; end')
244
+ method = process_method('
245
+ def one()
246
+ case fred
247
+ when "hi" then callee(); callee(); callee()
248
+ else callee(); callee(); callee()
249
+ end
250
+ end
251
+ ')
218
252
  expect(method.num_statements).to eq(6)
219
253
  end
220
254
 
@@ -234,8 +268,8 @@ describe TooManyStatements, 'does not count control statements' do
234
268
  end
235
269
 
236
270
  it 'counts 4 statements in an iterator' do
237
- method = process_method('def one() fred.each do; callee(); callee(); callee(); end; end')
238
- expect(method.num_statements).to eq(4)
271
+ source = 'def one() fred.each do; callee(); callee(); callee(); end; end'
272
+ expect(process_method(source).num_statements).to eq(4)
239
273
  end
240
274
 
241
275
  it 'counts 1 statement in a singleton method' do
@@ -259,14 +293,17 @@ describe TooManyStatements do
259
293
  expect(ctx).to receive(:config_for).with(TooManyStatements).and_return({})
260
294
  @smells = @detector.examine_context(ctx)
261
295
  end
296
+
262
297
  it 'reports only 1 smell' do
263
298
  expect(@smells.length).to eq(1)
264
299
  end
300
+
265
301
  it 'reports the number of statements' do
266
- expect(@smells[0].smell[TooManyStatements::STATEMENT_COUNT_KEY]).to eq(@num_statements)
302
+ expect(@smells[0].parameters[:count]).to eq(@num_statements)
267
303
  end
268
- it 'reports the correct subclass' do
269
- expect(@smells[0].subclass).to eq(TooManyStatements::SMELL_SUBCLASS)
304
+
305
+ it 'reports the correct smell sub class' do
306
+ expect(@smells[0].smell_type).to eq(TooManyStatements.smell_type)
270
307
  end
271
308
  end
272
309
  end
@@ -17,7 +17,8 @@ describe UncommunicativeMethodName do
17
17
 
18
18
  ['help', '+', '-', '/', '*'].each do |method_name|
19
19
  it "accepts the method name '#{method_name}'" do
20
- expect("def #{method_name}(fred) basics(17) end").not_to smell_of(UncommunicativeMethodName)
20
+ src = "def #{method_name}(fred) basics(17) end"
21
+ expect(src).not_to smell_of(UncommunicativeMethodName)
21
22
  end
22
23
  end
23
24
 
@@ -33,7 +34,7 @@ describe UncommunicativeMethodName do
33
34
  it_should_behave_like 'common fields set correctly'
34
35
 
35
36
  it 'reports the correct values' do
36
- expect(@warning.smell[UncommunicativeMethodName::METHOD_NAME_KEY]).to eq(method_name)
37
+ expect(@warning.parameters[:name]).to eq(method_name)
37
38
  expect(@warning.lines).to eq([1])
38
39
  expect(@warning.context).to eq(method_name)
39
40
  end
@@ -33,10 +33,10 @@ describe UncommunicativeModuleName do
33
33
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
34
34
  smells = @detector.examine_context(ctx)
35
35
  expect(smells.length).to eq(1)
36
- expect(smells[0].smell_class).to eq(UncommunicativeModuleName::SMELL_CLASS)
37
- expect(smells[0].subclass).to eq(UncommunicativeModuleName::SMELL_SUBCLASS)
38
- expect(smells[0].smell[UncommunicativeModuleName::MODULE_NAME_KEY]).to eq('X')
39
- expect(smells[0].context).to match(/#{smells[0].smell[UncommunicativeModuleName::MODULE_NAME_KEY]}/)
36
+ expect(smells[0].smell_category).to eq(UncommunicativeModuleName.smell_category)
37
+ expect(smells[0].smell_type).to eq(UncommunicativeModuleName.smell_type)
38
+ expect(smells[0].parameters[:name]).to eq('X')
39
+ expect(smells[0].context).to match(/#{smells[0].parameters[:name]}/)
40
40
  end
41
41
  end
42
42
 
@@ -59,7 +59,7 @@ describe UncommunicativeModuleName do
59
59
  it_should_behave_like 'common fields set correctly'
60
60
 
61
61
  it 'reports the correct values' do
62
- expect(@warning.smell[UncommunicativeModuleName::MODULE_NAME_KEY]).to eq('Printer2')
62
+ expect(@warning.parameters[:name]).to eq('Printer2')
63
63
  expect(@warning.lines).to eq([1])
64
64
  end
65
65
  end