code_poetry 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Gemfile +1 -1
- data/README.md +6 -6
- data/Rakefile +2 -2
- data/code_poetry.gemspec +7 -6
- data/lib/code_poetry/calculator.rb +19 -16
- data/lib/code_poetry/churn_calculator.rb +30 -0
- data/lib/code_poetry/cli.rb +1 -1
- data/lib/code_poetry/complexity_calculator.rb +1 -1
- data/lib/code_poetry/duplication_calculator.rb +10 -5
- data/lib/code_poetry/method.rb +1 -3
- data/lib/code_poetry/stat.rb +17 -11
- data/lib/code_poetry/version.rb +1 -1
- data/lib/tasks/code_poetry.rake +2 -2
- data/{spec → test}/dummy_files/1.rb +0 -0
- data/{spec → test}/dummy_files/2.rb +0 -0
- data/{spec/method_spec.rb → test/method_test.rb} +27 -16
- data/{spec/stat_spec.rb → test/stat_test.rb} +53 -32
- data/{spec/spec_helper.rb → test/test_helper.rb} +6 -1
- data/{spec/warning_scanner_spec.rb → test/warning_scanner_test.rb} +13 -6
- metadata +71 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f35c59a997f5fcc5544ad1c8e67e46e1d8fda47
|
4
|
+
data.tar.gz: 16e6e142767e8a0c4ce0b57b1be521945c958d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae820ea69f026dc1be7fcf43e9a91647856cb5798caabda62da9026cf82652f505628412d57aa6339a2b28f2988d2bfb9b22716247c22b61eb4631a550f96392
|
7
|
+
data.tar.gz: 1086ea2c0e514b3a0e68aeb2a0faf46aa5a2384a6dde95f4e7ec2ff7e8feaebcb1cf53986a64f49aa494b04fcb54016feec6c12ae0c06b36a188e52c7a808bf1
|
data/.travis.yml
CHANGED
@@ -2,3 +2,11 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
+
addons:
|
6
|
+
code_climate:
|
7
|
+
repo_token:
|
8
|
+
secure: "JJb9iyhNuNNUpnjGMWjNNIjaPOST53+vAzb6RHdzNKRC6jKgWZMXZsJ3Tzb6xFe21l+FmdBk+mKWVFHoBvUOlK34++CeXwDek8PhFi6bp7lJASqUabB66o32WPdTYnWy4WV5BesXJyFeKRL2SyFGoOw8B8Cpx+DrOVLR71s5Ovs="
|
9
|
+
notifications:
|
10
|
+
slack:
|
11
|
+
rooms:
|
12
|
+
secure: "bXtxfw97KhPDFNiS402PghKK2fvcfF4diZUWPaJu2VhRzBabveD+j4F4XQW7glRXcGzypOuCYqyTqHFXjjItO52+PEz4gUwak42UnFjHcGQ3//OeQB9bqCkR7IgyjILfWOS57JJE9XHa34p+cWnYntQ/u10rTiyivC1vfmjiufs="
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Code Poetry
|
2
2
|
|
3
|
-
[![Gem Version][rgb]][rgl] [![Build Status][trb]][trl] [![Code Climate][ccb]][ccl]
|
3
|
+
[![Gem Version][rgb]][rgl] [![Build Status][trb]][trl] [![Code Climate][ccb]][ccl] [![Code Climate][ccc]][ccl]
|
4
4
|
|
5
5
|
The poor men's [Code Climate][cc].
|
6
6
|
|
@@ -9,7 +9,7 @@ Analyzes the code of your Rails app and generates a straightforward HTML report.
|
|
9
9
|
Currently it uses the following metrics:
|
10
10
|
|
11
11
|
* Lines of Code
|
12
|
-
* Churns
|
12
|
+
* Churns
|
13
13
|
* Code Complexity [[Flog][flog]]
|
14
14
|
* Duplication [[Flay][flay]]
|
15
15
|
|
@@ -39,14 +39,14 @@ This will generate a HTML report to ```metrics/index.html```.
|
|
39
39
|
4. Push to the branch (`git push origin my-new-feature`)
|
40
40
|
5. Create new Pull Request
|
41
41
|
|
42
|
-
[rgb]: https://badge.fury.io/rb/code_poetry.
|
42
|
+
[rgb]: https://badge.fury.io/rb/code_poetry.svg
|
43
43
|
[rgl]: http://badge.fury.io/rb/code_poetry
|
44
|
-
[trb]: https://travis-ci.org/coding-chimp/code_poetry.
|
44
|
+
[trb]: https://travis-ci.org/coding-chimp/code_poetry.svg?branch=master
|
45
45
|
[trl]: https://travis-ci.org/coding-chimp/code_poetry
|
46
|
-
[ccb]: https://codeclimate.com/github/coding-chimp/code_poetry.
|
46
|
+
[ccb]: https://codeclimate.com/github/coding-chimp/code_poetry/badges/gpa.svg
|
47
47
|
[ccl]: https://codeclimate.com/github/coding-chimp/code_poetry
|
48
|
+
[ccc]: https://codeclimate.com/github/coding-chimp/code_poetry/badges/coverage.svg
|
48
49
|
|
49
50
|
[cc]: https://codeclimate.com
|
50
|
-
[ch]: https://github.com/danmayer/churn
|
51
51
|
[flog]: https://github.com/seattlerb/flog
|
52
52
|
[flay]: https://github.com/seattlerb/flay
|
data/Rakefile
CHANGED
data/code_poetry.gemspec
CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.
|
21
|
+
spec.add_runtime_dependency('code_poetry-html', '~> 0.3.1')
|
22
|
+
spec.add_runtime_dependency('flay', '~> 2.4')
|
23
|
+
spec.add_runtime_dependency('flog', '~> 4.2')
|
23
24
|
|
24
|
-
spec.
|
25
|
-
spec.
|
26
|
-
spec.
|
27
|
-
spec.
|
25
|
+
spec.add_development_dependency('bundler', '~> 1.3')
|
26
|
+
spec.add_development_dependency('minitest', '~> 5.3.4')
|
27
|
+
spec.add_development_dependency('mocha', '~> 1.1.0')
|
28
|
+
spec.add_development_dependency('rake')
|
28
29
|
end
|
@@ -1,44 +1,47 @@
|
|
1
|
-
require 'churn/calculator'
|
2
1
|
require 'code_poetry/complexity_calculator'
|
2
|
+
require 'code_poetry/churn_calculator'
|
3
3
|
require 'code_poetry/duplication_calculator'
|
4
4
|
|
5
5
|
module CodePoetry
|
6
6
|
class Calculator
|
7
|
-
def initialize(files)
|
7
|
+
def initialize(path, files)
|
8
|
+
@path = path
|
8
9
|
@files = files
|
9
|
-
@churns = {}
|
10
10
|
@stats = []
|
11
11
|
end
|
12
12
|
|
13
13
|
def calculate
|
14
14
|
puts 'Calculating'
|
15
15
|
|
16
|
+
create_stats
|
16
17
|
measure_churns
|
17
|
-
measure_complexity
|
18
18
|
measure_duplication
|
19
19
|
|
20
20
|
@stats.each do |stat|
|
21
|
-
|
21
|
+
measure_complexity(stat)
|
22
|
+
stat.set_churns(@churns[stat.relative_path])
|
22
23
|
stat.set_smells
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
+
private
|
27
28
|
|
28
|
-
def
|
29
|
-
|
29
|
+
def create_stats
|
30
|
+
@files.each do |file|
|
31
|
+
stat = Stat.new(file, @path)
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
unless stat.name.nil?
|
34
|
+
@stats << stat
|
35
|
+
end
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
|
-
def
|
37
|
-
@
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def measure_churns
|
40
|
+
@churns = ChurnCalculator.new(@path).calculate
|
41
|
+
end
|
42
|
+
|
43
|
+
def measure_complexity(stat)
|
44
|
+
ComplexityCalculator.new(stat).measure
|
42
45
|
end
|
43
46
|
|
44
47
|
def measure_duplication
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ChurnCalculator
|
2
|
+
def initialize(repo_path)
|
3
|
+
@repo_path = repo_path
|
4
|
+
end
|
5
|
+
|
6
|
+
def calculate
|
7
|
+
parse_log_for_churns
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def parse_log_for_churns
|
13
|
+
churns = {}
|
14
|
+
|
15
|
+
logs.each do |line|
|
16
|
+
churns[line] ? churns[line] += 1 : churns[line] = 1
|
17
|
+
end
|
18
|
+
|
19
|
+
churns
|
20
|
+
end
|
21
|
+
|
22
|
+
def logs
|
23
|
+
`cd #{@repo_path} && \
|
24
|
+
git log --all --name-only --format='format:' | grep -v '^$'`.split("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def sort_churns
|
28
|
+
@churns.sort! {|first,second| second[1] <=> first[1]}
|
29
|
+
end
|
30
|
+
end
|
data/lib/code_poetry/cli.rb
CHANGED
@@ -10,7 +10,7 @@ module CodePoetry
|
|
10
10
|
|
11
11
|
def self.excecute(path)
|
12
12
|
files = Array(expand_directories_to_files(path).sort).compact
|
13
|
-
calculator = Calculator.new(files)
|
13
|
+
calculator = Calculator.new(path, files)
|
14
14
|
stats = calculator.calculate
|
15
15
|
|
16
16
|
formatter = CodePoetry::Formatter::HTMLFormatter.new
|
@@ -39,8 +39,10 @@ module CodePoetry
|
|
39
39
|
|
40
40
|
stats, methods = fetch_stats_and_methods(nodes)
|
41
41
|
|
42
|
-
stats.each do |stat
|
43
|
-
|
42
|
+
stats.each do |stat|
|
43
|
+
unless methods.empty?
|
44
|
+
stat.duplications << Duplication.new(severity(hash), note_type(nodes), mass, methods)
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -54,15 +56,18 @@ module CodePoetry
|
|
54
56
|
result[0] << stat
|
55
57
|
|
56
58
|
method = stat.get_method_at_line(node.line)
|
57
|
-
|
58
|
-
|
59
|
+
|
60
|
+
unless method.nil?
|
61
|
+
method.increase_duplication_count
|
62
|
+
result[1] << method
|
63
|
+
end
|
59
64
|
|
60
65
|
result
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
69
|
def find_stat(filename)
|
65
|
-
@stats.detect { |stat| stat.
|
70
|
+
@stats.detect { |stat| stat.absolute_path == filename }
|
66
71
|
end
|
67
72
|
|
68
73
|
def severity(hash)
|
data/lib/code_poetry/method.rb
CHANGED
@@ -10,8 +10,7 @@ module CodePoetry
|
|
10
10
|
@last_line = last_line
|
11
11
|
@complexity = 0
|
12
12
|
@duplication_count = 0
|
13
|
-
|
14
|
-
@location = location
|
13
|
+
@location = location.sub './', ''
|
15
14
|
end
|
16
15
|
|
17
16
|
def smelly?
|
@@ -34,6 +33,5 @@ module CodePoetry
|
|
34
33
|
def increase_duplication_count
|
35
34
|
@duplication_count =+ 1
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
37
|
end
|
data/lib/code_poetry/stat.rb
CHANGED
@@ -7,12 +7,14 @@ module CodePoetry
|
|
7
7
|
Smell = Struct.new(:type, :object)
|
8
8
|
|
9
9
|
class Stat
|
10
|
-
attr_reader :
|
11
|
-
|
12
|
-
attr_accessor :
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
attr_reader :absolute_path, :duplication, :lines, :lines_of_code, :name
|
11
|
+
attr_reader :methods, :relative_path
|
12
|
+
attr_accessor :churns, :complexity, :complexity_per_method
|
13
|
+
attr_accessor :definition_complexity, :duplications, :smells
|
14
|
+
|
15
|
+
def initialize(path, project_path)
|
16
|
+
@absolute_path = path
|
17
|
+
@relative_path = path.sub("#{project_path}/", '')
|
16
18
|
@lines_of_code, @churns = 0, 0
|
17
19
|
@complexity, @complexity_per_method, @definition_complexity = 0, 0, 0
|
18
20
|
@methods, @smells, @duplications = [], [], []
|
@@ -38,7 +40,9 @@ module CodePoetry
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def get_method_at_line(line)
|
41
|
-
@methods.detect
|
43
|
+
@methods.detect do |method|
|
44
|
+
method.first_line <= line && method.last_line >= line
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
def set_smells
|
@@ -48,7 +52,9 @@ module CodePoetry
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def duplication
|
51
|
-
@duplications.map
|
55
|
+
@duplications.map do |duplication|
|
56
|
+
duplication.mass / duplication.methods.count
|
57
|
+
end.inject(0, :+)
|
52
58
|
end
|
53
59
|
|
54
60
|
def round_definition_complexity
|
@@ -58,7 +64,7 @@ module CodePoetry
|
|
58
64
|
private
|
59
65
|
|
60
66
|
def parse_file
|
61
|
-
@content = File.open(@
|
67
|
+
@content = File.open(@absolute_path, 'r').read
|
62
68
|
@indentation_warnings = indentation_warnings
|
63
69
|
|
64
70
|
set_name
|
@@ -67,7 +73,7 @@ module CodePoetry
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def set_name
|
70
|
-
@content = File.open(@
|
76
|
+
@content = File.open(@absolute_path, 'r').read
|
71
77
|
|
72
78
|
if match = /^\s*class\s+(\S+)/.match(@content) || /^\s*module\s+(\S+)/.match(@content)
|
73
79
|
@name = match[1]
|
@@ -103,7 +109,7 @@ module CodePoetry
|
|
103
109
|
last_line = find_last_line(name, first_line)
|
104
110
|
end
|
105
111
|
|
106
|
-
@methods << Method.new(element.first, name, first_line, last_line, @
|
112
|
+
@methods << Method.new(element.first, name, first_line, last_line, @absolute_path)
|
107
113
|
else
|
108
114
|
scan_sexp(element)
|
109
115
|
end
|
data/lib/code_poetry/version.rb
CHANGED
data/lib/tasks/code_poetry.rake
CHANGED
File without changes
|
File without changes
|
@@ -1,53 +1,64 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
require_relative '../lib/code_poetry/method'
|
3
3
|
|
4
4
|
describe CodePoetry::Method do
|
5
|
-
let(:
|
5
|
+
let(:meth) { CodePoetry::Method.new(:def, 'smelly?', 8, 10, 'path') }
|
6
6
|
|
7
7
|
describe '#smelly?' do
|
8
8
|
it 'returns true if the complexity is greater 25' do
|
9
|
-
|
10
|
-
|
9
|
+
meth.complexity = 26
|
10
|
+
|
11
|
+
meth.smelly?.must_equal true
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'returns false if the complexity is less or equal 25' do
|
14
|
-
|
15
|
-
|
15
|
+
meth.complexity = 25
|
16
|
+
|
17
|
+
meth.smelly?.must_equal false
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
describe '#duplicated?' do
|
20
22
|
it 'returns true if the duplication count is greater 0' do
|
21
|
-
|
22
|
-
|
23
|
+
meth.duplication_count = 1
|
24
|
+
|
25
|
+
meth.duplicated?.must_equal true
|
23
26
|
end
|
24
27
|
|
25
28
|
it 'returns false if the duplication count is equal 0' do
|
26
|
-
|
27
|
-
|
29
|
+
meth.duplication_count = 0
|
30
|
+
|
31
|
+
meth.duplicated?.must_equal false
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
describe '#pretty_name' do
|
32
36
|
it 'prepends a "." to the name if the method is an instance method' do
|
33
|
-
|
37
|
+
meth.node = :def
|
38
|
+
|
39
|
+
meth.pretty_name.must_equal '.smelly?'
|
34
40
|
end
|
35
41
|
|
36
42
|
it 'prepends a "#" to the name if the method is an class method' do
|
37
|
-
|
38
|
-
|
43
|
+
meth.node = :defs
|
44
|
+
|
45
|
+
meth.pretty_name.must_equal'#smelly?'
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
49
|
describe '#pretty_location' do
|
43
|
-
it '
|
44
|
-
|
50
|
+
it 'returns the location and line number range' do
|
51
|
+
meth.pretty_location.must_equal 'path:8..10'
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
48
55
|
describe '#increase_duplication_count' do
|
49
56
|
it 'increases the duplication count by 1' do
|
50
|
-
|
57
|
+
before = meth.duplication_count
|
58
|
+
|
59
|
+
meth.increase_duplication_count
|
60
|
+
|
61
|
+
meth.duplication_count.must_equal before + 1
|
51
62
|
end
|
52
63
|
end
|
53
64
|
end
|
@@ -1,32 +1,36 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
require_relative '../lib/code_poetry/stat'
|
3
3
|
|
4
4
|
describe CodePoetry::Stat do
|
5
|
-
before(:all) { @stat = CodePoetry::Stat.new(test_file(2)) }
|
5
|
+
before(:all) { @stat = CodePoetry::Stat.new(test_file(2), '') }
|
6
6
|
after(:each) { @stat.smells = [] }
|
7
7
|
|
8
8
|
describe '#initialize' do
|
9
9
|
it 'sets the correct stat name' do
|
10
|
-
|
10
|
+
stat = CodePoetry::Stat.new(test_file(1), '')
|
11
|
+
|
12
|
+
@stat.name.must_equal 'Foo'
|
13
|
+
stat.name.must_equal 'Foo'
|
14
|
+
stat
|
11
15
|
end
|
12
16
|
|
13
17
|
it 'counts the correct number of lines and lines of code' do
|
14
|
-
|
15
|
-
|
18
|
+
@stat.lines.count.must_equal 11
|
19
|
+
@stat.lines_of_code.must_equal 8
|
16
20
|
end
|
17
21
|
|
18
22
|
it 'sets the methods correctly' do
|
19
|
-
|
23
|
+
@stat.methods.count.must_equal 2
|
20
24
|
|
21
25
|
method = @stat.get_method('bar?')
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
method.node.must_equal :defs
|
27
|
+
method.first_line.must_equal 3
|
28
|
+
method.last_line.must_equal 5
|
25
29
|
|
26
30
|
method = @stat.get_method('fooz?')
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
method.node.must_equal :def
|
32
|
+
method.first_line.must_equal 7
|
33
|
+
method.last_line.must_equal 9
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
@@ -34,22 +38,26 @@ describe CodePoetry::Stat do
|
|
34
38
|
it 'sets the churns' do
|
35
39
|
@stat.set_churns(10)
|
36
40
|
|
37
|
-
|
41
|
+
@stat.churns.must_equal 10
|
38
42
|
end
|
39
43
|
|
40
44
|
it 'leaves the churns alone, if the param is nil' do
|
41
|
-
|
45
|
+
before = @stat.churns
|
46
|
+
|
47
|
+
@stat.set_churns(nil)
|
48
|
+
|
49
|
+
@stat.churns.must_equal before
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
45
53
|
describe '#get_method' do
|
46
54
|
it 'returns the method with the specified name' do
|
47
|
-
|
48
|
-
|
55
|
+
@stat.get_method('bar?').first_line.must_equal 3
|
56
|
+
@stat.get_method('fooz?').first_line.must_equal 7
|
49
57
|
end
|
50
58
|
|
51
59
|
it 'returns nil if there is no method with the specified name' do
|
52
|
-
|
60
|
+
@stat.get_method('bar').must_equal nil
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
@@ -57,24 +65,24 @@ describe CodePoetry::Stat do
|
|
57
65
|
it 'sets the complexity of the method with the specified name' do
|
58
66
|
@stat.set_method_complexity('bar?', 200)
|
59
67
|
|
60
|
-
|
68
|
+
@stat.get_method('bar?').complexity.must_equal 200
|
61
69
|
end
|
62
70
|
|
63
71
|
it 'adds the complexity to the definition_complexity if there is no method with the specified name' do
|
64
72
|
@stat.definition_complexity = 25
|
65
73
|
@stat.set_method_complexity('baz', 120)
|
66
74
|
|
67
|
-
|
75
|
+
@stat.definition_complexity.must_equal 145
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
71
79
|
describe '#get_method_at_line' do
|
72
80
|
it 'return the method at the specified line' do
|
73
|
-
|
81
|
+
@stat.get_method_at_line(3).name.must_equal 'bar?'
|
74
82
|
end
|
75
83
|
|
76
84
|
it 'returns nil if there is no mehtod at the specified line' do
|
77
|
-
|
85
|
+
@stat.get_method_at_line(20).must_equal nil
|
78
86
|
end
|
79
87
|
end
|
80
88
|
|
@@ -83,63 +91,76 @@ describe CodePoetry::Stat do
|
|
83
91
|
@stat.complexity = 150
|
84
92
|
@stat.set_smells
|
85
93
|
|
86
|
-
|
94
|
+
@stat.smells.detect { |smell| smell.type == 'complex_class' }.must_be_nil
|
87
95
|
end
|
88
96
|
|
89
97
|
it 'creates a complex_class smell if the overall complexity is greater 150' do
|
90
98
|
@stat.complexity = 151
|
91
99
|
@stat.set_smells
|
92
100
|
|
93
|
-
|
101
|
+
@stat.smells.detect { |smell| smell.type == 'complex_class' }.wont_be_nil
|
94
102
|
end
|
95
103
|
|
96
104
|
it 'creates no complex_class_definition smell if the definition complexity is less 41' do
|
97
105
|
@stat.definition_complexity = 40
|
98
106
|
@stat.set_smells
|
99
107
|
|
100
|
-
|
108
|
+
@stat.smells.detect { |smell| smell.type == 'complex_class_definition' }.must_be_nil
|
101
109
|
end
|
102
110
|
|
103
111
|
it 'creates a complex_class_definition smell if the definition complexity is greater 40' do
|
104
112
|
@stat.definition_complexity = 41
|
105
113
|
@stat.set_smells
|
106
114
|
|
107
|
-
|
115
|
+
@stat.smells.detect { |smell| smell.type == 'complex_class_definition' }.wont_be_nil
|
108
116
|
end
|
109
117
|
|
110
118
|
it 'creates no complex_method smell if no methods complexity is greater 25' do
|
111
119
|
@stat.set_method_complexity('bar?', 2)
|
112
120
|
@stat.set_smells
|
113
121
|
|
114
|
-
|
122
|
+
@stat.smells.detect { |smell| smell.type == 'complex_method' }.must_be_nil
|
115
123
|
end
|
116
124
|
|
117
125
|
it 'creates a complex_method smell if a methods complexity is greater 25' do
|
118
126
|
@stat.set_method_complexity('bar?', 26)
|
119
127
|
@stat.set_smells
|
120
128
|
|
121
|
-
|
129
|
+
@stat.smells.detect { |smell| smell.type == 'complex_method' }.wont_be_nil
|
122
130
|
end
|
123
131
|
|
124
132
|
it 'creates no duplication smell if there is no duplication' do
|
125
133
|
@stat.set_smells
|
126
134
|
|
127
|
-
|
135
|
+
@stat.smells.detect { |smell| smell.type == 'duplication' }.must_be_nil
|
128
136
|
end
|
129
137
|
|
130
138
|
it 'creates a duplication smell if there is duplication' do
|
131
|
-
@stat.duplications = [
|
139
|
+
@stat.duplications = [stub]
|
132
140
|
@stat.set_smells
|
133
141
|
|
134
|
-
|
142
|
+
@stat.smells.detect { |smell| smell.type == 'duplication' }.wont_be_nil
|
135
143
|
end
|
136
144
|
end
|
137
145
|
|
138
146
|
describe '#duplication' do
|
139
147
|
it 'adds up the masses of the duplications' do
|
140
|
-
@stat.duplications = [
|
148
|
+
@stat.duplications = [
|
149
|
+
stub(mass: 10, methods: [stub]),
|
150
|
+
stub(mass: 5, methods: [stub])
|
151
|
+
]
|
152
|
+
|
153
|
+
@stat.duplication.must_equal 15
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#round_definition_complexity' do
|
158
|
+
it 'should rount the definition complexity' do
|
159
|
+
@stat.definition_complexity = 2.15
|
160
|
+
|
161
|
+
@stat.round_definition_complexity
|
141
162
|
|
142
|
-
|
163
|
+
@stat.definition_complexity.must_equal 2
|
143
164
|
end
|
144
165
|
end
|
145
166
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
1
4
|
require 'simplecov'
|
2
5
|
SimpleCov.start do
|
3
6
|
add_filter 'spec'
|
4
7
|
end if ENV['COVERAGE']
|
5
8
|
|
6
|
-
require '
|
9
|
+
require 'minitest/autorun'
|
10
|
+
require 'mocha/mini_test'
|
11
|
+
require 'minitest/pride'
|
7
12
|
|
8
13
|
def test_file(file_name)
|
9
14
|
File.join(
|
@@ -1,18 +1,25 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
require_relative '../lib/code_poetry/warning_scanner'
|
3
3
|
|
4
4
|
describe CodePoetry::WarningScanner do
|
5
5
|
let(:scanner) { CodePoetry::WarningScanner.new }
|
6
6
|
|
7
7
|
describe '#scan' do
|
8
|
-
it 'returns an array
|
8
|
+
it 'returns an empty array if there are no warnings' do
|
9
|
+
require 'bundler'
|
9
10
|
source = File.open(test_file(1), 'r').read
|
10
|
-
expect(scanner.scan(source).size).to eq(0)
|
11
11
|
|
12
|
+
scanner.scan(source).size.must_equal 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns an array with warnings for every indendation in the source' do
|
12
16
|
source = File.open(test_file(2), 'r').read
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
|
18
|
+
warnings = scanner.scan(source)
|
19
|
+
|
20
|
+
warnings['def'].size.must_equal 2
|
21
|
+
warnings['def'][0].must_equal [3, 5]
|
22
|
+
warnings['def'][1].must_equal [7, 9]
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
metadata
CHANGED
@@ -1,99 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_poetry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bastian Bartmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: code_poetry-html
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: 0.3.1
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.3.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: flay
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '2.4'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: flog
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :
|
75
|
+
version: 5.3.4
|
76
|
+
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 5.3.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: mocha
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
type: :
|
89
|
+
version: 1.1.0
|
90
|
+
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Analyzes the code of your Rails app and generates a straightforward HTML
|
98
112
|
report.
|
99
113
|
email:
|
@@ -102,10 +116,10 @@ executables: []
|
|
102
116
|
extensions: []
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
105
|
-
- .gitignore
|
106
|
-
- .hound.yml
|
107
|
-
- .rspec
|
108
|
-
- .travis.yml
|
119
|
+
- ".gitignore"
|
120
|
+
- ".hound.yml"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
109
123
|
- Gemfile
|
110
124
|
- LICENSE
|
111
125
|
- README.md
|
@@ -113,6 +127,7 @@ files:
|
|
113
127
|
- code_poetry.gemspec
|
114
128
|
- lib/code_poetry.rb
|
115
129
|
- lib/code_poetry/calculator.rb
|
130
|
+
- lib/code_poetry/churn_calculator.rb
|
116
131
|
- lib/code_poetry/cli.rb
|
117
132
|
- lib/code_poetry/complexity_calculator.rb
|
118
133
|
- lib/code_poetry/duplication_calculator.rb
|
@@ -123,12 +138,12 @@ files:
|
|
123
138
|
- lib/code_poetry/version.rb
|
124
139
|
- lib/code_poetry/warning_scanner.rb
|
125
140
|
- lib/tasks/code_poetry.rake
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
131
|
-
-
|
141
|
+
- test/dummy_files/1.rb
|
142
|
+
- test/dummy_files/2.rb
|
143
|
+
- test/method_test.rb
|
144
|
+
- test/stat_test.rb
|
145
|
+
- test/test_helper.rb
|
146
|
+
- test/warning_scanner_test.rb
|
132
147
|
homepage: https://github.com/coding-chimp/code_poetry
|
133
148
|
licenses:
|
134
149
|
- MIT
|
@@ -139,25 +154,24 @@ require_paths:
|
|
139
154
|
- lib
|
140
155
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
156
|
requirements:
|
142
|
-
- -
|
157
|
+
- - ">="
|
143
158
|
- !ruby/object:Gem::Version
|
144
159
|
version: '0'
|
145
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
161
|
requirements:
|
147
|
-
- -
|
162
|
+
- - ">="
|
148
163
|
- !ruby/object:Gem::Version
|
149
164
|
version: '0'
|
150
165
|
requirements: []
|
151
166
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.4.5
|
153
168
|
signing_key:
|
154
169
|
specification_version: 4
|
155
170
|
summary: The poor men's Code Climate
|
156
171
|
test_files:
|
157
|
-
-
|
158
|
-
-
|
159
|
-
-
|
160
|
-
-
|
161
|
-
-
|
162
|
-
-
|
163
|
-
has_rdoc:
|
172
|
+
- test/dummy_files/1.rb
|
173
|
+
- test/dummy_files/2.rb
|
174
|
+
- test/method_test.rb
|
175
|
+
- test/stat_test.rb
|
176
|
+
- test/test_helper.rb
|
177
|
+
- test/warning_scanner_test.rb
|