simplecov-erb 0.1.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: 0eed6797c57ce3b0fb1821eb26033537cfc88c39
4
+ data.tar.gz: 207c7c995409242b6cc648d027a60276488ea9f0
5
+ SHA512:
6
+ metadata.gz: b2f8a2dc5489a6f1d66b0754ee69bcb136a6a7e9672c8c8d8e2e1c18627e69e211f860a092e4ff36149450358e55ca77bae8efb4d5a8352c36f58fa2247d7d17
7
+ data.tar.gz: 28f453094a5cb5f7a8fc88909b4c8843450e2bec124877e26b62901100600a426bd196f0322ebf1d124d27c6d1469dab0d3e971388171f4fdf4abed1552b631f
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ require "erb"
3
+ require "simplecov"
4
+
5
+ class SimpleCov::Formatter::ERBFormatter
6
+ # This is the entry point.
7
+ def format(result)
8
+ File.open(output_filepath, "wb") { |file| file.puts template.result(binding) }
9
+ puts output_message(result)
10
+ end
11
+
12
+ # These come as class methods when configured via a spec_helper or similar.
13
+ def self.output_filename=(filename)
14
+ @output_filename = filename
15
+ end
16
+
17
+ def self.erb_file=(filename)
18
+ @erb_file = filename
19
+ end
20
+
21
+ # This may be called from within an ERB template to get the line numbers with
22
+ # missed coverage.
23
+ #
24
+ # source_file - A source file object from SimpleCov
25
+ #
26
+ # Returns an Array of line numbers whose test coverage is "missed".
27
+ def missed_lines(source_file)
28
+ result = []
29
+ source_file.lines.each_with_index do |line, index|
30
+ result << (index+1) if line.missed?
31
+ end
32
+ result
33
+ end
34
+
35
+ # This may be called from within an ERB template to get the file name relative
36
+ # to the SimpleCov root.
37
+ #
38
+ # filename - A String with the full path to the file.
39
+ #
40
+ # Returns a String with the filename relative to the SimpleCov root.
41
+ def shortened_filename(filename)
42
+ if filename.start_with?(SimpleCov.root)
43
+ filename[SimpleCov.root.length..-1]
44
+ else
45
+ filename
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def template
52
+ # Path, safe_mode, trim_mode
53
+ ERB.new(File.read(erb_file), nil, "-")
54
+ end
55
+
56
+ def output_message(result)
57
+ "Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
58
+ end
59
+
60
+ # erb_file is a class variable when set via the configuration, but an instance variable when
61
+ # retrieved. Define it both ways here, so the instance variable defers to the class.
62
+ def self.erb_file
63
+ @erb_file
64
+ end
65
+
66
+ def erb_file
67
+ self.class.erb_file || File.expand_path("../views/simplecov.erb", File.dirname(__FILE__))
68
+ end
69
+
70
+ # output_filename is a class variable when set via the configuration, but an instance variable when
71
+ # retrieved. Define it both ways here, so the instance variable defers to the class.
72
+ def self.output_filename
73
+ @output_filename
74
+ end
75
+
76
+ def output_filename
77
+ self.class.output_filename ? File.basename(self.class.output_filename) : "coverage.txt"
78
+ end
79
+
80
+ # Misc. helper methods.
81
+ def output_filepath
82
+ File.join(output_path, output_filename)
83
+ end
84
+
85
+ def output_path
86
+ SimpleCov.coverage_path
87
+ end
88
+ end
@@ -0,0 +1,13 @@
1
+ --------------------------------------------------------------------------------
2
+ Incomplete test coverage
3
+ --------------------------------------------------------------------------------
4
+
5
+ <%- if result.covered_percent.to_i >= 100 -%>
6
+ 100% test coverage. You're all set, friend!
7
+ <%- else -%>
8
+ <%- result.files.each do |source_file| -%>
9
+ <%- if source_file.covered_percent.to_i < 100 -%>
10
+ <%= shortened_filename(source_file.filename) %>: <%= source_file.covered_percent.round(2).to_s %>% (missed: <%= missed_lines(source_file).join(",") %>)
11
+ <%- end -%>
12
+ <%- end -%>
13
+ <%- end -%>
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-erb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Paulisse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Customizable text formatter for SimpleCov code coverage tool for ruby
28
+ 1.9+
29
+ email:
30
+ - kpaulisse@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/simplecov-erb.rb
36
+ - views/simplecov.erb
37
+ homepage: https://github.com/kpaulisse/simplecov-erb
38
+ licenses: []
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project: simplecov-erb
56
+ rubygems_version: 2.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Customizable text formatter for SimpleCov code coverage tool for ruby 1.9+
60
+ test_files: []