code_poetry 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4067a9440e714228bbb8e47e2ca38d7a9bb6f60
4
- data.tar.gz: 3664dc167f75e0b183b7437e1ec1b92cb8d36448
3
+ metadata.gz: 6f35c59a997f5fcc5544ad1c8e67e46e1d8fda47
4
+ data.tar.gz: 16e6e142767e8a0c4ce0b57b1be521945c958d78
5
5
  SHA512:
6
- metadata.gz: 8e3ca8381b8338b0a31a7e2c79b7a57987e21db4821b8ebbeb2647d4611e02c046c078ff0c63822cef808a79c6c2cad226c270d4561b311f07de3ab4265e3046
7
- data.tar.gz: 153fdd0e09f92ad22993e2d8800709b265ac0b29ddc5cae3fb65506c7dc72049e6778056bdf26c9dab0f8598731da7f9e04ada6e35db91f94d191e0ee22fb4e8
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
@@ -4,6 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'rspec'
7
+ gem 'codeclimate-test-reporter', require: false
8
8
  gem 'simplecov', require: false
9
9
  end
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 [[Churn][ch]]
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.png
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.png?branch=master
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.png
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
@@ -3,8 +3,8 @@ require 'bundler/gem_tasks'
3
3
 
4
4
  Rake::TestTask.new do |test|
5
5
  test.verbose = true
6
- test.libs << 'spec'
7
- test.test_files = FileList['spec/**/*_spec.rb']
6
+ test.libs << 'test'
7
+ test.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
10
  task default: :test
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.add_development_dependency 'bundler', '~> 1.3'
22
- spec.add_development_dependency 'rake'
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.add_runtime_dependency 'code_poetry-html', ['~> 0.2']
25
- spec.add_runtime_dependency 'churn', ['~> 0.0']
26
- spec.add_runtime_dependency 'flog', ['~> 4.2']
27
- spec.add_runtime_dependency 'flay', ['~> 2.4']
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
- stat.set_churns(@churns[stat.file])
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
- private
27
+ private
27
28
 
28
- def measure_churns
29
- churns = Churn::ChurnCalculator.new(history: false).report(false)
29
+ def create_stats
30
+ @files.each do |file|
31
+ stat = Stat.new(file, @path)
30
32
 
31
- churns[:churn][:changes].each do |churn|
32
- @churns[churn[:file_path]] = churn[:times_changed]
33
+ unless stat.name.nil?
34
+ @stats << stat
35
+ end
33
36
  end
34
37
  end
35
38
 
36
- def measure_complexity
37
- @files.each do |file|
38
- stat = Stat.new(file)
39
- ComplexityCalculator.new(stat).measure
40
- @stats << stat
41
- end
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
@@ -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
@@ -21,7 +21,7 @@ module CodePoetry
21
21
  private
22
22
 
23
23
  def flog_file
24
- @flogger.flog(@stat.file)
24
+ @flogger.flog(@stat.absolute_path)
25
25
  @flogger.calculate
26
26
  end
27
27
 
@@ -39,8 +39,10 @@ module CodePoetry
39
39
 
40
40
  stats, methods = fetch_stats_and_methods(nodes)
41
41
 
42
- stats.each do |stat, method|
43
- stat.duplications << Duplication.new(severity(hash), note_type(nodes), mass, methods)
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
- method.increase_duplication_count
58
- result[1] << method
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.file == filename }
70
+ @stats.detect { |stat| stat.absolute_path == filename }
66
71
  end
67
72
 
68
73
  def severity(hash)
@@ -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
@@ -7,12 +7,14 @@ module CodePoetry
7
7
  Smell = Struct.new(:type, :object)
8
8
 
9
9
  class Stat
10
- attr_reader :duplication, :file, :lines, :lines_of_code, :name, :methods
11
- attr_accessor :churns, :complexity, :complexity_per_method, :definition_complexity
12
- attr_accessor :duplications, :smells
13
-
14
- def initialize(file)
15
- @file = file
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 { |method| method.first_line <= line && method.last_line >= line }
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 { |duplication| duplication.mass / duplication.methods.count }.inject(0, :+)
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(@file, 'r').read
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(@file, 'r').read
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, @file)
112
+ @methods << Method.new(element.first, name, first_line, last_line, @absolute_path)
107
113
  else
108
114
  scan_sexp(element)
109
115
  end
@@ -1,3 +1,3 @@
1
1
  module CodePoetry
2
- VERSION = '0.2.0'
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,8 +1,8 @@
1
- desc "Generate code metrics"
1
+ desc 'Generate code metrics'
2
2
  task :metrics, :path do |t, args|
3
3
  require 'code_poetry/cli'
4
4
 
5
- path = ARGV.last unless ARGV.last == 'metrics'
5
+ path = args.path || '.'
6
6
 
7
7
  CodePoetry::CLI.excecute(path)
8
8
  end
File without changes
File without changes
@@ -1,53 +1,64 @@
1
- require 'spec_helper'
1
+ require_relative 'test_helper'
2
2
  require_relative '../lib/code_poetry/method'
3
3
 
4
4
  describe CodePoetry::Method do
5
- let(:method) { CodePoetry::Method.new(:def, 'smelly?', 8, 10, 'path') }
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
- method.complexity = 26
10
- expect(method.smelly?).to be_true
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
- method.complexity = 25
15
- expect(method.smelly?).to be_false
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
- method.duplication_count = 1
22
- expect(method.duplicated?).to be_true
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
- method.duplication_count = 0
27
- expect(method.duplicated?).to be_false
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
- expect(method.pretty_name).to eq('.smelly?')
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
- method.node = :defs
38
- expect(method.pretty_name).to eq('#smelly?')
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 'something' do
44
- expect(method.pretty_location).to eq('path:8..10')
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
- expect { method.increase_duplication_count }.to change { method.duplication_count }.by(1)
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
- require 'spec_helper'
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
- expect(@stat.name).to eq('Foo')
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
- expect(@stat.lines.count).to eq(11)
15
- expect(@stat.lines_of_code).to eq(8)
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
- expect(@stat.methods.count).to eq(2)
23
+ @stat.methods.count.must_equal 2
20
24
 
21
25
  method = @stat.get_method('bar?')
22
- expect(method.node).to eq(:defs)
23
- expect(method.first_line).to eq(3)
24
- expect(method.last_line).to eq(5)
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
- expect(method.node).to eq(:def)
28
- expect(method.first_line).to eq(7)
29
- expect(method.last_line).to eq(9)
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
- expect(@stat.churns).to eq(10)
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
- expect { @stat.set_churns(nil) }.not_to change { @stat.churns }
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
- expect(@stat.get_method('bar?').first_line).to eq(3)
48
- expect(@stat.get_method('fooz?').first_line).to eq(7)
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
- expect(@stat.get_method('bar')).to eq(nil)
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
- expect(@stat.get_method('bar?').complexity).to eq(200)
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
- expect(@stat.definition_complexity).to eq(145)
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
- expect(@stat.get_method_at_line(3).name).to eq('bar?')
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
- expect(@stat.get_method_at_line(20)).to eq(nil)
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
- expect(@stat.smells.detect { |smell| smell.type == 'complex_class' }).to be_nil
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
- expect(@stat.smells.detect { |smell| smell.type == 'complex_class' }).to_not be_nil
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
- expect(@stat.smells.detect { |smell| smell.type == 'complex_class_definition' }).to be_nil
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
- expect(@stat.smells.detect { |smell| smell.type == 'complex_class_definition' }).to_not be_nil
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
- expect(@stat.smells.detect { |smell| smell.type == 'complex_method' }).to be_nil
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
- expect(@stat.smells.detect { |smell| smell.type == 'complex_method' }).to_not be_nil
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
- expect(@stat.smells.detect { |smell| smell.type == 'duplication' }).to be_nil
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 = [double]
139
+ @stat.duplications = [stub]
132
140
  @stat.set_smells
133
141
 
134
- expect(@stat.smells.detect { |smell| smell.type == 'duplication' }).to_not be_nil
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 = [double(mass: 10, methods: [double]), double(mass: 5, methods: [double])]
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
- expect(@stat.duplication).to eq(15)
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 'rspec/autorun'
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
- require 'spec_helper'
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 with warnings for every indendation in the source' do
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
- expect(scanner.scan(source)['def'].size).to eq(2)
14
- expect(scanner.scan(source)['def'][0]).to eq([3, 5])
15
- expect(scanner.scan(source)['def'][1]).to eq([7, 9])
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.2.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: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
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: '1.3'
20
- type: :development
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: '1.3'
26
+ version: 0.3.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: flay
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
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: '0'
40
+ version: '2.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: code_poetry-html
42
+ name: flog
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.2'
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: '0.2'
54
+ version: '4.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: churn
56
+ name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.0'
62
- type: :runtime
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: '0.0'
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
- name: flog
70
+ name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4.2'
76
- type: :runtime
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: '4.2'
82
+ version: 5.3.4
83
83
  - !ruby/object:Gem::Dependency
84
- name: flay
84
+ name: mocha
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '2.4'
90
- type: :runtime
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: '2.4'
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
- - spec/dummy_files/1.rb
127
- - spec/dummy_files/2.rb
128
- - spec/method_spec.rb
129
- - spec/spec_helper.rb
130
- - spec/stat_spec.rb
131
- - spec/warning_scanner_spec.rb
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.0.14
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
- - spec/dummy_files/1.rb
158
- - spec/dummy_files/2.rb
159
- - spec/method_spec.rb
160
- - spec/spec_helper.rb
161
- - spec/stat_spec.rb
162
- - spec/warning_scanner_spec.rb
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