ruby-watchr 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/watchr/analysers/flog.rb +10 -7
- data/lib/watchr/version.rb +1 -1
- data/spec/watchr/analysers/flog_spec.rb +23 -18
- metadata +2 -2
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'watchr/smell'
|
2
2
|
require 'watchr/smell_types'
|
3
3
|
|
4
|
+
require 'watchr/smell_builder'
|
4
5
|
module Watchr
|
5
6
|
module Analysers
|
6
7
|
module Flog
|
@@ -36,14 +37,16 @@ module Watchr
|
|
36
37
|
|
37
38
|
def analyse_complexity(target, type)
|
38
39
|
score = target.total_score
|
40
|
+
return unless is_complex?(score, type)
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
builder = Watchr::SmellBuilder.new(
|
43
|
+
smell_type(score, type), target.name, "complexity = #{score}"
|
44
|
+
)
|
45
|
+
|
46
|
+
builder.add_location(target.location.file, target.location.line)
|
47
|
+
builder.add_details({ :complexity => score })
|
48
|
+
|
49
|
+
add_smell(builder.smell)
|
47
50
|
end
|
48
51
|
|
49
52
|
def smell_type(score, type)
|
data/lib/watchr/version.rb
CHANGED
@@ -9,27 +9,32 @@ describe Watchr::Analysers::Flog do
|
|
9
9
|
analyse
|
10
10
|
}
|
11
11
|
|
12
|
+
let(:location) { stub('location',
|
13
|
+
:file => 'foo.rb',
|
14
|
+
:line => 20)
|
15
|
+
}
|
16
|
+
|
12
17
|
let(:method) { stub('method',
|
13
18
|
:name => 'method',
|
14
|
-
:location =>
|
19
|
+
:location => location,
|
15
20
|
:total_score => 10)
|
16
21
|
}
|
17
22
|
|
18
23
|
let(:complex_method) { stub('method',
|
19
24
|
:name => 'complex_method',
|
20
|
-
:location =>
|
25
|
+
:location => location,
|
21
26
|
:total_score => 30)
|
22
27
|
}
|
23
28
|
|
24
29
|
let(:very_complex_method) { stub('method',
|
25
30
|
:name => 'very_complex_method',
|
26
|
-
:location =>
|
31
|
+
:location => location,
|
27
32
|
:total_score => 100)
|
28
33
|
}
|
29
34
|
|
30
35
|
let(:clazz) { stub('class',
|
31
36
|
:name => 'Class',
|
32
|
-
:location =>
|
37
|
+
:location => location,
|
33
38
|
:total_score => 100,
|
34
39
|
:methods => [method, complex_method, very_complex_method])
|
35
40
|
}
|
@@ -43,16 +48,20 @@ describe Watchr::Analysers::Flog do
|
|
43
48
|
describe '#analyse_flog' do
|
44
49
|
let(:smell) { stub('smell') }
|
45
50
|
|
46
|
-
|
51
|
+
let(:builder) { stub('builder',
|
52
|
+
:add_location => true,
|
53
|
+
:add_details => true,
|
54
|
+
:smell => smell)
|
55
|
+
}
|
56
|
+
|
57
|
+
before { Watchr::SmellBuilder.stubs(:new).returns(builder) }
|
47
58
|
|
48
59
|
it 'should add smell for complex method' do
|
49
|
-
Watchr::
|
60
|
+
Watchr::SmellBuilder.expects(:new).with(
|
50
61
|
:complex_method,
|
51
62
|
complex_method.name,
|
52
63
|
"complexity = #{complex_method.total_score}",
|
53
|
-
|
54
|
-
{ :complexity => complex_method.total_score }
|
55
|
-
)
|
64
|
+
).returns(builder)
|
56
65
|
|
57
66
|
analyse.expects(:add_smell).returns(smell)
|
58
67
|
|
@@ -60,13 +69,11 @@ describe Watchr::Analysers::Flog do
|
|
60
69
|
end
|
61
70
|
|
62
71
|
it 'should add smell for very complex method' do
|
63
|
-
Watchr::
|
72
|
+
Watchr::SmellBuilder.expects(:new).with(
|
64
73
|
:very_complex_method,
|
65
74
|
very_complex_method.name,
|
66
|
-
"complexity = #{very_complex_method.total_score}"
|
67
|
-
|
68
|
-
{ :complexity => very_complex_method.total_score }
|
69
|
-
)
|
75
|
+
"complexity = #{very_complex_method.total_score}"
|
76
|
+
).returns(builder)
|
70
77
|
|
71
78
|
analyse.expects(:add_smell).returns(smell)
|
72
79
|
|
@@ -74,13 +81,11 @@ describe Watchr::Analysers::Flog do
|
|
74
81
|
end
|
75
82
|
|
76
83
|
it 'should add smell for very complex object' do
|
77
|
-
Watchr::
|
84
|
+
Watchr::SmellBuilder.expects(:new).with(
|
78
85
|
:very_complex_object,
|
79
86
|
clazz.name,
|
80
87
|
"complexity = #{clazz.total_score}",
|
81
|
-
|
82
|
-
{ :complexity => clazz.total_score }
|
83
|
-
)
|
88
|
+
).returns(builder)
|
84
89
|
|
85
90
|
analyse.expects(:add_smell).returns(smell)
|
86
91
|
|