simplecov-phabricator 0.0.1

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.
@@ -0,0 +1,6 @@
1
+ /coverage
2
+ /.bundle
3
+ /.idea
4
+ /.project
5
+ /.rspec
6
+ /pmip
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ group :test, :development do
4
+ gem 'rake'
5
+ gem 'minitest'
6
+ gem 'simplecov'
7
+ end
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ docile (1.1.0)
5
+ minitest (5.0.8)
6
+ multi_json (1.8.2)
7
+ rake (10.1.0)
8
+ simplecov (0.8.2)
9
+ docile (~> 1.1.0)
10
+ multi_json
11
+ simplecov-html (~> 0.8.0)
12
+ simplecov-html (0.8.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ minitest
19
+ rake
20
+ simplecov
@@ -0,0 +1,20 @@
1
+ = Simplecov Phabricator Formatter
2
+
3
+ The target of this formatter is Phabricator compliant code coverage report. More details at: https://secure.phabricator.com/book/phabricator/article/arcanist_coverage/
4
+
5
+ = Install
6
+
7
+ gem install simplecov-phabricator
8
+
9
+ = Usage
10
+
11
+ Add the gem to the Gemfile preferably in the group test:
12
+
13
+ gem 'simplecov', require: false
14
+ gem 'simplecov-phabricator', require: false
15
+
16
+ Enable formatter:
17
+ require 'simplecov'
18
+ require 'simplecov-phabricator'
19
+ SimpleCov.formatter = SimpleCov::Formatter::PhabricatorFormatter
20
+
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rake/testtask'
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.pattern = "test/test_*.rb"
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,60 @@
1
+ require 'fileutils'
2
+ require 'time'
3
+ require 'pathname'
4
+ require 'json'
5
+
6
+ unless defined?(SimpleCov)
7
+ raise RuntimeError, "simplecov-phabricator is a formatter for simplecov. Please update your test helper and gemfile to require 'simplecov'!"
8
+ end
9
+
10
+ class SimpleCov::Formatter::PhabricatorFormatter
11
+ def format( result )
12
+ coverage_report = {}
13
+ result.files.each do |file|
14
+ file_path = rails_file_path(file.filename)
15
+ coverage_report[file_path] = format_file_coverage(file)
16
+ end
17
+ save_coverage_report(coverage_report)
18
+ end
19
+
20
+ def self.output_path
21
+ SimpleCov.coverage_path
22
+ end
23
+
24
+ def self.file_name
25
+ 'phabricator-coverage.json'
26
+ end
27
+
28
+ private
29
+
30
+ def save_coverage_report(coverage)
31
+ output_filepath = File.join(SimpleCov::Formatter::PhabricatorFormatter.output_path,
32
+ SimpleCov::Formatter::PhabricatorFormatter.file_name)
33
+
34
+ File.open( output_filepath, "w" ) do |file_result|
35
+ file_result.write coverage.to_json
36
+ end
37
+ end
38
+
39
+ def rails_file_path(filename)
40
+ if defined?(Rails)
41
+ Pathname.new(filename).relative_path_from(Rails.root).to_s
42
+ else
43
+ filename
44
+ end
45
+ end
46
+
47
+ def format_file_coverage(file)
48
+ file.lines.map do |file_line|
49
+ if file_line.covered?
50
+ 'C' # C Covered. This line has test coverage.
51
+ elsif file_line.missed?
52
+ 'U' # U Uncovered. This line is executable but has no test coverage.
53
+ elsif file_line.never? || file_line.skipped?
54
+ 'N' # N Not executable. This is a comment or whitespace which should be ignored when computing test coverage.
55
+ else
56
+ ' '
57
+ end
58
+ end.join
59
+ end
60
+ end
@@ -0,0 +1,8 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class PhabricatorFormatter
4
+ VERSION = "0.0.1"
5
+ UPSTREAM_URL = "https://github.com/chetane/simplecov-phabricator"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "simplecov-phabricator/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "simplecov-phabricator"
7
+ s.version = SimpleCov::Formatter::PhabricatorFormatter::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Omar Skalli"]
10
+ s.email = ["chetane@gmail.com"]
11
+ s.homepage = SimpleCov::Formatter::PhabricatorFormatter::UPSTREAM_URL
12
+ s.summary = %q{A Simplecov Phabricator Formatter}
13
+ s.description = %q{A Simplevoc Formatter compatible with Phabricator's code review format.}
14
+ s.license = 'MIT'
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+
19
+ s.rubyforge_project = "simplecov-phabricator"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,13 @@
1
+ class SomeClass
2
+ def method_1
3
+ 1+1
4
+ end
5
+
6
+ def method_2 ( value )
7
+ value * value
8
+ end
9
+
10
+ def method_3
11
+ "über"
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ require 'minitest'
2
+ require 'minitest/autorun'
3
+ require 'minitest/unit'
4
+ require 'simplecov'
5
+
6
+ require 'simplecov-phabricator'
7
+
8
+ class TestSimpleCovFormatterPhabricatorFormatter < MiniTest::Test
9
+ def setup
10
+ @rcov_file = File.join( SimpleCov::Formatter::PhabricatorFormatter.output_path, SimpleCov::Formatter::PhabricatorFormatter.file_name)
11
+ File.delete( @rcov_file ) if File.exists?( @rcov_file )
12
+
13
+ @result = SimpleCov::Result.new(
14
+ {
15
+ File.expand_path( File.join( File.dirname( __FILE__ ), 'fixtures', 'some_class.rb' ) ) =>
16
+ [1,1,1,1,nil,1,0,1,1,nil,0,1,1]
17
+ }
18
+ )
19
+
20
+ # Set to default encoding
21
+ Encoding.default_internal = nil if defined?(Encoding)
22
+ end
23
+
24
+ def test_format
25
+ SimpleCov::Formatter::PhabricatorFormatter.new.format( @result )
26
+
27
+ assert File.exists?( @rcov_file )
28
+ end
29
+
30
+ def test_encoding
31
+ # This is done in many rails environments
32
+ Encoding.default_internal = 'UTF-8' if defined?(Encoding)
33
+
34
+ SimpleCov::Formatter::PhabricatorFormatter.new.format( @result )
35
+ end
36
+
37
+ def test_create_content
38
+ SimpleCov::Formatter::PhabricatorFormatter.new.format( @result )
39
+ content = File.open(@rcov_file, "r").read
40
+ assert_match(/{".+some_class\.rb":"CCCCNCUCCNUCC"}/, content)
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-phabricator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Omar Skalli
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Simplevoc Formatter compatible with Phabricator's code review format.
15
+ email:
16
+ - chetane@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.rdoc
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.rdoc
26
+ - Rakefile
27
+ - lib/simplecov-phabricator.rb
28
+ - lib/simplecov-phabricator/version.rb
29
+ - simplecov-phabricator.gemspec
30
+ - test/fixtures/some_class.rb
31
+ - test/test_simplecov-phabricator.rb
32
+ homepage: https://github.com/chetane/simplecov-phabricator
33
+ licenses:
34
+ - MIT
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: simplecov-phabricator
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: A Simplecov Phabricator Formatter
57
+ test_files:
58
+ - test/fixtures/some_class.rb
59
+ - test/test_simplecov-phabricator.rb