reek 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +6 -0
  3. data/README.md +15 -9
  4. data/bin/reek +1 -1
  5. data/config/defaults.reek +71 -86
  6. data/features/command_line_interface/options.feature +0 -15
  7. data/features/reports/reports.feature +23 -0
  8. data/features/samples.feature +3 -12
  9. data/lib/reek.rb +3 -3
  10. data/lib/reek/cli/application.rb +1 -1
  11. data/lib/reek/cli/command_line.rb +10 -8
  12. data/lib/reek/cli/reek_command.rb +6 -7
  13. data/lib/reek/cli/report.rb +34 -38
  14. data/lib/reek/cli/version_command.rb +1 -1
  15. data/lib/reek/cli/yaml_command.rb +1 -1
  16. data/lib/reek/core/code_parser.rb +4 -4
  17. data/lib/reek/core/hash_extensions.rb +2 -2
  18. data/lib/reek/core/method_context.rb +2 -2
  19. data/lib/reek/core/module_context.rb +4 -4
  20. data/lib/reek/core/singleton_method_context.rb +1 -1
  21. data/lib/reek/core/smell_repository.rb +7 -6
  22. data/lib/reek/core/sniffer.rb +4 -4
  23. data/lib/reek/examiner.rb +10 -3
  24. data/lib/reek/smell_warning.rb +0 -2
  25. data/lib/reek/smells.rb +22 -21
  26. data/lib/reek/smells/attribute.rb +4 -8
  27. data/lib/reek/smells/boolean_parameter.rb +2 -2
  28. data/lib/reek/smells/class_variable.rb +3 -2
  29. data/lib/reek/smells/{control_couple.rb → control_parameter.rb} +5 -5
  30. data/lib/reek/smells/data_clump.rb +13 -29
  31. data/lib/reek/smells/{duplication.rb → duplicate_method_call.rb} +9 -11
  32. data/lib/reek/smells/feature_envy.rb +2 -2
  33. data/lib/reek/smells/irresponsible_module.rb +3 -2
  34. data/lib/reek/smells/long_parameter_list.rb +6 -10
  35. data/lib/reek/smells/long_yield_list.rb +4 -8
  36. data/lib/reek/smells/nested_iterators.rb +31 -25
  37. data/lib/reek/smells/nil_check.rb +11 -12
  38. data/lib/reek/smells/{simulated_polymorphism.rb → repeated_conditional.rb} +6 -10
  39. data/lib/reek/smells/smell_detector.rb +3 -6
  40. data/lib/reek/smells/too_many_instance_variables.rb +60 -0
  41. data/lib/reek/smells/too_many_methods.rb +62 -0
  42. data/lib/reek/smells/{long_method.rb → too_many_statements.rb} +7 -12
  43. data/lib/reek/smells/uncommunicative_method_name.rb +3 -7
  44. data/lib/reek/smells/uncommunicative_module_name.rb +3 -7
  45. data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
  46. data/lib/reek/smells/uncommunicative_variable_name.rb +5 -9
  47. data/lib/reek/smells/unused_parameters.rb +62 -13
  48. data/lib/reek/smells/utility_function.rb +3 -7
  49. data/lib/reek/source.rb +8 -8
  50. data/lib/reek/source/core_extras.rb +1 -1
  51. data/lib/reek/source/source_code.rb +2 -2
  52. data/lib/reek/source/source_file.rb +2 -2
  53. data/lib/reek/source/source_locator.rb +1 -1
  54. data/lib/reek/source/source_repository.rb +4 -2
  55. data/lib/reek/spec.rb +9 -3
  56. data/lib/reek/spec/should_reek.rb +2 -2
  57. data/lib/reek/spec/should_reek_of.rb +1 -1
  58. data/lib/reek/spec/should_reek_only_of.rb +2 -2
  59. data/lib/reek/version.rb +1 -1
  60. data/reek.gemspec +3 -1
  61. data/spec/gem/updates_spec.rb +1 -1
  62. data/spec/gem/yard_spec.rb +1 -1
  63. data/spec/matchers/smell_of_matcher.rb +53 -19
  64. data/spec/reek/cli/help_command_spec.rb +2 -2
  65. data/spec/reek/cli/reek_command_spec.rb +6 -6
  66. data/spec/reek/cli/report_spec.rb +6 -6
  67. data/spec/reek/cli/version_command_spec.rb +2 -2
  68. data/spec/reek/cli/yaml_command_spec.rb +2 -2
  69. data/spec/reek/core/code_context_spec.rb +4 -4
  70. data/spec/reek/core/code_parser_spec.rb +2 -2
  71. data/spec/reek/core/config_spec.rb +4 -4
  72. data/spec/reek/core/method_context_spec.rb +3 -3
  73. data/spec/reek/core/module_context_spec.rb +3 -3
  74. data/spec/reek/core/object_refs_spec.rb +3 -3
  75. data/spec/reek/core/singleton_method_context_spec.rb +4 -4
  76. data/spec/reek/core/smell_configuration_spec.rb +2 -2
  77. data/spec/reek/core/stop_context_spec.rb +2 -2
  78. data/spec/reek/core/warning_collector_spec.rb +3 -3
  79. data/spec/reek/examiner_spec.rb +13 -4
  80. data/spec/reek/smell_warning_spec.rb +2 -2
  81. data/spec/reek/smells/attribute_spec.rb +4 -4
  82. data/spec/reek/smells/boolean_parameter_spec.rb +3 -3
  83. data/spec/reek/smells/class_variable_spec.rb +4 -4
  84. data/spec/reek/smells/{control_couple_spec.rb → control_parameter_spec.rb} +10 -10
  85. data/spec/reek/smells/data_clump_spec.rb +3 -3
  86. data/spec/reek/smells/{duplication_spec.rb → duplicate_method_call_spec.rb} +42 -26
  87. data/spec/reek/smells/feature_envy_spec.rb +3 -3
  88. data/spec/reek/smells/irresponsible_module_spec.rb +3 -3
  89. data/spec/reek/smells/long_parameter_list_spec.rb +3 -3
  90. data/spec/reek/smells/long_yield_list_spec.rb +3 -3
  91. data/spec/reek/smells/nested_iterators_spec.rb +42 -4
  92. data/spec/reek/smells/nil_check_spec.rb +23 -11
  93. data/spec/reek/smells/{simulated_polymorphism_spec.rb → repeated_conditional_spec.rb} +6 -6
  94. data/spec/reek/smells/smell_detector_shared.rb +2 -2
  95. data/spec/reek/smells/too_many_instance_variables_spec.rb +62 -0
  96. data/spec/reek/smells/{large_class_spec.rb → too_many_methods_spec.rb} +11 -56
  97. data/spec/reek/smells/{long_method_spec.rb → too_many_statements_spec.rb} +17 -17
  98. data/spec/reek/smells/uncommunicative_method_name_spec.rb +5 -5
  99. data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
  100. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
  101. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +5 -5
  102. data/spec/reek/smells/unused_parameters_spec.rb +19 -4
  103. data/spec/reek/smells/utility_function_spec.rb +3 -3
  104. data/spec/reek/source/code_comment_spec.rb +2 -2
  105. data/spec/reek/source/object_source_spec.rb +1 -1
  106. data/spec/reek/source/reference_collector_spec.rb +2 -2
  107. data/spec/reek/source/sexp_formatter_spec.rb +2 -2
  108. data/spec/reek/source/source_code_spec.rb +2 -2
  109. data/spec/reek/source/tree_dresser_spec.rb +2 -2
  110. data/spec/reek/spec/should_reek_of_spec.rb +2 -2
  111. data/spec/reek/spec/should_reek_only_of_spec.rb +2 -2
  112. data/spec/reek/spec/should_reek_spec.rb +2 -2
  113. data/spec/samples/all_but_one_masked/masked.reek +1 -1
  114. data/spec/samples/clean_due_to_masking/masked.reek +1 -1
  115. data/spec/samples/config/allow_duplication.reek +2 -2
  116. data/spec/samples/inline_config/dirty.rb +2 -2
  117. data/spec/samples/mask_some/some.reek +1 -1
  118. data/spec/samples/masked_by_dotfile/dirty.rb +8 -0
  119. data/spec/samples/not_quite_masked/smelly.rb +3 -0
  120. data/spec/samples/overrides/masked/lower.reek +1 -1
  121. data/spec/samples/overrides/upper.reek +1 -1
  122. data/spec/spec_helper.rb +4 -9
  123. data/tasks/test.rake +0 -2
  124. metadata +253 -263
  125. data/lib/reek/smells/large_class.rb +0 -87
  126. data/lib/xp.reek +0 -66
  127. data/spec/gem/manifest_spec.rb +0 -22
  128. data/spec/spec.opts +0 -1
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'feature_envy')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/feature_envy'
3
+ require 'reek/smells/smell_detector_shared'
4
4
 
5
5
  include Reek
6
6
  include Reek::Smells
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'irresponsible_module')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/irresponsible_module'
3
+ require 'reek/smells/smell_detector_shared'
4
4
  include Reek::Smells
5
5
 
6
6
  describe IrresponsibleModule do
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'long_parameter_list')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/long_parameter_list'
3
+ require 'reek/smells/smell_detector_shared'
4
4
 
5
5
  include Reek
6
6
  include Reek::Smells
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'long_yield_list')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/long_yield_list'
3
+ require 'reek/smells/smell_detector_shared'
4
4
 
5
5
  include Reek
6
6
  include Reek::Smells
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'nested_iterators')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/nested_iterators'
3
+ require 'reek/smells/smell_detector_shared'
4
4
 
5
5
  include Reek::Smells
6
6
 
@@ -51,7 +51,45 @@ def bad(fred)
51
51
  @jim.each {|ting| ting.each {|piece| @hal.send} }
52
52
  end
53
53
  EOS
54
- src.should smell_of(NestedIterators, {}, {})
54
+ src.should smell_of(NestedIterators, {})
55
+ end
56
+
57
+ it 'reports nested iterators only once per method even if levels are different' do
58
+ src = <<-EOS
59
+ def bad(fred)
60
+ @fred.each {|item| item.each {|part| part.foo} }
61
+ @jim.each {|ting| ting.each {|piece| piece.each {|atom| atom.foo } } }
62
+ end
63
+ EOS
64
+ src.should smell_of(NestedIterators, {})
65
+ end
66
+
67
+ it 'reports nesting inside iterator arguments' do
68
+ src = <<-EOS
69
+ def bad(fred, ted)
70
+ fred.foo(
71
+ ted.each {|item|
72
+ item.each {|part|
73
+ part.baz
74
+ }
75
+ }
76
+ ) { |qux| qux.quuz }
77
+ end
78
+ EOS
79
+ src.should smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2)
80
+ end
81
+
82
+ it 'reports the deepest level of nesting only' do
83
+ src = <<-EOS
84
+ def bad(fred)
85
+ fred.each {|item|
86
+ item.each {|part|
87
+ part.each {|sub| sub.foobar}
88
+ }
89
+ }
90
+ end
91
+ EOS
92
+ src.should smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 3)
55
93
  end
56
94
 
57
95
  context 'when the allowed nesting depth is 3' do
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'nil_check')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/nil_check'
3
+ require 'reek/smells/smell_detector_shared'
4
4
 
5
5
  include Reek
6
6
  include Reek::Smells
@@ -9,19 +9,31 @@ describe NilCheck do
9
9
 
10
10
  context 'for methods' do
11
11
 
12
+ it 'reports the correct line number' do
13
+ src = <<-EOS
14
+ def nilcheck foo
15
+ foo.nil?
16
+ end
17
+ EOS
18
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
19
+ detector = NilCheck.new('source_name')
20
+ smells = detector.examine_context(ctx)
21
+ smells[0].lines.should eq [2]
22
+ end
23
+
12
24
  it 'should report nothing when scope includes no nil checks' do
13
25
  'def no_nils; end'.should_not smell_of(NilCheck)
14
26
  end
15
27
 
16
28
  it 'should report when scope uses multiple nil? methods' do
17
29
  src = <<-eos
18
- def chk_multi_nil(para)
19
- para.nil?
30
+ def chk_multi_nil(para)
31
+ para.nil?
20
32
  puts "Hello"
21
- \"\".nil?
33
+ \"\".nil?
22
34
  end
23
35
  eos
24
- src.should smell_of(NilCheck,
36
+ src.should smell_of(NilCheck,
25
37
  {NilCheck => nil}, {NilCheck => nil})
26
38
  end
27
39
 
@@ -42,16 +54,16 @@ describe NilCheck do
42
54
 
43
55
  it 'should report when scope uses multiple case-clauses checking nil' do
44
56
  src = <<-eos
45
- def caseNil
46
- case @inst_var
47
- when nil then puts "Nil"
57
+ def case_nil
58
+ case @inst_var
59
+ when nil then puts "Nil"
48
60
  end
49
61
  puts "Hello"
50
62
  case @inst_var2
51
63
  when 1 then puts 1
52
64
  when nil then puts nil.inspect
53
65
  end
54
- end
66
+ end
55
67
  eos
56
68
  src.should smell_of(NilCheck,
57
69
  {NilCheck => nil}, {NilCheck => nil})
@@ -1,15 +1,15 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'simulated_polymorphism')
3
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_context')
4
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/repeated_conditional'
3
+ require 'reek/core/code_context'
4
+ require 'reek/smells/smell_detector_shared'
5
5
 
6
6
  include Reek::Core
7
7
  include Reek::Smells
8
8
 
9
- describe SimulatedPolymorphism do
9
+ describe RepeatedConditional do
10
10
  before :each do
11
11
  @source_name = 'howdy-doody'
12
- @detector = SimulatedPolymorphism.new(@source_name)
12
+ @detector = RepeatedConditional.new(@source_name)
13
13
  end
14
14
 
15
15
  it_should_behave_like 'SmellDetector'
@@ -1,5 +1,5 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'smell_configuration')
1
+ require 'spec_helper'
2
+ require 'reek/core/smell_configuration'
3
3
 
4
4
  include Reek::Core
5
5
 
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'reek/smells/too_many_instance_variables'
3
+ require 'reek/examiner'
4
+ require 'reek/core/code_parser'
5
+ require 'reek/smells/smell_detector_shared'
6
+
7
+ include Reek
8
+ include Reek::Smells
9
+
10
+ describe TooManyInstanceVariables do
11
+ before(:each) do
12
+ @source_name = 'elephant'
13
+ @detector = TooManyInstanceVariables.new(@source_name)
14
+ end
15
+
16
+ it_should_behave_like 'SmellDetector'
17
+
18
+ context 'counting instance variables' do
19
+ it 'should not report 9 ivars' do
20
+ '# clean class for testing purposes
21
+ class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=4; end;end'.should_not reek
22
+ end
23
+
24
+ it 'counts each ivar only once' do
25
+ '# clean class for testing purposes
26
+ class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=4;@aa=3; end;end'.should_not reek
27
+ end
28
+
29
+ it 'should report 10 ivars' do
30
+ '# smelly class for testing purposes
31
+ class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj=4; end;end'.should reek_only_of(:TooManyInstanceVariables)
32
+ end
33
+
34
+ it 'should not report 10 ivars in 2 extensions' do
35
+ src = <<EOS
36
+ # clean class for testing purposes
37
+ class Full;def ivars_a() @aa=@ab=@ac=@ad=@ae; end;end
38
+ # clean class for testing purposes
39
+ class Full;def ivars_b() @af=@ag=@ah=@ai=@aj; end;end
40
+ EOS
41
+ src.should_not reek
42
+ end
43
+ end
44
+
45
+ it 'reports correctly when the class has 10 instance variables' do
46
+ src = <<EOS
47
+ # smelly class for testing purposes
48
+ class Empty
49
+ def ivars
50
+ @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj=4
51
+ end
52
+ end
53
+ EOS
54
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
55
+ @warning = @detector.examine_context(ctx)[0]
56
+ @warning.source.should == @source_name
57
+ @warning.smell_class.should == 'LargeClass'
58
+ @warning.subclass.should == TooManyInstanceVariables::SMELL_SUBCLASS
59
+ @warning.smell[TooManyInstanceVariables::IVAR_COUNT_KEY].should == 10
60
+ @warning.lines.should == [2]
61
+ end
62
+ end
@@ -1,47 +1,20 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'large_class')
3
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'examiner')
4
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_parser')
5
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/too_many_methods'
3
+ require 'reek/examiner'
4
+ require 'reek/core/code_parser'
5
+ require 'reek/smells/smell_detector_shared'
6
6
 
7
7
  include Reek
8
8
  include Reek::Smells
9
9
 
10
- describe LargeClass do
10
+ describe TooManyMethods do
11
11
  before(:each) do
12
12
  @source_name = 'elephant'
13
- @detector = LargeClass.new(@source_name)
13
+ @detector = TooManyMethods.new(@source_name)
14
14
  end
15
15
 
16
16
  it_should_behave_like 'SmellDetector'
17
17
 
18
- context 'counting instance variables' do
19
- it 'should not report 9 ivars' do
20
- '# clean class for testing purposes
21
- class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=4; end;end'.should_not reek
22
- end
23
-
24
- it 'counts each ivar only once' do
25
- '# clean class for testing purposes
26
- class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=4;@aa=3; end;end'.should_not reek
27
- end
28
-
29
- it 'should report 10 ivars' do
30
- '# smelly class for testing purposes
31
- class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj=4; end;end'.should reek_only_of(:LargeClass)
32
- end
33
-
34
- it 'should not report 10 ivars in 2 extensions' do
35
- src = <<EOS
36
- # clean class for testing purposes
37
- class Full;def ivars_a() @aa=@ab=@ac=@ad=@ae; end;end
38
- # clean class for testing purposes
39
- class Full;def ivars_b() @af=@ag=@ah=@ai=@aj; end;end
40
- EOS
41
- src.should_not reek
42
- end
43
- end
44
-
45
18
  context 'counting methods' do
46
19
 
47
20
  it 'should not report 25 methods' do
@@ -73,8 +46,8 @@ EOS
73
46
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
74
47
  smells = @detector.examine_context(ctx)
75
48
  smells.length.should == 1
76
- smells[0].subclass.should == LargeClass::SUBCLASS_TOO_MANY_METHODS
77
- smells[0].smell[LargeClass::METHOD_COUNT_KEY].should == 26
49
+ smells[0].subclass.should == TooManyMethods::SMELL_SUBCLASS
50
+ smells[0].smell[TooManyMethods::METHOD_COUNT_KEY].should == 26
78
51
  end
79
52
  end
80
53
 
@@ -110,26 +83,8 @@ EOS
110
83
  @warning = @detector.examine_context(ctx)[0]
111
84
  @warning.source.should == @source_name
112
85
  @warning.smell_class.should == 'LargeClass'
113
- @warning.subclass.should == LargeClass::SUBCLASS_TOO_MANY_METHODS
114
- @warning.smell[LargeClass::METHOD_COUNT_KEY].should == 26
86
+ @warning.subclass.should == TooManyMethods::SMELL_SUBCLASS
87
+ @warning.smell[TooManyMethods::METHOD_COUNT_KEY].should == 26
115
88
  @warning.lines.should == [1]
116
89
  end
117
-
118
- it 'reports correctly when the class has 30 instance variables' do
119
- src = <<EOS
120
- # smelly class for testing purposes
121
- class Empty
122
- def ivars
123
- @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj=4
124
- end
125
- end
126
- EOS
127
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
128
- @warning = @detector.examine_context(ctx)[0]
129
- @warning.source.should == @source_name
130
- @warning.smell_class.should == 'LargeClass'
131
- @warning.subclass.should == LargeClass::SUBCLASS_TOO_MANY_IVARS
132
- @warning.smell[LargeClass::IVAR_COUNT_KEY].should == 10
133
- @warning.lines.should == [2]
134
- end
135
90
  end
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'long_method')
3
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_parser')
4
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'sniffer')
5
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
1
+ require 'spec_helper'
2
+ require 'reek/smells/too_many_statements'
3
+ require 'reek/core/code_parser'
4
+ require 'reek/core/sniffer'
5
+ require 'reek/smells/smell_detector_shared'
6
6
 
7
7
  include Reek
8
8
  include Reek::Smells
@@ -19,20 +19,20 @@ def process_singleton_method(src)
19
19
  Core::CodeParser.new(sniffer).process_defs(source.syntax_tree)
20
20
  end
21
21
 
22
- describe LongMethod do
22
+ describe TooManyStatements do
23
23
  it 'should not report short methods' do
24
24
  src = 'def short(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;end'
25
- src.should_not smell_of(LongMethod)
25
+ src.should_not smell_of(TooManyStatements)
26
26
  end
27
27
 
28
28
  it 'should report long methods' do
29
29
  src = 'def long() alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'
30
- src.should reek_only_of(:LongMethod, /6 statements/)
30
+ src.should reek_only_of(:TooManyStatements, /6 statements/)
31
31
  end
32
32
 
33
33
  it 'should not report initialize' do
34
34
  src = 'def initialize(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'
35
- src.should_not smell_of(LongMethod)
35
+ src.should_not smell_of(TooManyStatements)
36
36
  end
37
37
 
38
38
  it 'should only report a long method once' do
@@ -54,7 +54,7 @@ def standard_entries(rbconfig)
54
54
  end
55
55
  end
56
56
  EOS
57
- src.should reek_only_of(:LongMethod)
57
+ src.should reek_only_of(:TooManyStatements)
58
58
  end
59
59
 
60
60
  it 'should report long inner block' do
@@ -71,11 +71,11 @@ def long()
71
71
  end
72
72
  end
73
73
  EOS
74
- src.should reek_only_of(:LongMethod)
74
+ src.should reek_only_of(:TooManyStatements)
75
75
  end
76
76
  end
77
77
 
78
- describe LongMethod do
78
+ describe TooManyStatements do
79
79
  it 'counts 1 assignment' do
80
80
  method = process_method('def one() val = 4; end')
81
81
  method.num_statements.should == 1
@@ -112,7 +112,7 @@ describe LongMethod do
112
112
  end
113
113
  end
114
114
 
115
- describe LongMethod, 'does not count control statements' do
115
+ describe TooManyStatements, 'does not count control statements' do
116
116
  it 'counts 1 statement in a conditional expression' do
117
117
  method = process_method('def one() if val == 4; callee(); end; end')
118
118
  method.num_statements.should == 1
@@ -220,9 +220,9 @@ EOS
220
220
  end
221
221
  end
222
222
 
223
- describe LongMethod do
223
+ describe TooManyStatements do
224
224
  before(:each) do
225
- @detector = LongMethod.new('silver')
225
+ @detector = TooManyStatements.new('silver')
226
226
  end
227
227
 
228
228
  it_should_behave_like 'SmellDetector'
@@ -239,10 +239,10 @@ describe LongMethod do
239
239
  @smells.length.should == 1
240
240
  end
241
241
  it 'reports the number of statements' do
242
- @smells[0].smell[LongMethod::STATEMENT_COUNT_KEY].should == @num_statements
242
+ @smells[0].smell[TooManyStatements::STATEMENT_COUNT_KEY].should == @num_statements
243
243
  end
244
244
  it 'reports the correct subclass' do
245
- @smells[0].subclass.should == LongMethod::SUBCLASS_TOO_MANY_STATEMENTS
245
+ @smells[0].subclass.should == TooManyStatements::SMELL_SUBCLASS
246
246
  end
247
247
  end
248
248
  end