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.
- data/History.txt +19 -0
- data/README.rdoc +34 -0
- data/VERSION.yml +1 -1
- data/bin/excellent +21 -6
- data/lib/simplabs/excellent.rb +7 -5
- data/lib/simplabs/excellent/checks.rb +18 -1
- data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +19 -56
- data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +16 -16
- data/lib/simplabs/excellent/checks/base.rb +30 -21
- data/lib/simplabs/excellent/checks/case_missing_else_check.rb +13 -5
- data/lib/simplabs/excellent/checks/class_line_count_check.rb +10 -8
- data/lib/simplabs/excellent/checks/class_name_check.rb +11 -10
- data/lib/simplabs/excellent/checks/control_coupling_check.rb +13 -10
- data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +25 -9
- data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +4 -20
- data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +25 -10
- data/lib/simplabs/excellent/checks/duplication_check.rb +50 -0
- data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +10 -18
- data/lib/simplabs/excellent/checks/flog_block_check.rb +40 -0
- data/lib/simplabs/excellent/checks/flog_check.rb +27 -0
- data/lib/simplabs/excellent/checks/flog_class_check.rb +40 -0
- data/lib/simplabs/excellent/checks/flog_method_check.rb +40 -0
- data/lib/simplabs/excellent/checks/for_loop_check.rb +20 -4
- data/lib/simplabs/excellent/checks/line_count_check.rb +3 -21
- data/lib/simplabs/excellent/checks/method_line_count_check.rb +9 -7
- data/lib/simplabs/excellent/checks/method_name_check.rb +13 -9
- data/lib/simplabs/excellent/checks/module_line_count_check.rb +9 -7
- data/lib/simplabs/excellent/checks/module_name_check.rb +11 -7
- data/lib/simplabs/excellent/checks/name_check.rb +3 -8
- data/lib/simplabs/excellent/checks/nested_iterators_check.rb +33 -0
- data/lib/simplabs/excellent/checks/parameter_number_check.rb +13 -12
- data/lib/simplabs/excellent/checks/rails.rb +17 -0
- data/lib/simplabs/excellent/checks/rails/attr_accessible_check.rb +38 -0
- data/lib/simplabs/excellent/checks/rails/attr_protected_check.rb +39 -0
- data/lib/simplabs/excellent/checks/singleton_variable_check.rb +32 -0
- data/lib/simplabs/excellent/extensions/sexp.rb +21 -0
- data/lib/simplabs/excellent/extensions/string.rb +23 -0
- data/lib/simplabs/excellent/parsing.rb +12 -0
- data/lib/simplabs/excellent/parsing/abc_measure.rb +52 -0
- data/lib/simplabs/excellent/parsing/block_context.rb +43 -0
- data/lib/simplabs/excellent/parsing/call_context.rb +36 -0
- data/lib/simplabs/excellent/parsing/case_context.rb +31 -0
- data/lib/simplabs/excellent/parsing/class_context.rb +68 -0
- data/lib/simplabs/excellent/parsing/code_processor.rb +154 -0
- data/lib/simplabs/excellent/parsing/conditional_context.rb +25 -0
- data/lib/simplabs/excellent/parsing/cvar_context.rb +28 -0
- data/lib/simplabs/excellent/parsing/cyclomatic_complexity_measure.rb +73 -0
- data/lib/simplabs/excellent/parsing/flog_measure.rb +192 -0
- data/lib/simplabs/excellent/parsing/for_loop_context.rb +15 -0
- data/lib/simplabs/excellent/parsing/if_context.rb +38 -0
- data/lib/simplabs/excellent/parsing/method_context.rb +50 -0
- data/lib/simplabs/excellent/parsing/module_context.rb +29 -0
- data/lib/simplabs/excellent/{core → parsing}/parser.rb +4 -2
- data/lib/simplabs/excellent/parsing/resbody_context.rb +39 -0
- data/lib/simplabs/excellent/parsing/scopeable.rb +34 -0
- data/lib/simplabs/excellent/parsing/sexp_context.rb +125 -0
- data/lib/simplabs/excellent/parsing/singleton_method_context.rb +55 -0
- data/lib/simplabs/excellent/parsing/until_context.rb +24 -0
- data/lib/simplabs/excellent/parsing/while_context.rb +24 -0
- data/lib/simplabs/excellent/runner.rb +105 -0
- data/lib/simplabs/excellent/warning.rb +53 -0
- data/spec/checks/abc_metric_method_check_spec.rb +36 -8
- data/spec/checks/assignment_in_conditional_check_spec.rb +31 -14
- data/spec/checks/case_missing_else_check_spec.rb +8 -8
- data/spec/checks/class_line_count_check_spec.rb +24 -11
- data/spec/checks/class_name_check_spec.rb +9 -9
- data/spec/checks/control_coupling_check_spec.rb +84 -13
- data/spec/checks/cyclomatic_complexity_block_check_spec.rb +13 -17
- data/spec/checks/cyclomatic_complexity_method_check_spec.rb +32 -6
- data/spec/checks/duplication_check_spec.rb +139 -0
- data/spec/checks/empty_rescue_body_check_spec.rb +54 -16
- data/spec/checks/flog_block_check_spec.rb +28 -0
- data/spec/checks/flog_class_check_spec.rb +28 -0
- data/spec/checks/flog_method_check_spec.rb +46 -0
- data/spec/checks/for_loop_check_spec.rb +11 -11
- data/spec/checks/method_line_count_check_spec.rb +11 -12
- data/spec/checks/method_name_check_spec.rb +34 -13
- data/spec/checks/module_line_count_check_spec.rb +11 -12
- data/spec/checks/module_name_check_spec.rb +31 -7
- data/spec/checks/nested_iterators_check_spec.rb +44 -0
- data/spec/checks/parameter_number_check_spec.rb +48 -12
- data/spec/checks/rails/attr_accessible_check_spec.rb +79 -0
- data/spec/checks/rails/attr_protected_check_spec.rb +77 -0
- data/spec/checks/singleton_variable_check_spec.rb +66 -0
- data/spec/{core/extensions/underscore_spec.rb → extensions/string_spec.rb} +1 -1
- metadata +58 -15
- data/README.markdown +0 -30
- data/lib/simplabs/excellent/checks/class_variable_check.rb +0 -25
- data/lib/simplabs/excellent/core.rb +0 -2
- data/lib/simplabs/excellent/core/checking_visitor.rb +0 -34
- data/lib/simplabs/excellent/core/error.rb +0 -31
- data/lib/simplabs/excellent/core/extensions/underscore.rb +0 -27
- data/lib/simplabs/excellent/core/iterator_visitor.rb +0 -29
- data/lib/simplabs/excellent/core/parse_tree_runner.rb +0 -88
- data/lib/simplabs/excellent/core/visitable_sexp.rb +0 -31
- 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::
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
75
|
+
verify_warning_found(content, 2)
|
59
76
|
end
|
60
77
|
|
61
78
|
end
|
62
79
|
|
63
|
-
def
|
80
|
+
def verify_warning_found(content, line_number = nil)
|
64
81
|
@excellent.check_content(content)
|
65
|
-
|
82
|
+
warnings = @excellent.warnings
|
66
83
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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::
|
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
|
-
|
19
|
+
warnings = @excellent.warnings
|
20
20
|
|
21
|
-
|
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
|
-
|
32
|
+
warnings = @excellent.warnings
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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::
|
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
|
13
|
+
class OneLineClass; end
|
14
14
|
END
|
15
15
|
@excellent.check_content(content)
|
16
16
|
|
17
|
-
@excellent.
|
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
|
-
|
22
|
+
class ThreeLineClass
|
23
23
|
@foo = 1
|
24
24
|
end
|
25
25
|
END
|
26
26
|
@excellent.check_content(content)
|
27
27
|
|
28
|
-
@excellent.
|
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
|
46
|
+
class FourLineClass
|
34
47
|
@foo = 1
|
35
48
|
@bar = 2
|
36
49
|
end
|
37
50
|
END
|
38
51
|
@excellent.check_content(content)
|
39
|
-
|
52
|
+
warnings = @excellent.warnings
|
40
53
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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::
|
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.
|
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
|
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.
|
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
|
-
|
38
|
+
warnings = @excellent.warnings
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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::
|
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
|
11
|
+
it 'should accept methods that just print out the parameter' do
|
12
12
|
content = <<-END
|
13
|
-
def write(quoted
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
45
|
+
warnings = @excellent.warnings
|
23
46
|
|
24
|
-
|
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::
|
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
|
-
|
14
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
39
|
+
warnings = @excellent.warnings
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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::
|
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
|
-
|
202
|
+
warnings = @excellent.warnings
|
177
203
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|