Skip to content

Commit 8f2e5b7

Browse files
authored
Merge pull request #40 from fastruby/match-json-output
Match text and JSON output
2 parents 00ccb50 + 64f55b2 commit 8f2e5b7

File tree

7 files changed

+416
-347
lines changed

7 files changed

+416
-347
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
gem uninstall bundler -a -x || true
2828
- name: Install Bundler
2929
run: |
30-
if [[ "${{ matrix.ruby-version }}" == "2.6" || "${{ matrix.ruby-version }}" == "2.7" ]]; then
30+
if [[ "${{ matrix.ruby-version }}" == "2.5" ]]; then
31+
gem install bundler -v "~> 2.3.27"
32+
elif [[ "${{ matrix.ruby-version }}" == "2.6" || "${{ matrix.ruby-version }}" == "2.7" ]]; then
3133
gem install bundler -v "~> 2.4.0"
3234
else
3335
gem install bundler

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# main ([unreleased](https://github.com/fastruby/rails_stats/compare/v1.0.2...main))
22

3-
*
3+
* [BUGFIX: Fix JSON output missing Code and Tests total count](https://github.com/fastruby/rails_stats/pull/40)
4+
* Update README examples
45

56
# v2.0.1 ([commits](https://github.com/fastruby/rails_stats/compare/v2.0.0...v2.0.1))
67

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ gemspec
55
group :development, :test do
66
gem "bundler", ">= 1.6", "< 3.0"
77
gem "byebug"
8-
gem "codecov"
8+
gem "codecov", "~> 0.6.0"
99
gem "minitest"
1010
gem "minitest-around"
1111
gem "minitest-spec-context"
12-
gem "simplecov"
12+
gem "simplecov", "~> 0.21"
1313
gem "simplecov-console"
1414
end

README.md

Lines changed: 125 additions & 210 deletions
Large diffs are not rendered by default.

lib/rails_stats/json_formatter.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
module RailsStats
44
class JSONFormatter < StatsFormatter
55
def result
6-
@result = @statistics.map { |key, stats| stat_hash(key, stats) }
6+
@result = []
7+
old_stdout = $stdout
8+
$stdout = StringIO.new
9+
Bundler::Stats::CLI.start(["-f", "json"])
10+
bundler_stats_cli_json_result = $stdout.string
11+
$stdout = old_stdout
712

8-
if @grand_total
9-
@result << stat_hash("Total", @grand_total).merge(code_test_hash)
10-
end
13+
@result << JSON.parse(bundler_stats_cli_json_result) unless bundler_stats_cli_json_result.strip.empty?
14+
15+
@result += @statistics.map { |key, stats| stat_hash(key, stats) }
16+
@result << stat_hash("Code", @code_total).merge(code_test_hash) if @code_total
17+
@result << stat_hash("Tests", @tests_total).merge(code_test_hash) if @tests_total
18+
@result << stat_hash("Total", @grand_total).merge(code_test_hash) if @grand_total
1119

1220
@result
1321
end
1422

1523
def to_s
16-
puts result.to_json
24+
puts JSON.generate(result, ascii_only: false)
1725
end
1826

1927
private

test/fixtures/console-output.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
+-----------------------|------------|----------------+
22
| Name | Total Deps | 1st Level Deps |
33
+-----------------------|------------|----------------+
4-
| simplecov-console | 7 | 3 |
5-
| codecov | 5 | 2 |
4+
| simplecov-console | 8 | 3 |
5+
| codecov | 4 | 1 |
66
| rails_stats | 4 | 2 |
77
| simplecov | 3 | 3 |
88
| minitest-around | 1 | 1 |
@@ -14,14 +14,14 @@
1414

1515
Declared Gems 9
1616
Total Gems 18
17-
Unpinned Versions 8
17+
Unpinned Versions 6
1818
Github Refs 0
1919

2020
+----------------------+---------+---------+---------+---------+---------+-----+-------+
2121
| Name | Files | Lines | LOC | Classes | Methods | M/C | LOC/M |
2222
+----------------------+---------+---------+---------+---------+---------+-----+-------+
2323
| Channels | 2 | 8 | 8 | 2 | 0 | 0 | 0 |
24-
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
24+
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
2525
| Controllers | 1 | 7 | 6 | 1 | 1 | 1 | 4 |
2626
| Helpers | 1 | 3 | 3 | 0 | 0 | 0 | 0 |
2727
| Javascripts | 3 | 27 | 7 | 0 | 0 | 0 | 0 |

0 commit comments

Comments
 (0)