From 1f3b673e77c2692c5a698f96448754f001fb80cb Mon Sep 17 00:00:00 2001 From: Csaba Apagyi Date: Thu, 4 May 2017 11:52:46 +0200 Subject: [PATCH] Refactor test file to match naming and module structure; Add array yield test case --- .../streamer/json_streamer_spec.rb} | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) rename spec/{streamer_spec.rb => json/streamer/json_streamer_spec.rb} (92%) diff --git a/spec/streamer_spec.rb b/spec/json/streamer/json_streamer_spec.rb similarity index 92% rename from spec/streamer_spec.rb rename to spec/json/streamer/json_streamer_spec.rb index 066a96e..6a3c72c 100644 --- a/spec/streamer_spec.rb +++ b/spec/json/streamer/json_streamer_spec.rb @@ -8,7 +8,7 @@ @example_hash = {@example_key => @example_value} end - describe '#get_nesting_level' do + describe '#get' do context 'Get 0th level of empty JSON object' do it 'should yield empty JSON object' do @@ -133,10 +133,6 @@ end end - end - - describe '#get_nesting_level' do - context 'Get data from flat JSON by key' do it 'should yield value within JSON object' do @@ -213,6 +209,25 @@ end end + context 'JSON array' do + it 'should yield array elements' do + + hash = [@example_hash, @example_hash, @example_hash] + json_file_mock = StringIO.new(JSON.generate(hash)) + streamer = Json::Streamer::JsonStreamer.new(json_file_mock, 10) + + objects = [] + streamer.get(nesting_level:1) do |object| + objects.push(object) + end + + expect(objects.length).to eq(3) + objects[0..2].each do |element| + expect(element).to eq(@example_hash) + end + end + end + end end