simplecov-console 0.5.0 → 0.8.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
  SHA256:
3
- metadata.gz: 290f9f7dda635d7301e3c4f2acd9bb81a17fda27aee5a812983ba19bfea11ebe
4
- data.tar.gz: 2e317c4c10cf7dff407e2544c2916136c7d436f35a89fc10a509649a8706d32c
3
+ metadata.gz: c972c40225a8d1890e1a1b9d9e6cda1d55c9b7ec6e07e504dbd01e24ff834a10
4
+ data.tar.gz: b3ae36a6ee1500cceb6a7ee53f3d3d56246c143836ef8cc76169f8e51dd5a87a
5
5
  SHA512:
6
- metadata.gz: 2de0c0d1e3b265df0d214368841200362feee6817497562d0ad04246b2c2ab81346e714242bd767bf8ffbe7fdca8d321061559a5a05a47a09fe2c79f14df91bd
7
- data.tar.gz: 0d6bd990215178e64db73696dfa06454ba46d0f72771e380114d9c881e7945fc0e7c33dcc010b8c5b1b598eb4f4a2ad3cb39aff921c298446bc375306a66102f
6
+ metadata.gz: 0eefb3cffa6fe189951d47c978ae6a728fb5919a0f9eaaef62bedea886721379c470d81f9c0c57f4e5b87a0b6b14f31693a74e98c3a2fd016ea8364bed76b8b6
7
+ data.tar.gz: 7415cb6326ec3cbd80de5b34a068acffc1220f4e2c9def4b6e230adc660cf1ad8486e2febe92e1e5e0ea7eea6467622fdd26eba2a2f2e4d1a9d3361ba3674fde
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## 0.8 (2020.11.11)
4
+
5
+ - Added support for branch coverage - thanks [@robotdana!](https://github.com/robotdana) ([#19](https://github.com/chetan/simplecov-console/pull/19))
6
+
7
+ ## 0.7.2 (2020.03.05)
8
+
9
+ - Fix: table output include ([#17](https://github.com/chetan/simplecov-console/issues/17))
10
+
11
+ ## 0.7.1 (2020.03.05)
12
+
13
+ - Fix: block output doesn't work with frozen string literal ([#16](https://github.com/chetan/simplecov-console/issues/16))
14
+
15
+ ## 0.7 (2020.03.04)
16
+
17
+ - Added new 'block' style output option - thanks [@hpainter](https://github.com/hpainter)! ([#15](https://github.com/chetan/simplecov-console/issues/15))
18
+
19
+ ## 0.6 (2019.11.08)
20
+
21
+ - Added new config options: `sort`, `show_covered`, and `max_rows`
22
+
23
+ ## 0.5 (2019.05.24)
24
+
25
+ - Replaced `hirb` gem with `terminal-table` due to multiple warnings thrown ([#11](https://github.com/chetan/simplecov-console/issues/11))
26
+ - Support [disabling colorized](https://no-color.org/) output via `NO_COLOR` env var
data/Gemfile CHANGED
@@ -7,6 +7,6 @@ gem "ansi"
7
7
  group :development do
8
8
  gem "minitest"
9
9
  gem "yard"
10
- gem "bundler", "~> 1.2"
10
+ gem "bundler", "~> 2.1"
11
11
  gem "juwelier"
12
12
  end
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A simple console output formatter for SimpleCov
4
4
 
5
- ### Usage
5
+ ## Usage
6
6
 
7
7
  ```bash
8
8
  $ gem install simplecov-console
@@ -11,14 +11,15 @@ $ gem install simplecov-console
11
11
  ```ruby
12
12
  SimpleCov.formatter = SimpleCov::Formatter::Console
13
13
  # or
14
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
15
15
  SimpleCov::Formatter::HTMLFormatter,
16
16
  SimpleCov::Formatter::Console,
17
- ]
17
+ ])
18
18
  ```
19
19
 
20
20
  Example output:
21
- ```
21
+
22
+ ```text
22
23
  COVERAGE: 82.34% -- 2345/2848 lines in 111 files
23
24
 
24
25
  showing bottom (worst) 15 of 69 files
@@ -44,17 +45,135 @@ showing bottom (worst) 15 of 69 files
44
45
  42 file(s) with 100% coverage not shown
45
46
  ```
46
47
 
48
+ ## Configuration
49
+
50
+ ### Disabling colorized output
51
+
52
+ Simply export `NO_COLOR=1` and colors will be disabled.
53
+
54
+ ```sh
55
+ NO_COLOR=1 rake test
56
+ ```
57
+
58
+ ### Sorting the output
59
+
60
+ By default the coverage report is sorted by coverage % in descending order. To sort alphabetically by path, set the `SORT` environment variable to "path", or add the following to your test helper:
61
+
62
+ ```ruby
63
+ SimpleCov::Formatter::Console.sort = 'path' # sort by file path
64
+ ```
65
+
66
+ ### Showing covered files
67
+
68
+ By default, fully covered files are excluded from the report. To show them, set the `SHOW_COVERED` environment variable to `true` or add the following to your test helper:
69
+
70
+ ```ruby
71
+ SimpleCov::Formatter::Console.show_covered = true # show all files in coverage report
72
+ ```
73
+
74
+ ### Maximum rows displayed
75
+
76
+ By default, a maximum of 15 files with the worst coverage are displayed in the report. You can override this limit by setting the `MAX_ROWS` environment variable, or adding the following to your test helper:
77
+
78
+ ```ruby
79
+ SimpleCov::Formatter::Console.max_rows = # some number
80
+ ```
81
+
82
+ Setting a value of `-1` or `nil` will show all of the files.
83
+
47
84
  ### Table options
48
85
 
49
- In some cases, you may need to pass some options to Hirb's Table.render. For example, if the filenames are
86
+ In some cases, you may need to pass some options to `TerminalTable.new`. For example, if the filenames are
50
87
  truncated so much that you can't read them. In that case, you can add a line like this when setting the formatter:
51
88
 
52
89
  ```ruby
53
- SimpleCov::Formatter::Console.table_options = {max_width: 200}
90
+ SimpleCov::Formatter::Console.table_options = {:style => {:width => 200}}
54
91
  SimpleCov.formatter = SimpleCov::Formatter::Console
55
92
  ```
56
93
 
57
- ### Contributing
94
+ ### Block output style
95
+
96
+ As an alternative to the default table output format, results can be printed as plain text blocks instead by setting
97
+ the formatter `output_style` to 'block':
98
+
99
+ ```ruby
100
+ SimpleCov::Formatter::Console.output_style = 'block'
101
+ SimpleCov.formatter = SimpleCov::Formatter::Console
102
+ ```
103
+
104
+ Example output:
105
+
106
+ ```text
107
+ COVERAGE: 82.34% -- 2345/2848 lines in 111 files
108
+
109
+ showing bottom (worst) 5 of 69 files
110
+
111
+ file: lib/bixby/api/websocket_server.rb
112
+ coverage: 22.73% (17/22 lines)
113
+ missed: 11, 14, 17-18, 20-22, 24, 28-30, 32, 36-...
114
+
115
+ file: app/models/role.rb
116
+ coverage: 30.77% (9/13 lines)
117
+ missed: 28-34, 36-37
118
+
119
+ file: lib/bixby/modules/metrics/rescan.rb
120
+ coverage: 32.14% (19/28 lines)
121
+ missed: 19-23, 27-31, 33-37, 39-41, 43
122
+
123
+ file: lib/archie/mail.rb
124
+ coverage: 42.86% (8/14 lines)
125
+ missed: 6-8, 12-15, 22
126
+
127
+ file: lib/archie/controller.rb
128
+ coverage: 44.00% (28/50 lines)
129
+ missed: 18-21, 23, 27-30, 32, 38-40, 44-45, 48-4...
130
+
131
+ 42 file(s) with 100% coverage not shown
132
+ ```
133
+
134
+ ### Branch Coverage Support
135
+
136
+ When branch coverage is [enabled in simplecov](https://github.com/simplecov-ruby/simplecov/tree/818bc2547842a90c607b4fec834320766a8686de#branch-coverage-ruby--25), branch info will automatically be displayed in the output:
137
+
138
+ ```text
139
+ COVERAGE: 78.26% -- 18/23 lines in 2 files
140
+ BRANCH COVERAGE: 83.33% -- 5/6 branches in 2 branches
141
+
142
+ +----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
143
+ | coverage | file | lines | missed | missing | branch coverage | branches | branches missed | branches missing |
144
+ +----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
145
+ | 72.22% | lib/simplecov-console-test.rb | 18 | 5 | 10-12, 16, 25 | 83.33% | 6 | 1 | 25[then] |
146
+ +----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
147
+ ```
148
+
149
+ ## History
150
+
151
+ ### 0.8 (2020.11.11)
152
+
153
+ - Added support for branch coverage - thanks [@robotdana!](https://github.com/robotdana) ([#19](https://github.com/chetan/simplecov-console/pull/19))
154
+
155
+ ### 0.7.2 (2020.03.05)
156
+
157
+ - Fix: table output include ([#17](https://github.com/chetan/simplecov-console/issues/17))
158
+
159
+ ### 0.7.1 (2020.03.05)
160
+
161
+ - Fix: block output doesn't work with frozen string literal ([#16](https://github.com/chetan/simplecov-console/issues/16))
162
+
163
+ ### 0.7 (2020.03.04)
164
+
165
+ - Added new 'block' style output option - thanks [@hpainter](https://github.com/hpainter)! ([#15](https://github.com/chetan/simplecov-console/issues/15))
166
+
167
+ ### 0.6 (2019.11.08)
168
+
169
+ - Added new config options: `sort`, `show_covered`, and `max_rows`
170
+
171
+ ### 0.5 (2019.05.24)
172
+
173
+ - Replaced `hirb` gem with `terminal-table` due to multiple warnings thrown ([#11](https://github.com/chetan/simplecov-console/issues/11))
174
+ - Support [disabling colorized](https://no-color.org/) output via `NO_COLOR` env var
175
+
176
+ ## Contributing
58
177
 
59
178
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
60
179
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -66,5 +185,5 @@ SimpleCov.formatter = SimpleCov::Formatter::Console
66
185
 
67
186
  ### Copyright
68
187
 
69
- Copyright (c) 2014 Chetan Sarva. See LICENSE.txt for
188
+ Copyright (c) 2020 Chetan Sarva. See LICENSE.txt for
70
189
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.8.0
@@ -1,11 +1,10 @@
1
- require 'terminal-table'
2
1
  require 'ansi/code'
3
2
 
4
3
  class SimpleCov::Formatter::Console
5
4
 
6
5
  VERSION = IO.read(File.expand_path("../../VERSION", __FILE__)).strip
7
6
 
8
- ATTRIBUTES = [:table_options, :use_colors]
7
+ ATTRIBUTES = [:table_options, :use_colors, :max_rows, :show_covered, :sort, :output_style]
9
8
  class << self
10
9
  attr_accessor(*ATTRIBUTES)
11
10
  end
@@ -14,7 +13,36 @@ class SimpleCov::Formatter::Console
14
13
  SimpleCov::Formatter::Console.use_colors =
15
14
  (ENV['NO_COLOR'].nil? or ENV['NO_COLOR'].empty?) ? true : false
16
15
 
16
+ # configure max rows from MAX_ROWS env var
17
+ SimpleCov::Formatter::Console.max_rows = ENV.fetch('MAX_ROWS', 15).to_i
18
+
19
+ # configure show_covered from SHOW_COVERED env var
20
+ SimpleCov::Formatter::Console.show_covered = ENV.fetch('SHOW_COVERED', 'false') == 'true'
21
+
22
+ # configure sort from SORT env var
23
+ SimpleCov::Formatter::Console.sort = ENV.fetch('SORT', 'coverage')
24
+
25
+ # configure output format ('table', 'block')
26
+ SimpleCov::Formatter::Console.output_style = ENV.fetch('OUTPUT_STYLE', 'table')
27
+
28
+ def include_output_style
29
+ if SimpleCov::Formatter::Console.output_style == 'block' then
30
+ require 'simplecov-console/output/block'
31
+ extend BlockOutput
32
+ else
33
+ # default to table
34
+ require 'simplecov-console/output/table'
35
+ extend TableOutput
36
+ end
37
+ end
38
+
39
+ def show_branch_coverage?(result)
40
+ Gem::Version.new(SimpleCov::VERSION) >= Gem::Version.new('0.18.5') &&
41
+ result.coverage_statistics[:branch]
42
+ end
43
+
17
44
  def format(result)
45
+ include_output_style
18
46
 
19
47
  root = nil
20
48
  if Module.const_defined? :ROOT then
@@ -28,53 +56,54 @@ class SimpleCov::Formatter::Console
28
56
  end
29
57
 
30
58
  puts
31
- puts "COVERAGE: #{colorize(pct(result))} -- #{result.covered_lines}/#{result.total_lines} lines in #{result.files.size} files"
59
+ puts "COVERAGE: #{colorize(pct(result.covered_percent))} -- #{result.covered_lines}/#{result.total_lines} lines in #{result.files.size} files"
60
+ show_branch_coverage = show_branch_coverage?(result)
61
+ if show_branch_coverage
62
+ puts "BRANCH COVERAGE: #{colorize(pct(result.coverage_statistics[:branch].percent))} -- #{result.covered_branches}/#{result.total_branches} branches in #{result.files.size} branches"
63
+ end
32
64
  puts
33
65
 
34
66
  if root.nil? then
35
67
  return
36
68
  end
37
69
 
38
- files = result.files.sort{ |a,b| a.covered_percent <=> b.covered_percent }
39
-
40
- covered_files = 0
41
- files.select!{ |file|
42
- if file.covered_percent == 100 then
43
- covered_files += 1
44
- false
70
+ if SimpleCov::Formatter::Console.sort == 'coverage'
71
+ if show_branch_coverage
72
+ files = result.files.sort do |a,b|
73
+ (a.covered_percent <=> b.covered_percent).nonzero? ||
74
+ (a.coverage_statistics[:branch].percent <=> b.coverage_statistics[:branch].percent)
75
+ end
45
76
  else
46
- true
77
+ files = result.files.sort_by(&:covered_percent)
47
78
  end
48
- }
49
-
50
- if files.nil? or files.empty? then
51
- return
79
+ else
80
+ files = result.files
52
81
  end
53
82
 
54
- table = files.map do |f|
55
- [
56
- colorize(pct(f)),
57
- f.filename.gsub(root + "/", ''),
58
- f.lines_of_code,
59
- f.missed_lines.count,
60
- missed(f.missed_lines).join(", ")
61
- ]
62
- end
83
+ covered_files = 0
63
84
 
64
- if table.size > 15 then
65
- puts "showing bottom (worst) 15 of #{table.size} files"
66
- table = table.slice(0, 15)
85
+ unless SimpleCov::Formatter::Console.show_covered
86
+ files.select!{ |file|
87
+ if file.covered_percent == 100 && (!show_branch_coverage || file.coverage_statistics[:branch].percent == 100) then
88
+ covered_files += 1
89
+ false
90
+ else
91
+ true
92
+ end
93
+ }
94
+ if files.nil? or files.empty? then
95
+ return
96
+ end
67
97
  end
68
98
 
69
- table_options = SimpleCov::Formatter::Console.table_options || {}
70
- if !table_options.kind_of?(Hash) then
71
- raise ArgumentError.new("SimpleCov::Formatter::Console.table_options must be a Hash")
99
+ max_rows = SimpleCov::Formatter::Console.max_rows
100
+
101
+ if ![-1, nil].include?(max_rows) && files.size > max_rows then
102
+ puts "showing bottom (worst) #{max_rows} of #{files.size} files"
103
+ files = files.slice(0, max_rows)
72
104
  end
73
- headings = %w{ coverage file lines missed missing }
74
105
 
75
- opts = table_options.merge({:headings => headings, :rows => table})
76
- t = Terminal::Table.new(opts)
77
- puts t
106
+ puts output(files, root, show_branch_coverage)
78
107
 
79
108
  if covered_files > 0 then
80
109
  puts "#{covered_files} file(s) with 100% coverage not shown"
@@ -82,6 +111,12 @@ class SimpleCov::Formatter::Console
82
111
 
83
112
  end
84
113
 
114
+ def branches_missed(missed_branches)
115
+ missed_branches.group_by(&:start_line).map do |line_number, branches|
116
+ "#{line_number}[#{branches.map(&:type).join(',')}]"
117
+ end
118
+ end
119
+
85
120
  def missed(missed_lines)
86
121
  groups = {}
87
122
  base = nil
@@ -110,8 +145,8 @@ class SimpleCov::Formatter::Console
110
145
  group_str
111
146
  end
112
147
 
113
- def pct(obj)
114
- sprintf("%6.2f%%", obj.covered_percent)
148
+ def pct(number)
149
+ sprintf("%6.2f%%", number)
115
150
  end
116
151
 
117
152
  def use_colors?
@@ -131,5 +166,4 @@ class SimpleCov::Formatter::Console
131
166
  ANSI.red { s }
132
167
  end
133
168
  end
134
-
135
169
  end
@@ -0,0 +1,28 @@
1
+
2
+ class SimpleCov::Formatter::Console
3
+ module BlockOutput
4
+
5
+ # format per-file results output as plain text blocks
6
+ def output(files, root, show_branch)
7
+ blocks = []
8
+ files.each do |f|
9
+ block = []
10
+ block << sprintf("%8.8s: %s", 'file', f.filename.gsub(root + "/", ''))
11
+ block << sprintf("%8.8s: %s (%d/%d lines)", 'coverage',
12
+ colorize(sprintf("%.2f%%", f.covered_percent)),
13
+ f.covered_lines.count, f.lines_of_code)
14
+ block << sprintf("%8.8s: %s", 'missed', missed(f.missed_lines).join(", "))
15
+ if show_branch
16
+ block << sprintf("%8.8s: %s (%d/%d branches)", 'branches',
17
+ colorize(sprintf("%.2f%%", f.coverage_statistics[:branch].percent)),
18
+ (f.total_branches.count - f.missed_branches.count), f.total_branches.count)
19
+ block << sprintf("%8.8s: %s", 'missed', branches_missed(f.missed_branches).join(", "))
20
+ end
21
+ blocks << block.join("\n")
22
+ end
23
+
24
+ "\n" + blocks.join("\n\n") + "\n\n"
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ require 'terminal-table'
2
+
3
+ class SimpleCov::Formatter::Console
4
+ module TableOutput
5
+
6
+ # format per-file results output using Terminal::Table
7
+ def output(files, root,show_branch)
8
+ table = files.map do |f|
9
+ row = [
10
+ colorize(pct(f.covered_percent)),
11
+ f.filename.gsub(root + "/", ''),
12
+ f.lines_of_code,
13
+ f.missed_lines.count,
14
+ missed(f.missed_lines).join(", "),
15
+ ]
16
+ if show_branch
17
+ row += [
18
+ colorize(pct(f.coverage_statistics[:branch].percent)),
19
+ f.total_branches.count,
20
+ f.missed_branches.count,
21
+ branches_missed(f.missed_branches).join(", ")
22
+ ]
23
+ end
24
+
25
+ row
26
+ end
27
+
28
+ table_options = SimpleCov::Formatter::Console.table_options || {}
29
+ if !table_options.kind_of?(Hash) then
30
+ raise ArgumentError.new("SimpleCov::Formatter::Console.table_options must be a Hash")
31
+ end
32
+
33
+ headings = %w{ coverage file lines missed missing }
34
+ if show_branch
35
+ headings += [
36
+ 'branch coverage',
37
+ 'branches',
38
+ 'branches missed',
39
+ 'branches missing'
40
+ ]
41
+ end
42
+
43
+ opts = table_options.merge({:headings => headings, :rows => table})
44
+ Terminal::Table.new(opts)
45
+ end
46
+
47
+ end
48
+ end
@@ -2,66 +2,62 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: simplecov-console 0.5.0 ruby lib
5
+ # stub: simplecov-console 0.8.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "simplecov-console".freeze
9
- s.version = "0.5.0"
9
+ s.version = "0.8.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 = ["Chetan Sarva".freeze]
14
- s.date = "2019-05-24"
14
+ s.date = "2020-11-11"
15
15
  s.description = "Simple console output formatter for SimpleCov".freeze
16
16
  s.email = "chetan@pixelcop.net".freeze
17
17
  s.extra_rdoc_files = [
18
+ "CHANGELOG.md",
18
19
  "LICENSE.txt",
19
20
  "README.md"
20
21
  ]
21
22
  s.files = [
22
23
  ".document",
24
+ "CHANGELOG.md",
23
25
  "Gemfile",
24
26
  "LICENSE.txt",
25
27
  "README.md",
26
28
  "Rakefile",
27
29
  "VERSION",
28
30
  "lib/simplecov-console.rb",
31
+ "lib/simplecov-console/output/block.rb",
32
+ "lib/simplecov-console/output/table.rb",
29
33
  "simplecov-console.gemspec",
30
34
  "test/helper.rb",
31
35
  "test/test_simplecov-console.rb"
32
36
  ]
33
37
  s.homepage = "http://github.com/chetan/simplecov-console".freeze
34
38
  s.licenses = ["MIT".freeze]
35
- s.rubygems_version = "3.0.2".freeze
39
+ s.rubygems_version = "3.1.4".freeze
36
40
  s.summary = "Simple console output formatter".freeze
37
41
 
38
42
  if s.respond_to? :specification_version then
39
43
  s.specification_version = 4
44
+ end
40
45
 
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<simplecov>.freeze, [">= 0"])
43
- s.add_runtime_dependency(%q<terminal-table>.freeze, [">= 0"])
44
- s.add_runtime_dependency(%q<ansi>.freeze, [">= 0"])
45
- s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
46
- s.add_development_dependency(%q<yard>.freeze, [">= 0"])
47
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.2"])
48
- s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
49
- else
50
- s.add_dependency(%q<simplecov>.freeze, [">= 0"])
51
- s.add_dependency(%q<terminal-table>.freeze, [">= 0"])
52
- s.add_dependency(%q<ansi>.freeze, [">= 0"])
53
- s.add_dependency(%q<minitest>.freeze, [">= 0"])
54
- s.add_dependency(%q<yard>.freeze, [">= 0"])
55
- s.add_dependency(%q<bundler>.freeze, ["~> 1.2"])
56
- s.add_dependency(%q<juwelier>.freeze, [">= 0"])
57
- end
46
+ if s.respond_to? :add_runtime_dependency then
47
+ s.add_runtime_dependency(%q<simplecov>.freeze, [">= 0"])
48
+ s.add_runtime_dependency(%q<terminal-table>.freeze, [">= 0"])
49
+ s.add_runtime_dependency(%q<ansi>.freeze, [">= 0"])
50
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
51
+ s.add_development_dependency(%q<yard>.freeze, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 2.1"])
53
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
58
54
  else
59
55
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
60
56
  s.add_dependency(%q<terminal-table>.freeze, [">= 0"])
61
57
  s.add_dependency(%q<ansi>.freeze, [">= 0"])
62
58
  s.add_dependency(%q<minitest>.freeze, [">= 0"])
63
59
  s.add_dependency(%q<yard>.freeze, [">= 0"])
64
- s.add_dependency(%q<bundler>.freeze, ["~> 1.2"])
60
+ s.add_dependency(%q<bundler>.freeze, ["~> 2.1"])
65
61
  s.add_dependency(%q<juwelier>.freeze, [">= 0"])
66
62
  end
67
63
  end
@@ -2,21 +2,108 @@ require 'helper'
2
2
 
3
3
  class TestSimplecovConsole < MiniTest::Test
4
4
 
5
- Source = Struct.new(:line_number)
5
+ # mock for SimpleCov::SourceFile::Line
6
+ Line = Struct.new(:line_number)
7
+
8
+ # mock for SimpleCov::SourceFile
9
+ SourceFile = Struct.new(
10
+ :filename,
11
+ :lines_of_code,
12
+ :covered_lines,
13
+ :missed_lines,
14
+ :covered_percent
15
+ )
16
+
17
+ CoverageStatistics = Struct.new(
18
+ :percent
19
+ )
20
+
21
+ Branch = Struct.new(
22
+ :start_line,
23
+ :type
24
+ )
25
+
26
+ SourceFileWithBranches = Struct.new(
27
+ :filename,
28
+ :lines_of_code,
29
+ :covered_lines,
30
+ :missed_lines,
31
+ :covered_percent,
32
+ :coverage_statistics,
33
+ :total_branches,
34
+ :missed_branches
35
+ )
6
36
 
7
37
  def setup
8
38
  @console = SimpleCov::Formatter::Console.new
9
39
  end
10
40
 
41
+ def teardown
42
+ SimpleCov::Formatter::Console.output_style = 'table'
43
+ end
44
+
11
45
  def test_defined
12
46
  assert defined?(SimpleCov::Formatter::Console)
13
47
  assert defined?(SimpleCov::Formatter::Console::VERSION)
14
48
  end
15
49
 
16
50
  def test_missed
17
- missed_lines = [Source.new(1), Source.new(2),
18
- Source.new(3), Source.new(5)]
51
+ missed_lines = [Line.new(1), Line.new(2),
52
+ Line.new(3), Line.new(5)]
19
53
  expected_result = ["1-3", "5"]
20
54
  assert_equal @console.missed(missed_lines), expected_result
21
55
  end
56
+
57
+ def test_table_output
58
+ SimpleCov::Formatter::Console.output_style = 'table'
59
+ @console.include_output_style
60
+ files = [
61
+ SourceFile.new('foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0)
62
+ ]
63
+ actual = @console.output(files,'/',false)
64
+ assert actual.is_a? Terminal::Table
65
+ assert_equal 1, actual.rows.count
66
+ end
67
+
68
+ def test_table_output_with_branches
69
+ SimpleCov::Formatter::Console.output_style = 'table'
70
+ @console.include_output_style
71
+ files = [
72
+ SourceFileWithBranches.new(
73
+ 'foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0,
74
+ {branch: CoverageStatistics.new(50.0)}, [1,2],
75
+ [Branch.new(2, :then)]
76
+ )
77
+ ]
78
+ actual = @console.output(files,'/',true)
79
+ assert actual.is_a? Terminal::Table
80
+ assert_equal 1, actual.rows.count
81
+ end
82
+
83
+ def test_block_output
84
+ SimpleCov::Formatter::Console.use_colors = false
85
+ SimpleCov::Formatter::Console.output_style = 'block'
86
+ @console.include_output_style
87
+
88
+ files = [
89
+ SourceFile.new('foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0)
90
+ ]
91
+ expected = "\n file: foo.rb\ncoverage: 40.00% (2/5 lines)\n missed: 1, 4-5\n\n"
92
+ assert_equal expected, @console.output(files,'/',false)
93
+ end
94
+
95
+ def test_block_output_with_branches
96
+ SimpleCov::Formatter::Console.use_colors = false
97
+ SimpleCov::Formatter::Console.output_style = 'block'
98
+ @console.include_output_style
99
+ files = [
100
+ SourceFileWithBranches.new(
101
+ 'foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0,
102
+ {branch: CoverageStatistics.new(50.0)}, [1,2],
103
+ [Branch.new(2, :then)]
104
+ )
105
+ ]
106
+ expected = "\n file: foo.rb\ncoverage: 40.00% (2/5 lines)\n missed: 1, 4-5\nbranches: 50.00% (1/2 branches)\n missed: 2[then]\n\n"
107
+ assert_equal expected, @console.output(files,'/',true)
108
+ end
22
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chetan Sarva
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.2'
89
+ version: '2.1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.2'
96
+ version: '2.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: juwelier
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,20 @@ email: chetan@pixelcop.net
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files:
116
+ - CHANGELOG.md
116
117
  - LICENSE.txt
117
118
  - README.md
118
119
  files:
119
120
  - ".document"
121
+ - CHANGELOG.md
120
122
  - Gemfile
121
123
  - LICENSE.txt
122
124
  - README.md
123
125
  - Rakefile
124
126
  - VERSION
125
127
  - lib/simplecov-console.rb
128
+ - lib/simplecov-console/output/block.rb
129
+ - lib/simplecov-console/output/table.rb
126
130
  - simplecov-console.gemspec
127
131
  - test/helper.rb
128
132
  - test/test_simplecov-console.rb
@@ -130,7 +134,7 @@ homepage: http://github.com/chetan/simplecov-console
130
134
  licenses:
131
135
  - MIT
132
136
  metadata: {}
133
- post_install_message:
137
+ post_install_message:
134
138
  rdoc_options: []
135
139
  require_paths:
136
140
  - lib
@@ -145,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
149
  - !ruby/object:Gem::Version
146
150
  version: '0'
147
151
  requirements: []
148
- rubygems_version: 3.0.2
149
- signing_key:
152
+ rubygems_version: 3.1.4
153
+ signing_key:
150
154
  specification_version: 4
151
155
  summary: Simple console output formatter
152
156
  test_files: []