From ede214bf2110a3dcf789bd7f9f9a2e56ca973a00 Mon Sep 17 00:00:00 2001 From: buty4649 Date: Thu, 13 Jun 2024 23:12:48 +0900 Subject: [PATCH] Add tests for invalid JSON and duplicate keys handling --- spec/filter/json_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/filter/json_spec.rb b/spec/filter/json_spec.rb index a514cae..0cb3d5b 100644 --- a/spec/filter/json_spec.rb +++ b/spec/filter/json_spec.rb @@ -281,4 +281,34 @@ it { expect(last_command_started).to have_output output_string_eq output } end end + + context 'when inptut is invalid JSON' do + describe 'Error message' do + let(:input) { '{"foo": "bar"' } + + let(:args) { '-j _' } + let(:expect_output) do + 'Error: failed to parse JSON: unexpected end of data position: 14' + end + + it_behaves_like 'a failed exec' + end + end + + context 'with duplicate keys in the input object' do + describe 'Output string' do + let(:input) { '{"foo": "bar", "foo": "baz"}' } + + let(:args) { '-j _' } + let(:expect_output) do + <<~JSON + { + "foo": "baz" + } + JSON + end + + it_behaves_like 'a successful exec' + end + end end