minitest-flog 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/minitest/flog.rb +12 -0
- data/lib/minitest/flog/assertions.rb +57 -0
- data/lib/minitest/flog/reporter.rb +30 -0
- data/lib/minitest/flog/test.rb +23 -0
- data/lib/minitest/flog/version.rb +5 -0
- data/lib/minitest/flog_plugin.rb +16 -0
- data/minitest-flog.gemspec +27 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47f3bbf4f167da612be5dd39f6bff7ccdff80435
|
4
|
+
data.tar.gz: 43716da3ccac152b7b010078a09a9619801862d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97a926d9693c36d87142039608038a8399e3d64d3e16767a6b0bae85eb3a65d673e96a7ab868780a42057e3bf9a07c8f32b70a31646424b58787db1fa8f53cf4
|
7
|
+
data.tar.gz: 67ea644b62ffcf6fdcb8d4cc1d38e9c4b98559df8d752d4f298484d873d94efc159d004b5ea397e5ce0adef0b062cc27613f9fd1c2e30cc88736bbab1358f9b9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chris Kottom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# minitest-flog
|
2
|
+
|
3
|
+
Beat your code, see where it bleeds.
|
4
|
+
|
5
|
+
Flog analyzes Ruby code for signs of complexity and produces a numeric score
|
6
|
+
for each method and class in every file it scans. A higher score is indicative
|
7
|
+
of more complex constructs and therefore refactoring opportunities.
|
8
|
+
|
9
|
+
This gem integrates Flog directly into your project's test suite so that you're
|
10
|
+
automatically alerted to any additions or updates that will lead to pain down
|
11
|
+
the line.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'minitest-flog'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install minitest-flog
|
28
|
+
|
29
|
+
You'll need to require the library in your test helper:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require "minitest/flog"
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
minitest-flog introduces a new Minitest::Flog::Test class that you'll
|
38
|
+
use to make any assertions about complexity in your project.
|
39
|
+
|
40
|
+
Create a new test by subclassing Minitest::Flog::Test. You can then make
|
41
|
+
assertions about the Flog scoring you expect to calculate for code in selected
|
42
|
+
directories in your project. The example below has two assertions:
|
43
|
+
|
44
|
+
* No method should have a score over 100.0.
|
45
|
+
* 95% of all methods should have scores less than or equal to 40.0.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class MyProjectFlogger < Minitest::Test
|
49
|
+
def flog_lib
|
50
|
+
assert_method_score("lib", score: 100.0)
|
51
|
+
assert_method_score("lib", score: 40.0, ratio: 0.95)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Invoking your tests with the `-f` or `--flog` option will turn on extended
|
57
|
+
Flog-like reporting in case of a failure.
|
58
|
+
|
59
|
+
## To-Dos
|
60
|
+
|
61
|
+
* Implement Minitest::Spec compatibility
|
62
|
+
* Threadsafe access to class variables
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/[my-github-username]/minitest-flog/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The MIT License (MIT)
|
75
|
+
|
76
|
+
Copyright (c) 2015 Chris Kottom
|
77
|
+
|
78
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
79
|
+
of this software and associated documentation files (the "Software"), to deal
|
80
|
+
in the Software without restriction, including without limitation the rights
|
81
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
82
|
+
copies of the Software, and to permit persons to whom the Software is
|
83
|
+
furnished to do so, subject to the following conditions:
|
84
|
+
|
85
|
+
The above copyright notice and this permission notice shall be included in
|
86
|
+
all copies or substantial portions of the Software.
|
87
|
+
|
88
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
89
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
90
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
91
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
92
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
93
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
94
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "minitest/flog"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "flog_cli"
|
2
|
+
|
3
|
+
module Minitest
|
4
|
+
module Flog
|
5
|
+
module Assertions
|
6
|
+
DEFAULT_FLOG_OPTIONS = { all: true, continue: true }
|
7
|
+
DEFAULT_METHOD_OPTIONS = { score: 40.0, ratio: 1.0 }
|
8
|
+
|
9
|
+
attr_accessor :filtered, :dir, :threshold
|
10
|
+
|
11
|
+
def assert_method_score(dir, options = {})
|
12
|
+
options = DEFAULT_METHOD_OPTIONS.merge options
|
13
|
+
self.dir = dir
|
14
|
+
self.threshold = options[:score]
|
15
|
+
|
16
|
+
scores = _flog_scores_for_directory(dir)
|
17
|
+
self.filtered = scores.select { |method, score| score > options[:score] }
|
18
|
+
|
19
|
+
score_count = scores.count.to_f.round(2)
|
20
|
+
filtered_count = self.filtered.count.to_f.round(2)
|
21
|
+
msg = options[:msg] || message(options[:score], options[:ratio],
|
22
|
+
1.0 - (filtered_count / score_count))
|
23
|
+
assert (filtered_count / score_count) <= (1.0 - options[:ratio]), msg
|
24
|
+
end
|
25
|
+
|
26
|
+
def _flog_scores_for_directory(dir)
|
27
|
+
flog = flog_for(dir)
|
28
|
+
scores = {}
|
29
|
+
flog.each_by_score do |method, score, list|
|
30
|
+
scores[method] = score
|
31
|
+
end
|
32
|
+
scores
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def flog_for(dir)
|
38
|
+
hash = FlogCLI.expand_dirs_to_files(dir).hash
|
39
|
+
|
40
|
+
unless flog = Minitest::Flog.flogs[hash]
|
41
|
+
flog = FlogCLI.new DEFAULT_FLOG_OPTIONS
|
42
|
+
result = flog.flog dir
|
43
|
+
Minitest::Flog.flogs[hash] = flog
|
44
|
+
self.flog = flog
|
45
|
+
end
|
46
|
+
flog
|
47
|
+
end
|
48
|
+
|
49
|
+
def message(score, expected_ratio, actual_ratio)
|
50
|
+
expected_percent = sprintf("%.1f", expected_ratio * 100)
|
51
|
+
actual_percent = sprintf("%.1f", actual_ratio * 100)
|
52
|
+
"Expected #{ expected_percent }% of flogged methods to have " +
|
53
|
+
"score < #{ score } (actual: #{ actual_percent }%)"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "minitest"
|
2
|
+
|
3
|
+
module Minitest
|
4
|
+
module Flog
|
5
|
+
class Reporter < Minitest::Reporter
|
6
|
+
attr_accessor :failed_flogs
|
7
|
+
|
8
|
+
def initialize(io = $stdout, options = {})
|
9
|
+
super
|
10
|
+
self.failed_flogs = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def record(result)
|
14
|
+
if result.is_a?(Minitest::Flog::Test) && result.failure
|
15
|
+
self.failed_flogs << result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def report
|
20
|
+
return unless self.options[:flog] && self.failed_flogs.any?
|
21
|
+
|
22
|
+
result = "\nFlog reporting"
|
23
|
+
failed_flogs.each do |f|
|
24
|
+
result << f.detail_report
|
25
|
+
end
|
26
|
+
self.io.print result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Minitest
|
2
|
+
module Flog
|
3
|
+
class Test < ::Minitest::Test
|
4
|
+
include Assertions
|
5
|
+
|
6
|
+
attr_accessor :flog
|
7
|
+
|
8
|
+
def self.runnable_methods
|
9
|
+
methods_matching(/^flog_/)
|
10
|
+
end
|
11
|
+
|
12
|
+
def detail_report
|
13
|
+
path = File.expand_path(self.dir)
|
14
|
+
result = "\n #{ path }:\n"
|
15
|
+
flog.each_by_score do |method, score, list|
|
16
|
+
break if score < self.threshold
|
17
|
+
result << sprintf(" %8.1f %s\n", score, method)
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "minitest"
|
2
|
+
require "flog"
|
3
|
+
|
4
|
+
module Minitest
|
5
|
+
def self.plugin_flog_options(opts, options)
|
6
|
+
opts.on "-f", "--flog", "Display a detailed Flog report output" do |f|
|
7
|
+
options[:flog] = true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.plugin_flog_init(options)
|
12
|
+
if options[:flog]
|
13
|
+
self.reporter << Minitest::Flog::Reporter.new(options[:io], options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'minitest/flog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "minitest-flog"
|
8
|
+
spec.version = Minitest::Flog::VERSION
|
9
|
+
spec.authors = ["Chris Kottom"]
|
10
|
+
spec.email = ["chris@chriskottom.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Flog integration for Minitest}
|
13
|
+
spec.description = %q{Uses Flog to test code complexity during testing}
|
14
|
+
spec.homepage = "https://github.com/chriskottom/minitest-flog"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "minitest", "~> 5.5"
|
23
|
+
spec.add_dependency "flog", "~> 4.3"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-flog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Kottom
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: flog
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Uses Flog to test code complexity during testing
|
70
|
+
email:
|
71
|
+
- chris@chriskottom.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/minitest/flog.rb
|
86
|
+
- lib/minitest/flog/assertions.rb
|
87
|
+
- lib/minitest/flog/reporter.rb
|
88
|
+
- lib/minitest/flog/test.rb
|
89
|
+
- lib/minitest/flog/version.rb
|
90
|
+
- lib/minitest/flog_plugin.rb
|
91
|
+
- minitest-flog.gemspec
|
92
|
+
homepage: https://github.com/chriskottom/minitest-flog
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Flog integration for Minitest
|
116
|
+
test_files: []
|