From 34211c91b342da3056ce25734ee76c8e3e8f00bb Mon Sep 17 00:00:00 2001 From: buty4649 Date: Thu, 5 Dec 2024 12:39:24 +0900 Subject: [PATCH 1/2] Improve test for -r option --- spec/filter/json_spec.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/filter/json_spec.rb b/spec/filter/json_spec.rb index 24af0f4..0fee448 100644 --- a/spec/filter/json_spec.rb +++ b/spec/filter/json_spec.rb @@ -14,12 +14,19 @@ context 'with -r option' do describe 'Output string' do let(:input) { load_fixture('json/string.json') } - let(:output) { 'test' } + let(:args) { '-j -r _' } + let(:expect_output) { "test\n" } - before { run_rf('-j -r _', input) } + it_behaves_like 'a successful exec' + end - it { expect(last_command_started).to be_successfully_executed } - it { expect(last_command_started).to have_output output_string_eq output } + # When using pipes, `--no-color` is implicitly applied internally, so we explicitly test for it. + context 'with --color option' do + let(:input) { load_fixture('json/string.json') } + let(:args) { '-j -r --color _' } + let(:expect_output) { "test\n" } + + it_behaves_like 'a successful exec' end end From b722774ddf7d0bf3798d138f5a7e818464becff0 Mon Sep 17 00:00:00 2001 From: buty4649 Date: Wed, 4 Dec 2024 17:48:30 +0900 Subject: [PATCH 2/2] Disable colorize in json raw output --- mrblib/rf/00filter/json.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mrblib/rf/00filter/json.rb b/mrblib/rf/00filter/json.rb index 9423bf3..f107804 100644 --- a/mrblib/rf/00filter/json.rb +++ b/mrblib/rf/00filter/json.rb @@ -50,11 +50,7 @@ def format(val, record) def string_to_json(str) if raw? - if colorize - JSON.colorize(str, JSON.color_string) - else - str - end + str else str.to_json(colorize:, pretty_print:) end