From 846a93684d2d81ef102717004cd076c1b93544f7 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 17 Apr 2015 18:05:45 -0700 Subject: add :unique_key_checking flag to parser can be used to error out if keys are duplicated in input rather than silently replacing. --- spec/ffi_yajl/parser_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb index 7592f67..ed6ef2a 100644 --- a/spec/ffi_yajl/parser_spec.rb +++ b/spec/ffi_yajl/parser_spec.rb @@ -492,6 +492,21 @@ describe "FFI_Yajl::Parser" do expect{ parser }.not_to raise_error end end + + context "should ignore repeated keys by default" do + let(:json) { '{"foo":"bar","foo":"baz"}' } + it "should replace the first hash key with the second" do + expect(parser).to eql( "foo" => "baz" ) + end + end + + context "should raise an exception for repeated keys" do + let(:json) { '{"foo":"bar","foo":"baz"}' } + let(:options) { { :unique_key_checking => true } } + it "should raise" do + expect{ parser }.to raise_error(FFI_Yajl::ParseError) + end + end end context "when options are set to empty hash" do -- cgit v1.2.1