simplecov-lcov 0.6.0 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b37eaf4c08dce2a3b79b07aca977fcd7fd71ea2d
4
- data.tar.gz: 647af1efeba8bd64d285ce52592cff6842c48874
3
+ metadata.gz: cc8a6e79e2c447469190f8627959b7cc705e7261
4
+ data.tar.gz: 7b2d488756eaf1f269b16f91301ad93e343c08a3
5
5
  SHA512:
6
- metadata.gz: 00fd5066d8c2ea23950ba2d74ded0c8126dbe7fdd045b3f806712a67cd46b2aaa096e6d25900d74b9d5dc6415f68ba65d17ef49d8b2c0ad5764fc9c6e0e1a4a5
7
- data.tar.gz: a55252a2373073f150a5d9dd0be54f2b4a80a9eec06162e8ef69b298c52435012dd6fd014a61fb5dae6f4f2dd99d5a64754df38387bf202adde33e3f743f7ef2
6
+ metadata.gz: 2752794178b5b410f587f5db080fff262dd0fb5d85233518e4bf0f58d9baaaefd1f814f356b7ea8d8db9f00810572b1311c55a32310e463f0d5887372c89a148
7
+ data.tar.gz: 0e41a7b80310684bf577d31e2c6ea0685001c5b62de7d60e175c62305b1e533183d4725e7478624316c43dea06af56baf772de988b309fdc0b4680791a9c6639
data/README.markdown CHANGED
@@ -27,11 +27,21 @@ Custom SimpleCov formatter to generate a lcov style coverage.
27
27
  ```Ruby
28
28
  require 'simplecov'
29
29
  require 'simplecov-lcov'
30
- SimpleCov::Formatter::LcovFormatter.report_with_single_file = true
30
+ SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
31
31
  SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
32
32
  SimpleCov.start
33
33
  ```
34
34
 
35
+ Other available configuration options for single file report:
36
+
37
+ ```Ruby
38
+ SimpleCov::Formatter::LcovFormatter.config do |c|
39
+ c.output_directory = 'your/path' # default: "coverage/lcov"
40
+ c.lcov_file_name = 'lcov.info' # default: "YOUR_PROJECT_NAME.lcov"
41
+ c.single_report_path = 'your/path/lcov.info'
42
+ end
43
+ ```
44
+
35
45
  ## Contributing to simplecov-lcov
36
46
 
37
47
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
@@ -0,0 +1,28 @@
1
+ module SimpleCovLcov
2
+ class Configuration
3
+ attr_writer :report_with_single_file
4
+ attr_writer :output_directory
5
+ attr_writer :lcov_file_name
6
+
7
+ def report_with_single_file?
8
+ !!@report_with_single_file
9
+ end
10
+
11
+ def output_directory
12
+ @output_directory || File.join(SimpleCov.coverage_path, 'lcov')
13
+ end
14
+
15
+ def single_report_path=(new_path)
16
+ self.output_directory = File.dirname(new_path)
17
+ @single_report_path = new_path
18
+ end
19
+
20
+ def single_report_path
21
+ @single_report_path || File.join(output_directory, lcov_file_name)
22
+ end
23
+
24
+ def lcov_file_name
25
+ @lcov_file_name || "#{Pathname.new(SimpleCov.root).basename}.lcov"
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'pathname'
3
+ require_relative 'simple_cov_lcov/configuration'
3
4
 
4
5
  fail 'simplecov-lcov requires simplecov' unless defined?(SimpleCov)
5
6
 
@@ -12,53 +13,65 @@ module SimpleCov
12
13
  # _result_ :: [SimpleCov::Result] abcoverage result instance.
13
14
  def format(result)
14
15
  create_output_directory!
15
- if self.class.report_with_single_file?
16
+
17
+ if report_with_single_file?
16
18
  write_lcov_to_single_file!(result.files)
17
19
  else
18
20
  result.files.each { |file| write_lcov!(file) }
19
21
  end
20
22
 
21
- puts "Lcov style coverage report generated for #{result.command_name} to #{SimpleCov::Formatter::LcovFormatter.output_directory}."
23
+ puts "Lcov style coverage report generated for #{result.command_name} to #{lcov_results_path}"
22
24
  end
23
25
 
24
26
  class << self
25
- attr_writer :report_with_single_file
26
-
27
- def report_with_single_file?
28
- !!@report_with_single_file
27
+ def config
28
+ @config ||= SimpleCovLcov::Configuration.new
29
+ yield @config if block_given?
30
+ @config
29
31
  end
30
32
 
31
- # Output directory for generated files.
32
- # ==== Return
33
- # Path for output directory.
34
- def output_directory
35
- File.join(SimpleCov.coverage_path, 'lcov')
36
- end
33
+ def report_with_single_file=(value)
34
+ deprecation_message = \
35
+ "#{caller(1..1).first} " \
36
+ "`#{LcovFormatter}.report_with_single_file=` is deprecated. " \
37
+ "Use `#{LcovFormatter}.config.report_with_single_file=` instead"
37
38
 
38
- # Output path for single file report.
39
- # ==== Return
40
- # Path for output path of single file report.
41
- def single_report_path
42
- basename = Pathname.new(SimpleCov.root).basename.to_s
43
- File.join(output_directory, "#{basename}.lcov")
39
+ warn deprecation_message
40
+ config.report_with_single_file = value
44
41
  end
45
42
  end
46
43
 
47
44
  private
48
45
 
46
+ def output_directory
47
+ self.class.config.output_directory
48
+ end
49
+
50
+ def lcov_results_path
51
+ report_with_single_file? ? single_report_path : output_directory
52
+ end
53
+
54
+ def report_with_single_file?
55
+ self.class.config.report_with_single_file?
56
+ end
57
+
58
+ def single_report_path
59
+ self.class.config.single_report_path
60
+ end
61
+
49
62
  def create_output_directory!
50
- return if Dir.exist?(self.class.output_directory)
51
- FileUtils.mkdir_p(self.class.output_directory)
63
+ return if Dir.exist?(output_directory)
64
+ FileUtils.mkdir_p(output_directory)
52
65
  end
53
66
 
54
67
  def write_lcov!(file)
55
- File.open(File.join(self.class.output_directory, output_filename(file.filename)), 'w') do |f|
68
+ File.open(File.join(output_directory, output_filename(file.filename)), 'w') do |f|
56
69
  f.write format_file(file)
57
70
  end
58
71
  end
59
72
 
60
73
  def write_lcov_to_single_file!(files)
61
- File.open(self.class.single_report_path, 'w') do |f|
74
+ File.open(single_report_path, 'w') do |f|
62
75
  files.each { |file| f.write format_file(file) }
63
76
  end
64
77
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: simplecov-lcov 0.6.0 ruby lib
5
+ # stub: simplecov-lcov 0.7.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "simplecov-lcov".freeze
9
- s.version = "0.6.0"
9
+ s.version = "0.7.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["fortissimo1997".freeze]
14
- s.date = "2018-02-07"
14
+ s.date = "2018-02-10"
15
15
  s.description = "Custom SimpleCov formatter to generate a lcov style coverage.".freeze
16
16
  s.email = "fortissimo1997@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -29,8 +29,10 @@ Gem::Specification.new do |s|
29
29
  "README.markdown",
30
30
  "Rakefile",
31
31
  "VERSION",
32
+ "lib/simple_cov_lcov/configuration.rb",
32
33
  "lib/simplecov-lcov.rb",
33
34
  "simplecov-lcov.gemspec",
35
+ "spec/configuration_spec.rb",
34
36
  "spec/fixtures/app/models/user.rb",
35
37
  "spec/fixtures/hoge.rb",
36
38
  "spec/fixtures/lcov/spec-fixtures-app-models-user.rb.lcov",
@@ -0,0 +1,99 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe SimpleCovLcov::Configuration do
4
+ subject(:configuration) { described_class.new }
5
+
6
+ describe '#output_directory' do
7
+ context 'when directory is not customized' do
8
+ it 'returns default directory path' do
9
+ expect(configuration.output_directory).to eq File.join(SimpleCov.coverage_path, 'lcov')
10
+ end
11
+ end
12
+
13
+ context 'when directory is customized' do
14
+ let(:custom_directory_path) { 'some/custom/path' }
15
+
16
+ before do
17
+ configuration.output_directory = custom_directory_path
18
+ end
19
+
20
+ it 'returns customized directory path' do
21
+ expect(configuration.output_directory).to eq custom_directory_path
22
+ end
23
+ end
24
+
25
+ context 'when single_report_path is customized' do
26
+ before do
27
+ configuration.single_report_path = 'some/custom/path/lcov.info'
28
+ end
29
+
30
+ it 'sets correct path' do
31
+ expect(configuration.output_directory).to eq 'some/custom/path'
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#report_with_single_file?' do
37
+ context 'when no customisations are made' do
38
+ it { is_expected.not_to be_report_with_single_file }
39
+ end
40
+
41
+ context 'when report_with_single_file set to true' do
42
+ before do
43
+ configuration.report_with_single_file = true
44
+ end
45
+
46
+ it { is_expected.to be_report_with_single_file }
47
+ end
48
+ end
49
+
50
+ describe '#single_report_path' do
51
+ let(:default_single_report_dir) { File.join(SimpleCov.coverage_path, 'lcov') }
52
+ let(:default_file_name) { 'simplecov-lcov.lcov' }
53
+
54
+ context 'when no path customisations where made' do
55
+ it 'returns default path' do
56
+ default_path = File.join(default_single_report_dir, default_file_name)
57
+ expect(configuration.single_report_path).to eq default_path
58
+ end
59
+ end
60
+
61
+ context 'when file name is customised' do
62
+ let(:custom_file_name) { 'my-custom-file.info' }
63
+
64
+ before do
65
+ configuration.lcov_file_name = custom_file_name
66
+ end
67
+
68
+ it 'returns path with custom file name' do
69
+ path_with_custom_file_name = File.join(default_single_report_dir, custom_file_name)
70
+ expect(configuration.single_report_path).to eq path_with_custom_file_name
71
+ end
72
+ end
73
+
74
+ context 'when output directory is customised' do
75
+ let(:custom_file_directory) { 'path/to/my/custom/dir' }
76
+
77
+ before do
78
+ configuration.output_directory = custom_file_directory
79
+ end
80
+
81
+ it 'returns path with custom file name' do
82
+ customized_path = File.join(custom_file_directory, default_file_name)
83
+ expect(configuration.single_report_path).to eq customized_path
84
+ end
85
+ end
86
+
87
+ context 'when single_report_path is customised' do
88
+ let(:custom_path) { 'my/path/with/file.lcov' }
89
+
90
+ before do
91
+ configuration.single_report_path = custom_path
92
+ end
93
+
94
+ it 'returns customised path' do
95
+ expect(configuration.single_report_path).to eq custom_path
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,84 +1,98 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'active_support/core_ext/kernel/reporting'
3
3
 
4
- describe SimpleCov::Formatter::LcovFormatter do
5
- describe '#format' do
6
- let(:expand_path) {
7
- lambda do |filename|
8
- File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
9
- end
10
- }
11
-
12
- let(:simplecov_result_hash) {
13
- {
14
- expand_path.call('hoge.rb') => [nil, nil, nil, 1, 2, 2, 1, nil, 0, 0, 0, 1],
15
- expand_path.call('app/models/user.rb') => [nil, nil, nil, 2, 2, 2, 2, nil, 0, 0, 0, nil, 1, 0, 0, 1]
4
+ module SimpleCov::Formatter
5
+ describe LcovFormatter do
6
+ describe '#format' do
7
+ let(:expand_path) {
8
+ lambda do |filename|
9
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
10
+ end
16
11
  }
17
- }
18
-
19
- let(:simplecov_result) {
20
- SimpleCov::Result.new(simplecov_result_hash)
21
- }
22
12
 
23
- context 'generating report per file' do
24
- before {
25
- SimpleCov::Formatter::LcovFormatter.new.format(simplecov_result)
13
+ let(:simplecov_result_hash) {
14
+ {
15
+ expand_path.call('hoge.rb') => [nil, nil, nil, 1, 2, 2, 1, nil, 0, 0, 0, 1],
16
+ expand_path.call('app/models/user.rb') => [nil, nil, nil, 2, 2, 2, 2, nil, 0, 0, 0, nil, 1, 0, 0, 1]
17
+ }
26
18
  }
27
19
 
28
- describe File do
29
- it { expect(File).to exist(File.join(SimpleCov::Formatter::LcovFormatter.output_directory, 'spec-fixtures-hoge.rb.lcov')) }
30
- it { expect(File).to exist(File.join(SimpleCov::Formatter::LcovFormatter.output_directory, 'spec-fixtures-app-models-user.rb.lcov')) }
31
- end
20
+ let(:simplecov_result) {
21
+ SimpleCov::Result.new(simplecov_result_hash)
22
+ }
32
23
 
33
- describe 'spec-fixtures-hoge.rb.lcov' do
34
- let(:output_path) {
35
- File.join(SimpleCov::Formatter::LcovFormatter.output_directory, 'spec-fixtures-hoge.rb.lcov')
24
+ context 'generating report per file' do
25
+ before {
26
+ LcovFormatter.new.format(simplecov_result)
36
27
  }
37
- let(:fixture) {
38
- File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-hoge.rb.lcov")
39
- }
40
- it { expect(File.read(output_path)).to eq(fixture) }
41
- end
42
28
 
43
- describe 'spec-fixtures-app-models-user.rb.lcov' do
44
- let(:output_path) {
45
- File.join(SimpleCov::Formatter::LcovFormatter.output_directory, 'spec-fixtures-app-models-user.rb.lcov')
46
- }
47
- let(:fixture) {
48
- File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-app-models-user.rb.lcov")
49
- }
50
- it { expect(File.read(output_path)).to eq(fixture) }
51
- end
52
- end
29
+ describe File do
30
+ it { expect(File).to exist(File.join(LcovFormatter.config.output_directory, 'spec-fixtures-hoge.rb.lcov')) }
31
+ it { expect(File).to exist(File.join(LcovFormatter.config.output_directory, 'spec-fixtures-app-models-user.rb.lcov')) }
32
+ end
53
33
 
54
- context 'generating single file report' do
55
- before {
56
- SimpleCov::Formatter::LcovFormatter.report_with_single_file = true
57
- SimpleCov::Formatter::LcovFormatter.new.format(simplecov_result)
58
- }
34
+ describe 'spec-fixtures-hoge.rb.lcov' do
35
+ let(:output_path) {
36
+ File.join(LcovFormatter.config.output_directory, 'spec-fixtures-hoge.rb.lcov')
37
+ }
38
+ let(:fixture) {
39
+ File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-hoge.rb.lcov")
40
+ }
41
+ it { expect(File.read(output_path)).to eq(fixture) }
42
+ end
59
43
 
60
- describe File do
61
- it { expect(File).to exist(SimpleCov::Formatter::LcovFormatter.single_report_path) }
44
+ describe 'spec-fixtures-app-models-user.rb.lcov' do
45
+ let(:output_path) {
46
+ File.join(LcovFormatter.config.output_directory, 'spec-fixtures-app-models-user.rb.lcov')
47
+ }
48
+ let(:fixture) {
49
+ File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-app-models-user.rb.lcov")
50
+ }
51
+ it { expect(File.read(output_path)).to eq(fixture) }
52
+ end
62
53
  end
63
54
 
64
- describe 'single_report_path' do
65
- let(:output_path) {
66
- SimpleCov::Formatter::LcovFormatter.single_report_path
67
- }
68
- let(:fixture_of_hoge) {
69
- File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-hoge.rb.lcov")
55
+ context 'generating single file report' do
56
+ before {
57
+ LcovFormatter.config.report_with_single_file = true
58
+ LcovFormatter.new.format(simplecov_result)
70
59
  }
71
- let(:fixture_of_user) {
72
- File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-app-models-user.rb.lcov")
73
- }
74
- it { expect(File.read(output_path)).to match(fixture_of_hoge) }
75
- it { expect(File.read(output_path)).to match(fixture_of_user) }
60
+
61
+ describe File do
62
+ it { expect(File).to exist(LcovFormatter.config.single_report_path) }
63
+ end
64
+
65
+ describe 'single_report_path' do
66
+ let(:output_path) {
67
+ LcovFormatter.config.single_report_path
68
+ }
69
+ let(:fixture_of_hoge) {
70
+ File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-hoge.rb.lcov")
71
+ }
72
+ let(:fixture_of_user) {
73
+ File.read("#{File.dirname(__FILE__)}/fixtures/lcov/spec-fixtures-app-models-user.rb.lcov")
74
+ }
75
+ it { expect(File.read(output_path)).to match(fixture_of_hoge) }
76
+ it { expect(File.read(output_path)).to match(fixture_of_user) }
77
+ end
76
78
  end
77
79
  end
78
80
  end
79
81
 
80
- describe '.output_directory' do
81
- subject { SimpleCov::Formatter::LcovFormatter.output_directory }
82
- it { expect(subject).to eq(File.join(SimpleCov.coverage_path, 'lcov')) }
82
+ describe '.report_with_single_file=' do
83
+ before do
84
+ allow(LcovFormatter).to receive(:warn)
85
+ allow(LcovFormatter.config).to receive(:report_with_single_file=)
86
+ end
87
+
88
+ it 'sets configuration options correctly' do
89
+ LcovFormatter.report_with_single_file = true
90
+ expect(LcovFormatter.config).to have_received(:report_with_single_file=).with(true)
91
+ end
92
+
93
+ it 'shows deprecation warning' do
94
+ LcovFormatter.report_with_single_file = true
95
+ expect(LcovFormatter).to have_received(:warn).with(/LcovFormatter\.report_with_single_file=` is deprecated/)
96
+ end
83
97
  end
84
98
  end
data/spec/spec_helper.rb CHANGED
@@ -12,10 +12,10 @@ SimpleCov.configure do
12
12
  clean_filters
13
13
  end
14
14
 
15
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
15
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
16
16
  SimpleCov::Formatter::HTMLFormatter,
17
17
  Coveralls::SimpleCov::Formatter
18
- ]
18
+ ])
19
19
 
20
20
  ENV['COVERAGE'] && SimpleCov.start do
21
21
  add_filter '/.rvm/'
@@ -33,10 +33,10 @@ require 'simplecov-lcov'
33
33
 
34
34
  RSpec.configure do |config|
35
35
  config.before(:each) do
36
- if Dir.exist?(SimpleCov::Formatter::LcovFormatter.output_directory)
36
+ if Dir.exist?(SimpleCov::Formatter::LcovFormatter.config.output_directory)
37
37
  FileUtils
38
38
  .remove_dir(
39
- SimpleCov::Formatter::LcovFormatter.output_directory,
39
+ SimpleCov::Formatter::LcovFormatter.config.output_directory,
40
40
  true
41
41
  )
42
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-lcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fortissimo1997
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2018-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -126,8 +126,10 @@ files:
126
126
  - README.markdown
127
127
  - Rakefile
128
128
  - VERSION
129
+ - lib/simple_cov_lcov/configuration.rb
129
130
  - lib/simplecov-lcov.rb
130
131
  - simplecov-lcov.gemspec
132
+ - spec/configuration_spec.rb
131
133
  - spec/fixtures/app/models/user.rb
132
134
  - spec/fixtures/hoge.rb
133
135
  - spec/fixtures/lcov/spec-fixtures-app-models-user.rb.lcov