ruby-watchr 0.1.9 → 0.2.0

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,4 +1,4 @@
1
- require 'watchr/smell'
1
+ require 'watchr/smell_builder'
2
2
 
3
3
  module Watchr
4
4
  module Analysers
@@ -6,18 +6,22 @@ module Watchr
6
6
  include SmellTypes
7
7
 
8
8
  def analyse_reek(report)
9
- report.smells.each do |smell|
10
- location = Location.new(
11
- smell.location['source'],
12
- smell.location['lines'].first
9
+ report.smells.each do |reek_smell|
10
+ location = reek_smell.location
11
+ smell = reek_smell.smell
12
+
13
+ builder = Watchr::SmellBuilder.new(
14
+ underscore(smell['subclass']).to_sym,
15
+ location['context'],
16
+ smell['message'],
17
+ )
18
+
19
+ builder.add_location(
20
+ location['source'],
21
+ location['lines'].first
13
22
  )
14
23
 
15
- add_smell(Watchr::Smell.new(
16
- underscore(smell.smell['subclass']).to_sym,
17
- smell.location['context'],
18
- smell.smell['message'],
19
- location
20
- ))
24
+ add_smell(builder.smell)
21
25
  end
22
26
  end
23
27
 
data/lib/watchr/smell.rb CHANGED
@@ -4,14 +4,11 @@ module Watchr
4
4
  class Smell
5
5
  include SmellTypes
6
6
 
7
- def initialize(type, context, description, locations, details = {})
7
+ def initialize(type, context, description)
8
8
  @type = type
9
9
  @context = context
10
10
  @description = description
11
11
  @locations = []
12
- @details = details
13
-
14
- Array(locations).each {|l| add_location(l)}
15
12
  end
16
13
 
17
14
  def type
@@ -34,6 +31,10 @@ module Watchr
34
31
  @details
35
32
  end
36
33
 
34
+ def details=(details)
35
+ @details = details
36
+ end
37
+
37
38
  def add_location(location)
38
39
  @locations << location
39
40
  end
@@ -0,0 +1,31 @@
1
+ require 'watchr/smell'
2
+ require 'watchr/smell_types'
3
+
4
+ module Watchr
5
+ class SmellBuilder
6
+ include SmellTypes
7
+
8
+ attr_reader :smell
9
+
10
+ def initialize(type, context, description)
11
+ assert_smell_type(type)
12
+
13
+ @smell = Smell.new(type, context, description)
14
+ end
15
+
16
+ def add_location(file, line)
17
+ @smell.add_location(Location.new(file, line))
18
+ end
19
+
20
+ def add_details(details)
21
+ @smell.details = details
22
+ end
23
+
24
+ private
25
+
26
+ def assert_smell_type(type)
27
+ raise "Invalid smell type '#{type}'" \
28
+ unless ALL_SMELLS.include?(type)
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Watchr
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'watchr/analysers/reek'
3
+
4
+ describe Watchr::Analysers::Reek do
5
+ let(:analyse) {
6
+ analyse = stub('analyse', :add_smell => true)
7
+ analyse.extend Watchr::Analysers::Reek
8
+
9
+ analyse
10
+ }
11
+
12
+ describe '#analyse_reek' do
13
+ subject { analyse.analyse_reek(report) }
14
+
15
+ let(:reek_smell) { stub('smell',
16
+ :smell => {
17
+ 'subclass' => 'BooleanParameter',
18
+ 'message' => 'message'
19
+ },
20
+
21
+ :location => {
22
+ 'context' => 'context',
23
+ 'lines' => [12],
24
+ 'source' => 'source.rb'
25
+ })
26
+ }
27
+
28
+ let(:reek_smells) { [reek_smell] }
29
+
30
+ let(:report) { stub('report', :smells => reek_smells) }
31
+
32
+ let(:smell) { stub('smell', :add_location => true) }
33
+
34
+ it 'should add smell for each reek report smell' do
35
+ Watchr::Smell.expects(:new).with(:boolean_parameter, 'context', 'message').returns(smell)
36
+
37
+ analyse.expects(:add_smell).returns(smell)
38
+
39
+ subject
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'watchr/smell_builder'
3
+
4
+ describe Watchr::SmellBuilder do
5
+ context 'invalid smell type' do
6
+ subject { Watchr::SmellBuilder.new(:foo, '', '') }
7
+
8
+ it { lambda { subject }.should raise_error "Invalid smell type 'foo'" }
9
+ end
10
+ end
@@ -7,15 +7,13 @@ describe Watchr::Smell do
7
7
 
8
8
  let(:location) { 'location' }
9
9
 
10
- let(:locations) { location }
11
-
12
10
  let(:description) { 'description' }
13
11
 
14
12
  let(:context) { 'context' }
15
13
 
16
14
  let(:details) { stub('details') }
17
15
 
18
- let(:smell) { Watchr::Smell.new(type, context, description, locations, details) }
16
+ let(:smell) { Watchr::Smell.new(type, context, description) }
19
17
 
20
18
  subject { smell }
21
19
 
@@ -26,12 +24,14 @@ describe Watchr::Smell do
26
24
  describe '#locations' do
27
25
  subject { smell.locations }
28
26
 
27
+ before { smell.add_location(location) }
28
+
29
29
  context 'one location' do
30
30
  it { should == [location] }
31
31
  end
32
32
 
33
33
  context 'multiple locations' do
34
- let(:locations) { [location, location] }
34
+ before { smell.add_location(location) }
35
35
 
36
36
  it { should == [location, location] }
37
37
  end
@@ -39,7 +39,17 @@ describe Watchr::Smell do
39
39
 
40
40
  its(:description) { should == description }
41
41
 
42
- its(:details) { should == details }
42
+ describe '#details' do
43
+ context 'without any' do
44
+ its(:details) { should == nil }
45
+ end
46
+
47
+ context 'with given' do
48
+ before { smell.details = details }
49
+
50
+ its(:details) { should == details }
51
+ end
52
+ end
43
53
 
44
54
  its(:context) { should == context }
45
55
  end
@@ -37,6 +37,4 @@ describe Watchr::SmellsCollector do
37
37
  it { should be_false }
38
38
  end
39
39
  end
40
-
41
-
42
40
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 9
9
- version: 0.1.9
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Petr Janda
@@ -101,6 +101,7 @@ files:
101
101
  - lib/watchr/paths.rb
102
102
  - lib/watchr/rating.rb
103
103
  - lib/watchr/smell.rb
104
+ - lib/watchr/smell_builder.rb
104
105
  - lib/watchr/smell_types.rb
105
106
  - lib/watchr/smells_collector.rb
106
107
  - lib/watchr/version.rb
@@ -109,12 +110,14 @@ files:
109
110
  - spec/spec_helper.rb
110
111
  - spec/watchr/analyse_spec.rb
111
112
  - spec/watchr/analysers/flog_spec.rb
113
+ - spec/watchr/analysers/reek_spec.rb
112
114
  - spec/watchr/file_analyse_spec.rb
113
115
  - spec/watchr/location_spec.rb
114
116
  - spec/watchr/metrics/flay/report_spec.rb
115
117
  - spec/watchr/metrics/flog/flog_report_spec.rb
116
118
  - spec/watchr/paths_spec.rb
117
119
  - spec/watchr/rating_spec.rb
120
+ - spec/watchr/smell_builder_spec.rb
118
121
  - spec/watchr/smell_spec.rb
119
122
  - spec/watchr/smells_collector_spec.rb
120
123
  - watchr.gemspec
@@ -156,11 +159,13 @@ test_files:
156
159
  - spec/spec_helper.rb
157
160
  - spec/watchr/analyse_spec.rb
158
161
  - spec/watchr/analysers/flog_spec.rb
162
+ - spec/watchr/analysers/reek_spec.rb
159
163
  - spec/watchr/file_analyse_spec.rb
160
164
  - spec/watchr/location_spec.rb
161
165
  - spec/watchr/metrics/flay/report_spec.rb
162
166
  - spec/watchr/metrics/flog/flog_report_spec.rb
163
167
  - spec/watchr/paths_spec.rb
164
168
  - spec/watchr/rating_spec.rb
169
+ - spec/watchr/smell_builder_spec.rb
165
170
  - spec/watchr/smell_spec.rb
166
171
  - spec/watchr/smells_collector_spec.rb