diff --git a/CHANGELOG.md b/CHANGELOG.md index 03655ae..5b3a432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rails_stats/console_formatter.rb b/lib/rails_stats/console_formatter.rb index e12fae1..83b56d0 100644 --- a/lib/rails_stats/console_formatter.rb +++ b/lib/rails_stats/console_formatter.rb @@ -3,7 +3,7 @@ module RailsStats class ConsoleFormatter < StatsFormatter def to_s - Bundler::Stats::CLI.start + Bundler::Stats::CLI.start(['--format', 'text']) print_header sorted_keys = @statistics.keys.sort @@ -70,4 +70,4 @@ def print_schema_stats end end end -end \ No newline at end of file +end diff --git a/test/lib/rails_stats/console_formatter_test.rb b/test/lib/rails_stats/console_formatter_test.rb new file mode 100644 index 0000000..60f318a --- /dev/null +++ b/test/lib/rails_stats/console_formatter_test.rb @@ -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