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 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