abcing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43744baaa2fe4138222d3ea2808e94658983a85e
4
+ data.tar.gz: 45d5010f1b3b3d2a597d0ecac85b17c5005918ce
5
+ SHA512:
6
+ metadata.gz: 5738aeb756c8e9009cd3ba43be511476b1b22bae652fec8fce779263588c2a2e7f548cbcbb037d08345ce689fa421d0d02d72dc7f51cbdd4753e8dc806079ef0
7
+ data.tar.gz: a97b72cac034dfa1d7d6f1744f966cd470da570fad89bac6ce673913228469a5c91f873fa0c40e914020c6001367dbab5e89819dbaef6c4018928b33eb6b9f24
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Emile
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # ABCing
2
+
3
+ ![alt tag](https://s3-eu-west-1.amazonaws.com/abcing/coverage.png)
4
+
5
+ Dumbed down automated test coverage metrics.
6
+ Checks your working directory for class names, and tries to match them in the test directories.
7
+
8
+ The way this works is:
9
+
10
+ If it finds a matching class name in one of your test directories, you get a green result.
11
+ If it finds a class name in the working directory but not in the test directory, it is printed in red.
12
+ Other letters (not present in your working directory or test directories) are printed in yellow.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'abcing'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install abcing
29
+
30
+ ## Usage
31
+
32
+ abcing /path/to/project/root
33
+
34
+ Currently this only considers app/ and lib/ for the scan.
35
+ It will check spec/ and features/ for matching class names found in the working directory.
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/abcing/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
44
+
45
+ ## TODO
46
+
47
+ 1. check for presence of config file for scan params
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'abcing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "abcing"
8
+ spec.version = Abcing::VERSION
9
+ spec.authors = ["Emile"]
10
+ spec.email = ["emile.swarts123@gmail.com"]
11
+ spec.summary = %q{Dumb code metrics}
12
+ spec.description = %q{See coverage by alphabet}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['abcing']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
24
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'abcing'
4
+
5
+ working_directory = ARGV[0] || Dir.pwd
6
+
7
+ ABCing::Runner.new(working_directory).run
@@ -0,0 +1,50 @@
1
+ require 'abcing/alphabet_match'
2
+ require 'abcing/class_file_finder'
3
+ require 'abcing/class_name_finder'
4
+ require 'abcing/colour_alphabet_result'
5
+ require 'abcing/renderer'
6
+ require 'abcing/scanner'
7
+ require 'abcing/version'
8
+
9
+ module ABCing
10
+ class Runner
11
+ def initialize(working_dir)
12
+ @working_dir = working_dir
13
+ end
14
+
15
+ def run
16
+ app_directories = ["#{@working_dir}/app", "#{@working_dir}/lib"]
17
+ test_directories = ["#{@working_dir}/spec", "#{@working_dir}/features"]
18
+
19
+ params = {
20
+ app_directories: app_directories,
21
+ test_directories: test_directories }
22
+
23
+ scan_results = ABCing::Scanner.new(params).results
24
+
25
+ ABCing::Renderer.new(scan_results).render
26
+ end
27
+ end
28
+ end
29
+
30
+ class String
31
+ def colorize(color_code)
32
+ "\e[#{color_code}m#{self}\e[0m"
33
+ end
34
+
35
+ def red
36
+ colorize(31)
37
+ end
38
+
39
+ def green
40
+ colorize(32)
41
+ end
42
+
43
+ def yellow
44
+ colorize(33)
45
+ end
46
+
47
+ def pink
48
+ colorize(35)
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ module ABCing
2
+ class AlphabetMatch
3
+ def initialize(class_names)
4
+ @class_names = class_names
5
+ end
6
+
7
+ def letters
8
+ class_letters.flatten.sort.uniq
9
+ end
10
+
11
+ private
12
+
13
+ def class_letters
14
+ @class_names.map { |c| c[0] }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module ABCing
2
+ class ClassFileFinder
3
+ def initialize(directories = ['.'])
4
+ @target_directories = directories
5
+ end
6
+
7
+ def find
8
+ @target_directories.collect do |dir|
9
+ matching_files(dir)
10
+ end.flatten
11
+ end
12
+
13
+ private
14
+
15
+ def matching_files(directory)
16
+ files_for_directory(directory).select do |f|
17
+ is_class_file? f
18
+ end
19
+ end
20
+
21
+ def is_class_file?(file)
22
+ File.read(file).include?('class ')
23
+ end
24
+
25
+ def files_for_directory(directory)
26
+ Dir["#{directory}/**/*.rb"]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module ABCing
2
+ class ClassNameFinder
3
+ def initialize(contents)
4
+ @contents = contents
5
+ end
6
+
7
+ def find
8
+ @contents.collect { |c| c.scan(/class (\w+).*$/).flatten.uniq }.flatten.uniq
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ module ABCing
2
+ class ColourAlphabetResult
3
+ def initialize(params)
4
+ @test_letters = params.fetch(:test_letters)
5
+ @app_letters = params.fetch(:app_letters)
6
+ @alphabet = ('A'..'Z').to_a
7
+ end
8
+
9
+ def calculate
10
+ results = {}
11
+
12
+ @alphabet.each do |a|
13
+ results[a.to_sym] = colour(a)
14
+ end
15
+
16
+ results
17
+ end
18
+
19
+ def colour(letter)
20
+ return :green if test_letter_covered?(letter)
21
+
22
+ return :red if test_letter_not_covered?(letter)
23
+
24
+ :yellow
25
+ end
26
+
27
+ def test_letter_covered?(letter)
28
+ @app_letters.include?(letter) and @test_letters.include?(letter)
29
+ end
30
+
31
+ def test_letter_not_covered?(letter)
32
+ @app_letters.include?(letter) and !@test_letters.include?(letter)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ module ABCing
2
+ class Renderer
3
+ def initialize(scan_results)
4
+ p scan_results
5
+ @alphabet = ('A'..'Z').to_a
6
+ @scan_results = scan_results
7
+ end
8
+
9
+ def render
10
+ puts report
11
+ end
12
+
13
+ private
14
+
15
+ def report
16
+ coloured_letters.map do |coloured_letter, colour|
17
+ coloured_letter.to_s.send(colour)
18
+ end.join(' ')
19
+ end
20
+
21
+ def coloured_letters
22
+ test_letters = @scan_results.fetch(:test_letter_matches)
23
+ app_letters = @scan_results.fetch(:app_letter_matches)
24
+
25
+ params = {
26
+ test_letters: test_letters,
27
+ app_letters: app_letters }
28
+
29
+ ABCing::ColourAlphabetResult.new(params).calculate
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,52 @@
1
+ module ABCing
2
+ class Scanner
3
+ def initialize(params)
4
+ @app_directories = params.fetch(:app_directories)
5
+ @test_directories = params.fetch(:test_directories)
6
+ end
7
+
8
+ def results
9
+ test_classes = []
10
+
11
+ app_class_names.each do |a|
12
+ @test_directories.each do |t|
13
+ entries = test_class_names(a)
14
+ test_classes << entries unless entries.empty?
15
+ end
16
+ end
17
+
18
+ { test_letter_matches: first_letters(test_classes.flatten.uniq),
19
+ app_letter_matches: first_letters(app_class_names) }
20
+ end
21
+
22
+ private
23
+
24
+ def test_class_names(app_class_name)
25
+ contents(test_files).collect { |e| e.scan(/^.*(#{app_class_name}).*$/) }.flatten
26
+ end
27
+
28
+ def app_class_names
29
+ class_names contents(files @app_directories)
30
+ end
31
+
32
+ def contents(files)
33
+ files.collect { |f| File.read(f) }
34
+ end
35
+
36
+ def test_files
37
+ @test_directories.collect { |dir| Dir["#{dir}/**/*.rb"] }.flatten
38
+ end
39
+
40
+ def files(directories)
41
+ ABCing::ClassFileFinder.new(directories).find
42
+ end
43
+
44
+ def class_names(file_contents)
45
+ ABCing::ClassNameFinder.new(file_contents).find
46
+ end
47
+
48
+ def first_letters(class_names)
49
+ ABCing::AlphabetMatch.new(class_names).letters
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Abcing
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+
2
+ require_relative '../lib/abcing/alphabet_match'
3
+
4
+ describe ABCing::AlphabetMatch do
5
+ before(:each) do
6
+ Dir.mkdir 'dummy'
7
+ end
8
+
9
+ after(:each) do
10
+ FileUtils.rm_rf 'dummy'
11
+ end
12
+
13
+ it 'collects 2 letters' do
14
+ class_names = ['Bar', 'Foo']
15
+ matcher = ABCing::AlphabetMatch.new(class_names)
16
+
17
+ expect(matcher.letters).to eq(['B', 'F'])
18
+ end
19
+
20
+ it 'Only collects unique letters' do
21
+ class_names = ['Zoo', 'Zebra']
22
+
23
+ matcher = ABCing::AlphabetMatch.new(class_names)
24
+
25
+ expect(matcher.letters).to eq(['Z'])
26
+ end
27
+
28
+ it 'Orders letter results alphabetically' do
29
+ class_names = ['Cobra', 'Acid', 'Bee']
30
+
31
+ matcher = ABCing::AlphabetMatch.new(class_names)
32
+
33
+ expect(matcher.letters).to eq(['A', 'B', 'C'])
34
+ end
35
+ end
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+ require 'abcing/class_file_finder'
3
+
4
+ describe ABCing::ClassFileFinder do
5
+ before(:each) do
6
+ Dir.mkdir 'dummy'
7
+ out_file = File.new("dummy/foo.rb", "w")
8
+ out_file.puts("class Foo; end;")
9
+ out_file.close
10
+
11
+ out_file = File.new("dummy/bar.rb", "w")
12
+ out_file.puts("class Foo; end;")
13
+ out_file.close
14
+ end
15
+
16
+ after(:each) do
17
+ FileUtils.rm_rf 'dummy'
18
+ end
19
+
20
+ context 'Included files' do
21
+ it 'Finds files with class defined in them' do
22
+ expected_results = [
23
+ 'dummy/bar.rb',
24
+ 'dummy/foo.rb',
25
+ ]
26
+
27
+ finder = ABCing::ClassFileFinder.new(['dummy'])
28
+ expect(finder.find).to eq(expected_results)
29
+ end
30
+ end
31
+
32
+ context 'Excluded files' do
33
+ it 'that do not have a .rb extension' do
34
+ out_file = File.new("dummy/foo_config.txt", "w")
35
+ out_file.puts("class FooConfig; end;")
36
+ out_file.close
37
+
38
+ expected_results = [
39
+ 'dummy/bar.rb',
40
+ 'dummy/foo.rb',
41
+ ]
42
+
43
+ finder = ABCing::ClassFileFinder.new(['dummy'])
44
+ expect(finder.find).to eq(expected_results)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../lib/abcing/class_name_finder.rb'
2
+
3
+ describe ABCing::ClassNameFinder do
4
+ it 'produces class names from string input' do
5
+ content = ['class Something; end']
6
+ finder = ABCing::ClassNameFinder.new(content)
7
+ expect(finder.find).to eq(['Something'])
8
+ end
9
+
10
+ it 'Only finds unique class names' do
11
+ content = ['class Something; end
12
+ class Something; end']
13
+ finder = ABCing::ClassNameFinder.new(content)
14
+ expect(finder.find).to eq(['Something'])
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../lib/abcing/colour_alphabet_result.rb'
2
+
3
+ describe ABCing::ColourAlphabetResult do
4
+ it 'finds tested class letters' do
5
+ params = {
6
+ test_letters: ['A', 'B'],
7
+ app_letters: ['A', 'B']
8
+ }
9
+
10
+ result = ABCing::ColourAlphabetResult.new(params).calculate
11
+ expect(result).to include(A: :green, B: :green)
12
+ end
13
+
14
+ it 'does not find a test for a class letter' do
15
+ params = {
16
+ test_letters: ['A'],
17
+ app_letters: ['A', 'B']
18
+ }
19
+
20
+ result = ABCing::ColourAlphabetResult.new(params).calculate
21
+ expect(result).to include(A: :green, B: :red)
22
+ end
23
+
24
+ it 'does not find an application class or test class from the letter of the alphabet' do
25
+ params = {
26
+ test_letters: [],
27
+ app_letters: []
28
+ }
29
+
30
+ result = ABCing::ColourAlphabetResult.new(params).calculate
31
+ expect(result).to include(A: :yellow, B: :yellow)
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../lib/abcing/renderer'
2
+
3
+ describe ABCing::Renderer do
4
+ it '#render' do
5
+ scan_results = {
6
+ test_letter_matches: ["A", "B"],
7
+ app_letter_matches: ["A", "C"] }
8
+
9
+ ABCing::Renderer.new(scan_results).render
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../lib/abcing/scanner.rb'
2
+
3
+ describe ABCing::Scanner do
4
+ it 'scans' do
5
+ params = { app_directories: [], test_directories: [] }
6
+ scanner = ABCing::Scanner.new(params)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abcing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Emile
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: See coverage by alphabet
56
+ email:
57
+ - emile.swarts123@gmail.com
58
+ executables:
59
+ - abcing
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - abcing.gemspec
71
+ - bin/abcing
72
+ - lib/abcing.rb
73
+ - lib/abcing/alphabet_match.rb
74
+ - lib/abcing/class_file_finder.rb
75
+ - lib/abcing/class_name_finder.rb
76
+ - lib/abcing/colour_alphabet_result.rb
77
+ - lib/abcing/renderer.rb
78
+ - lib/abcing/scanner.rb
79
+ - lib/abcing/version.rb
80
+ - spec/alphabet_match_spec.rb
81
+ - spec/class_file_finder_spec.rb
82
+ - spec/class_name_finder_spec.rb
83
+ - spec/colour_alphabet_result_spec.rb
84
+ - spec/renderer_spec.rb
85
+ - spec/scan_result_spec.rb
86
+ homepage: ''
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Dumb code metrics
110
+ test_files:
111
+ - spec/alphabet_match_spec.rb
112
+ - spec/class_file_finder_spec.rb
113
+ - spec/class_name_finder_spec.rb
114
+ - spec/colour_alphabet_result_spec.rb
115
+ - spec/renderer_spec.rb
116
+ - spec/scan_result_spec.rb