Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# main ([unreleased](https://github.com/fastruby/rails_stats/compare/v1.0.2...main))

* [CHORE: Improve the GH Test Workflow](https://github.com/fastruby/rails_stats/pull/35)
* [BUGFIX: Explicitly set format as text for `Bundler::Stats::CLI` on `ConsoleFormatter`](https://github.com/fastruby/rails_stats/pull/43)
* [BUGFIX: Fix JSON output missing Code and Tests total count](https://github.com/fastruby/rails_stats/pull/40)
* Update README examples
* [FEATURE: Output number of tables created from schema.rb or structure.sql, add polymorphic models count](https://github.com/fastruby/rails_stats/pull/37)
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_stats/console_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RailsStats
class ConsoleFormatter < StatsFormatter
def to_s
Bundler::Stats::CLI.start
Bundler::Stats::CLI.start(['--format', 'text'])
Copy link
Copy Markdown
Member

@JuanVqz JuanVqz Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the command; although it works, please consider being more explicit by including the stats subcommand.

Thor may be defaulting to stats but this makes the intent clearer and less reliant on Thor's default behavior.

Suggested change
Bundler::Stats::CLI.start(['--format', 'text'])
Bundler::Stats::CLI.start(['stats', '--format', 'text'])

Without stats

➜ Bundler::Stats::CLI.start(['--format', 'text'])"
The dependency `bundler` wasn't found. It may not be present in your Gemfile.lock. This often happens when a dependency isn't installed on your platform.
The dependency `bundler` wasn't found. It may not be present in your Gemfile.lock. This often happens when a dependency isn't installed on your platform.
+-----------------------|------------|----------------+
|                  Name | Total Deps | 1st Level Deps |
+-----------------------|------------|----------------+
|     simplecov-console | 8          | 3              |
|               codecov | 4          | 1              |
|           rails_stats | 4          | 2              |
|             simplecov | 3          | 3              |
|       minitest-around | 1          | 1              |
|               bundler | 0          | 0              |
|                byebug | 0          | 0              |
|              minitest | 0          | 0              |
| minitest-spec-context | 0          | 0              |
+-----------------------|------------|----------------+

      Declared Gems   9
         Total Gems   18
  Unpinned Versions   6
        Github Refs   0

With stats

➜ Bundler::Stats::CLI.start(['stats', '--format', 'text'])"
The dependency `bundler` wasn't found. It may not be present in your Gemfile.lock. This often happens when a dependency isn't installed on your platform.
The dependency `bundler` wasn't found. It may not be present in your Gemfile.lock. This often happens when a dependency isn't installed on your platform.
+-----------------------|------------|----------------+
|                  Name | Total Deps | 1st Level Deps |
+-----------------------|------------|----------------+
|     simplecov-console | 8          | 3              |
|               codecov | 4          | 1              |
|           rails_stats | 4          | 2              |
|             simplecov | 3          | 3              |
|       minitest-around | 1          | 1              |
|               bundler | 0          | 0              |
|                byebug | 0          | 0              |
|              minitest | 0          | 0              |
| minitest-spec-context | 0          | 0              |
+-----------------------|------------|----------------+

      Declared Gems   9
         Total Gems   18
  Unpinned Versions   6
        Github Refs   0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruyrocha Do you think committing this is a good addition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruyrocha Do you think committing this is a good addition?

I'll revisit this (plus tests) later today; I didn't double-check but I have the sense stats is already being chained.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruyrocha, would appreciate that; feel free to ping me when you are done. 👍

Copy link
Copy Markdown
Member

@JuanVqz JuanVqz Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked it, and I don't think we need to add the stats arg; so, this is good to go.


print_header
sorted_keys = @statistics.keys.sort
Expand Down Expand Up @@ -70,4 +70,4 @@ def print_schema_stats
end
end
end
end
end
26 changes: 26 additions & 0 deletions test/lib/rails_stats/console_formatter_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'test_helper'

describe RailsStats::ConsoleFormatter do
describe '#to_s' do
it 'invokes Bundler::Stats::CLI with text format' do
root_directory = File.absolute_path('./test/dummy')
calculator = RailsStats::StatsCalculator.new(root_directory)
formatter = RailsStats::ConsoleFormatter.new(calculator)

received_args = nil
original = Bundler::Stats::CLI.method(:start)
Bundler::Stats::CLI.define_singleton_method(:start) { |args = []| received_args = args }

begin
capture_io { formatter.to_s }
ensure
Bundler::Stats::CLI.singleton_class.remove_method(:start)
Bundler::Stats::CLI.define_singleton_method(:start, original)
end

assert_equal ['--format', 'text'], received_args
end
end
end
Loading