ruby-watchr 0.2.1 → 0.2.2

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.
@@ -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
- add_smell(
41
- Watchr::Smell.new(
42
- smell_type(score, type), target.name,
43
- "complexity = #{score}", target.location,
44
- { :complexity => score }
45
- )
46
- ) if is_complex?(score, type)
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)
@@ -1,3 +1,3 @@
1
1
  module Watchr
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -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 => stub('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 => stub('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 => stub('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 => stub('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
- before { Watchr::Smell.stubs(:new).returns(smell) }
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::Smell.expects(:new).with(
60
+ Watchr::SmellBuilder.expects(:new).with(
50
61
  :complex_method,
51
62
  complex_method.name,
52
63
  "complexity = #{complex_method.total_score}",
53
- complex_method.location,
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::Smell.expects(:new).with(
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
- very_complex_method.location,
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::Smell.expects(:new).with(
84
+ Watchr::SmellBuilder.expects(:new).with(
78
85
  :very_complex_object,
79
86
  clazz.name,
80
87
  "complexity = #{clazz.total_score}",
81
- clazz.location,
82
- { :complexity => clazz.total_score }
83
- )
88
+ ).returns(builder)
84
89
 
85
90
  analyse.expects(:add_smell).returns(smell)
86
91
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Petr Janda