simplabs-excellent 1.0.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/History.txt +19 -0
  2. data/README.rdoc +34 -0
  3. data/VERSION.yml +1 -1
  4. data/bin/excellent +21 -6
  5. data/lib/simplabs/excellent.rb +7 -5
  6. data/lib/simplabs/excellent/checks.rb +18 -1
  7. data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +19 -56
  8. data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +16 -16
  9. data/lib/simplabs/excellent/checks/base.rb +30 -21
  10. data/lib/simplabs/excellent/checks/case_missing_else_check.rb +13 -5
  11. data/lib/simplabs/excellent/checks/class_line_count_check.rb +10 -8
  12. data/lib/simplabs/excellent/checks/class_name_check.rb +11 -10
  13. data/lib/simplabs/excellent/checks/control_coupling_check.rb +13 -10
  14. data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +25 -9
  15. data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +4 -20
  16. data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +25 -10
  17. data/lib/simplabs/excellent/checks/duplication_check.rb +50 -0
  18. data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +10 -18
  19. data/lib/simplabs/excellent/checks/flog_block_check.rb +40 -0
  20. data/lib/simplabs/excellent/checks/flog_check.rb +27 -0
  21. data/lib/simplabs/excellent/checks/flog_class_check.rb +40 -0
  22. data/lib/simplabs/excellent/checks/flog_method_check.rb +40 -0
  23. data/lib/simplabs/excellent/checks/for_loop_check.rb +20 -4
  24. data/lib/simplabs/excellent/checks/line_count_check.rb +3 -21
  25. data/lib/simplabs/excellent/checks/method_line_count_check.rb +9 -7
  26. data/lib/simplabs/excellent/checks/method_name_check.rb +13 -9
  27. data/lib/simplabs/excellent/checks/module_line_count_check.rb +9 -7
  28. data/lib/simplabs/excellent/checks/module_name_check.rb +11 -7
  29. data/lib/simplabs/excellent/checks/name_check.rb +3 -8
  30. data/lib/simplabs/excellent/checks/nested_iterators_check.rb +33 -0
  31. data/lib/simplabs/excellent/checks/parameter_number_check.rb +13 -12
  32. data/lib/simplabs/excellent/checks/rails.rb +17 -0
  33. data/lib/simplabs/excellent/checks/rails/attr_accessible_check.rb +38 -0
  34. data/lib/simplabs/excellent/checks/rails/attr_protected_check.rb +39 -0
  35. data/lib/simplabs/excellent/checks/singleton_variable_check.rb +32 -0
  36. data/lib/simplabs/excellent/extensions/sexp.rb +21 -0
  37. data/lib/simplabs/excellent/extensions/string.rb +23 -0
  38. data/lib/simplabs/excellent/parsing.rb +12 -0
  39. data/lib/simplabs/excellent/parsing/abc_measure.rb +52 -0
  40. data/lib/simplabs/excellent/parsing/block_context.rb +43 -0
  41. data/lib/simplabs/excellent/parsing/call_context.rb +36 -0
  42. data/lib/simplabs/excellent/parsing/case_context.rb +31 -0
  43. data/lib/simplabs/excellent/parsing/class_context.rb +68 -0
  44. data/lib/simplabs/excellent/parsing/code_processor.rb +154 -0
  45. data/lib/simplabs/excellent/parsing/conditional_context.rb +25 -0
  46. data/lib/simplabs/excellent/parsing/cvar_context.rb +28 -0
  47. data/lib/simplabs/excellent/parsing/cyclomatic_complexity_measure.rb +73 -0
  48. data/lib/simplabs/excellent/parsing/flog_measure.rb +192 -0
  49. data/lib/simplabs/excellent/parsing/for_loop_context.rb +15 -0
  50. data/lib/simplabs/excellent/parsing/if_context.rb +38 -0
  51. data/lib/simplabs/excellent/parsing/method_context.rb +50 -0
  52. data/lib/simplabs/excellent/parsing/module_context.rb +29 -0
  53. data/lib/simplabs/excellent/{core → parsing}/parser.rb +4 -2
  54. data/lib/simplabs/excellent/parsing/resbody_context.rb +39 -0
  55. data/lib/simplabs/excellent/parsing/scopeable.rb +34 -0
  56. data/lib/simplabs/excellent/parsing/sexp_context.rb +125 -0
  57. data/lib/simplabs/excellent/parsing/singleton_method_context.rb +55 -0
  58. data/lib/simplabs/excellent/parsing/until_context.rb +24 -0
  59. data/lib/simplabs/excellent/parsing/while_context.rb +24 -0
  60. data/lib/simplabs/excellent/runner.rb +105 -0
  61. data/lib/simplabs/excellent/warning.rb +53 -0
  62. data/spec/checks/abc_metric_method_check_spec.rb +36 -8
  63. data/spec/checks/assignment_in_conditional_check_spec.rb +31 -14
  64. data/spec/checks/case_missing_else_check_spec.rb +8 -8
  65. data/spec/checks/class_line_count_check_spec.rb +24 -11
  66. data/spec/checks/class_name_check_spec.rb +9 -9
  67. data/spec/checks/control_coupling_check_spec.rb +84 -13
  68. data/spec/checks/cyclomatic_complexity_block_check_spec.rb +13 -17
  69. data/spec/checks/cyclomatic_complexity_method_check_spec.rb +32 -6
  70. data/spec/checks/duplication_check_spec.rb +139 -0
  71. data/spec/checks/empty_rescue_body_check_spec.rb +54 -16
  72. data/spec/checks/flog_block_check_spec.rb +28 -0
  73. data/spec/checks/flog_class_check_spec.rb +28 -0
  74. data/spec/checks/flog_method_check_spec.rb +46 -0
  75. data/spec/checks/for_loop_check_spec.rb +11 -11
  76. data/spec/checks/method_line_count_check_spec.rb +11 -12
  77. data/spec/checks/method_name_check_spec.rb +34 -13
  78. data/spec/checks/module_line_count_check_spec.rb +11 -12
  79. data/spec/checks/module_name_check_spec.rb +31 -7
  80. data/spec/checks/nested_iterators_check_spec.rb +44 -0
  81. data/spec/checks/parameter_number_check_spec.rb +48 -12
  82. data/spec/checks/rails/attr_accessible_check_spec.rb +79 -0
  83. data/spec/checks/rails/attr_protected_check_spec.rb +77 -0
  84. data/spec/checks/singleton_variable_check_spec.rb +66 -0
  85. data/spec/{core/extensions/underscore_spec.rb → extensions/string_spec.rb} +1 -1
  86. metadata +58 -15
  87. data/README.markdown +0 -30
  88. data/lib/simplabs/excellent/checks/class_variable_check.rb +0 -25
  89. data/lib/simplabs/excellent/core.rb +0 -2
  90. data/lib/simplabs/excellent/core/checking_visitor.rb +0 -34
  91. data/lib/simplabs/excellent/core/error.rb +0 -31
  92. data/lib/simplabs/excellent/core/extensions/underscore.rb +0 -27
  93. data/lib/simplabs/excellent/core/iterator_visitor.rb +0 -29
  94. data/lib/simplabs/excellent/core/parse_tree_runner.rb +0 -88
  95. data/lib/simplabs/excellent/core/visitable_sexp.rb +0 -31
  96. data/spec/checks/class_variable_check_spec.rb +0 -26
@@ -3,18 +3,35 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
4
4
 
5
5
  before do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::AssignmentInConditionalCheck.new)
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::AssignmentInConditionalCheck.new)
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
10
10
 
11
11
  it 'should accept an assignment before an if clause' do
12
12
  content = <<-END
13
- count = count += 1 if some_condition
13
+ count = count += 1 if @some_condition
14
14
  END
15
15
  @excellent.check_content(content)
16
16
 
17
- @excellent.errors.should be_empty
17
+ @excellent.warnings.should be_empty
18
+ end
19
+
20
+ it 'should accept block parameters in an if clause' do
21
+ content = <<-END
22
+ return true if exp.children.any? { |child| contains_statements?(child) }
23
+ END
24
+ @excellent.check_content(content)
25
+
26
+ @excellent.warnings.should be_empty
27
+ end
28
+
29
+ it 'should reject assignments of results of blocks in an if clause' do
30
+ content = <<-END
31
+ return true if value = exp.children.find { |child| contains_statements?(child) }
32
+ END
33
+
34
+ verify_warning_found(content)
18
35
  end
19
36
 
20
37
  it 'should reject an assignment inside an if clause' do
@@ -22,7 +39,7 @@ describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
22
39
  call_foo if bar = bam
23
40
  END
24
41
 
25
- verify_error_found(content)
42
+ verify_warning_found(content)
26
43
  end
27
44
 
28
45
  it 'should reject an assignment inside an unless clause' do
@@ -30,7 +47,7 @@ describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
30
47
  call_foo unless bar = bam
31
48
  END
32
49
 
33
- verify_error_found(content)
50
+ verify_warning_found(content)
34
51
  end
35
52
 
36
53
  it 'should reject an assignment inside a while clause' do
@@ -38,7 +55,7 @@ describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
38
55
  call_foo while bar = bam
39
56
  END
40
57
 
41
- verify_error_found(content)
58
+ verify_warning_found(content)
42
59
  end
43
60
 
44
61
  it 'should reject an assignment inside an until clause' do
@@ -46,7 +63,7 @@ describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
46
63
  call_foo until bar = bam
47
64
  END
48
65
 
49
- verify_error_found(content)
66
+ verify_warning_found(content)
50
67
  end
51
68
 
52
69
  it 'should reject an assignment inside a ternary operator check clause' do
@@ -55,19 +72,19 @@ describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
55
72
  END
56
73
 
57
74
  #RubyParser sets line number 2 here
58
- verify_error_found(content, 2)
75
+ verify_warning_found(content, 2)
59
76
  end
60
77
 
61
78
  end
62
79
 
63
- def verify_error_found(content, line_number = nil)
80
+ def verify_warning_found(content, line_number = nil)
64
81
  @excellent.check_content(content)
65
- errors = @excellent.errors
82
+ warnings = @excellent.warnings
66
83
 
67
- errors.should_not be_empty
68
- errors[0].info.should == {}
69
- errors[0].line_number.should == (line_number || 1)
70
- errors[0].message.should == 'Assignment in condition.'
84
+ warnings.should_not be_empty
85
+ warnings[0].info.should == {}
86
+ warnings[0].line_number.should == (line_number || 1)
87
+ warnings[0].message.should == 'Assignment in condition.'
71
88
  end
72
89
 
73
90
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
4
4
 
5
5
  before do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::CaseMissingElseCheck.new)
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::CaseMissingElseCheck.new)
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
@@ -16,9 +16,9 @@ describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
16
16
  end
17
17
  END
18
18
  @excellent.check_content(content)
19
- errors = @excellent.errors
19
+ warnings = @excellent.warnings
20
20
 
21
- errors.should be_empty
21
+ warnings.should be_empty
22
22
  end
23
23
 
24
24
  it 'should reject case statements that do not have an else clause' do
@@ -29,12 +29,12 @@ describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
29
29
  end
30
30
  END
31
31
  @excellent.check_content(content)
32
- errors = @excellent.errors
32
+ warnings = @excellent.warnings
33
33
 
34
- errors.should_not be_empty
35
- errors[0].info.should == {}
36
- errors[0].line_number.should == 2
37
- errors[0].message.should == 'Case statement is missing else clause.'
34
+ warnings.should_not be_empty
35
+ warnings[0].info.should == {}
36
+ warnings[0].line_number.should == 2
37
+ warnings[0].message.should == 'Case statement is missing else clause.'
38
38
  end
39
39
 
40
40
  end
@@ -3,45 +3,58 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::ClassLineCountCheck do
4
4
 
5
5
  before do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ClassLineCountCheck.new({ :threshold => 1 }))
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::ClassLineCountCheck.new({ :threshold => 3 }))
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
10
10
 
11
11
  it 'should accept classes with less lines than the threshold' do
12
12
  content = <<-END
13
- class ZeroLineClass; end
13
+ class OneLineClass; end
14
14
  END
15
15
  @excellent.check_content(content)
16
16
 
17
- @excellent.errors.should be_empty
17
+ @excellent.warnings.should be_empty
18
18
  end
19
19
 
20
20
  it 'should accept classes with the same number of lines as the threshold' do
21
21
  content = <<-END
22
- Class OneLineClass
22
+ class ThreeLineClass
23
23
  @foo = 1
24
24
  end
25
25
  END
26
26
  @excellent.check_content(content)
27
27
 
28
- @excellent.errors.should be_empty
28
+ @excellent.warnings.should be_empty
29
+ end
30
+
31
+ it 'should not count blank lines' do
32
+ content = <<-END
33
+ class ThreeLineClass
34
+
35
+ @foo = 1
36
+
37
+ end
38
+ END
39
+ @excellent.check_content(content)
40
+
41
+ @excellent.warnings.should be_empty
29
42
  end
30
43
 
31
44
  it 'should reject classes with more lines than the threshold' do
32
45
  content = <<-END
33
- class TwoLineClass
46
+ class FourLineClass
34
47
  @foo = 1
35
48
  @bar = 2
36
49
  end
37
50
  END
38
51
  @excellent.check_content(content)
39
- errors = @excellent.errors
52
+ warnings = @excellent.warnings
40
53
 
41
- errors.should_not be_empty
42
- errors[0].info.should == { :class => :TwoLineClass, :count => 2 }
43
- errors[0].line_number.should == 1
44
- errors[0].message.should == 'Class TwoLineClass has 2 lines.'
54
+ warnings.should_not be_empty
55
+ warnings[0].info.should == { :class => 'FourLineClass', :count => 4 }
56
+ warnings[0].line_number.should == 1
57
+ warnings[0].message.should == 'FourLineClass has 4 lines.'
45
58
  end
46
59
 
47
60
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::ClassNameCheck do
4
4
 
5
5
  before(:each) do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ClassNameCheck.new)
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::ClassNameCheck.new)
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
@@ -14,19 +14,19 @@ describe Simplabs::Excellent::Checks::ClassNameCheck do
14
14
  END
15
15
  @excellent.check_content(content)
16
16
 
17
- @excellent.errors.should be_empty
17
+ @excellent.warnings.should be_empty
18
18
  end
19
19
 
20
20
  it 'should be able to parse scoped class names' do
21
21
  content = <<-END
22
- class MyScope::GoodClassName
22
+ class Outer::Inner::GoodClassName
23
23
  def method
24
24
  end
25
25
  end
26
26
  END
27
27
  @excellent.check_content(content)
28
28
 
29
- @excellent.errors.should be_empty
29
+ @excellent.warnings.should be_empty
30
30
  end
31
31
 
32
32
  it 'should reject class names with underscores' do
@@ -35,12 +35,12 @@ describe Simplabs::Excellent::Checks::ClassNameCheck do
35
35
  end
36
36
  END
37
37
  @excellent.check_content(content)
38
- errors = @excellent.errors
38
+ warnings = @excellent.warnings
39
39
 
40
- errors.should_not be_empty
41
- errors[0].info.should == { :class => :Bad_ClassName }
42
- errors[0].line_number.should == 1
43
- errors[0].message.should == 'Bad class name Bad_ClassName.'
40
+ warnings.should_not be_empty
41
+ warnings[0].info.should == { :class => 'Bad_ClassName' }
42
+ warnings[0].line_number.should == 1
43
+ warnings[0].message.should == 'Bad class name Bad_ClassName.'
44
44
  end
45
45
 
46
46
  end
@@ -3,30 +3,101 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::ControlCouplingCheck do
4
4
 
5
5
  before(:each) do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ControlCouplingCheck.new)
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::ControlCouplingCheck.new)
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
10
10
 
11
- it 'should reject methods with if checks using a parameter' do
11
+ it 'should accept methods that just print out the parameter' do
12
12
  content = <<-END
13
- def write(quoted, foo)
14
- if quoted
15
- write_quoted(@value)
16
- else
17
- puts @value
18
- end
13
+ def write(quoted)
14
+ pp quoted
15
+ end
16
+ END
17
+ @excellent.check_content(content)
18
+ warnings = @excellent.warnings
19
+
20
+ warnings.should be_empty
21
+ end
22
+
23
+ it 'should accept methods with ternary operators using an instance variable' do
24
+ content = <<-END
25
+ def write(quoted)
26
+ @quoted ? write_quoted('1') : write_quoted('2')
27
+ end
28
+ END
29
+
30
+ @excellent.check_content(content)
31
+ warnings = @excellent.warnings
32
+
33
+ warnings.should be_empty
34
+ end
35
+
36
+ it 'should accept methods with ternary operators using a local variable' do
37
+ content = <<-END
38
+ def write(quoted)
39
+ test = false
40
+ test ? write_quoted('1') : write_quoted('2')
19
41
  end
20
42
  END
43
+
21
44
  @excellent.check_content(content)
22
- errors = @excellent.errors
45
+ warnings = @excellent.warnings
23
46
 
24
- errors.should_not be_empty
25
- errors[0].info.should == { :method => :write, :argument => :quoted }
26
- errors[0].line_number.should == 2
27
- errors[0].message.should == 'Control of write is coupled to quoted.'
47
+ warnings.should be_empty
28
48
  end
29
49
 
50
+ %w(if unless).each do |conditional|
51
+
52
+ it "should reject methods with #{conditional} checks using a parameter" do
53
+ content = <<-END
54
+ def write(quoted)
55
+ #{conditional} quoted
56
+ write_quoted('test')
57
+ end
58
+ end
59
+ END
60
+
61
+ verify_warning_found(content)
62
+ end
63
+
64
+ end
65
+
66
+ it 'should reject methods with ternary operators using a parameter' do
67
+ content = <<-END
68
+ def write(quoted)
69
+ quoted ? write_quoted('1') : write_quoted('2')
70
+ end
71
+ END
72
+
73
+ verify_warning_found(content)
74
+ end
75
+
76
+ it "should reject methods with case statements using a parameter" do
77
+ content = <<-END
78
+ def write(quoted)
79
+ case quoted
80
+ when 1
81
+ write_quoted('1')
82
+ when 2
83
+ write_quoted('2')
84
+ end
85
+ end
86
+ END
87
+
88
+ verify_warning_found(content)
89
+ end
90
+
91
+ end
92
+
93
+ def verify_warning_found(content)
94
+ @excellent.check_content(content)
95
+ warnings = @excellent.warnings
96
+
97
+ warnings.should_not be_empty
98
+ warnings[0].info.should == { :method => 'write', :argument => 'quoted' }
99
+ warnings[0].line_number.should == 1
100
+ warnings[0].message.should == 'write is coupled to quoted.'
30
101
  end
31
102
 
32
103
  end
@@ -3,17 +3,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck do
4
4
 
5
5
  before(:each) do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck.new({ :threshold => 0 }))
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck.new({ :threshold => 0 }))
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
10
10
 
11
11
  it 'should find a simple block' do
12
12
  content = <<-END
13
- def method_name
14
- it 'should be a simple block' do
15
- call_foo
16
- end
13
+ it 'should be a simple block' do
14
+ call_foo
17
15
  end
18
16
  END
19
17
 
@@ -22,13 +20,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck do
22
20
 
23
21
  it 'should find a block with multiple paths' do
24
22
  content = <<-END
25
- def method_name
26
- it 'should be a complex block' do
27
- if some_condition
28
- call_foo
29
- else
30
- call_bar
31
- end
23
+ it 'should be a complex block' do
24
+ if some_condition
25
+ call_foo
26
+ else
27
+ call_bar
32
28
  end
33
29
  end
34
30
  END
@@ -40,12 +36,12 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck do
40
36
 
41
37
  def verify_content_complexity(content, score)
42
38
  @excellent.check_content(content)
43
- errors = @excellent.errors
39
+ warnings = @excellent.warnings
44
40
 
45
- errors.should_not be_empty
46
- errors[0].info.should == { :score => score }
47
- errors[0].line_number.should == 2
48
- errors[0].message.should == "Block has cyclomatic complexity of #{score}."
41
+ warnings.should_not be_empty
42
+ warnings[0].info.should == { :block => 'block', :score => score }
43
+ warnings[0].line_number.should == 1
44
+ warnings[0].message.should == "block has cyclomatic complexity of #{score}."
49
45
  end
50
46
 
51
47
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do
4
4
 
5
5
  before do
6
- @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck.new({ :threshold => 0 }))
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck.new({ :threshold => 0 }))
7
7
  end
8
8
 
9
9
  describe '#evaluate' do
@@ -169,16 +169,42 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do
169
169
  verify_content_complexity(content, 5)
170
170
  end
171
171
 
172
+ it 'should also work on singleton methods' do
173
+ content = <<-END
174
+ class Class
175
+ def self.method_name
176
+ if first_condition then
177
+ call_foo
178
+ else
179
+ if second_condition then
180
+ call_bar
181
+ else
182
+ call_bam if third_condition
183
+ end
184
+ call_baz if fourth_condition
185
+ end
186
+ end
187
+ end
188
+ END
189
+ @excellent.check_content(content)
190
+ warnings = @excellent.warnings
191
+
192
+ warnings.should_not be_empty
193
+ warnings[0].info.should == { :method => 'Class.method_name', :score => 5 }
194
+ warnings[0].line_number.should == 2
195
+ warnings[0].message.should == "Class.method_name has cyclomatic complexity of 5."
196
+ end
197
+
172
198
  end
173
199
 
174
200
  def verify_content_complexity(content, score)
175
201
  @excellent.check_content(content)
176
- errors = @excellent.errors
202
+ warnings = @excellent.warnings
177
203
 
178
- errors.should_not be_empty
179
- errors[0].info.should == { :method => :method_name, :score => score }
180
- errors[0].line_number.should == 1
181
- errors[0].message.should == "Method method_name has cyclomatic complexity of #{score}."
204
+ warnings.should_not be_empty
205
+ warnings[0].info.should == { :method => 'method_name', :score => score }
206
+ warnings[0].line_number.should == 1
207
+ warnings[0].message.should == "method_name has cyclomatic complexity of #{score}."
182
208
  end
183
209
 
184
210
  end