|
29 | 29 |
|
30 | 30 | describe '#<<' do |
31 | 31 | it 'forwards data to parser' do |
32 | | - data = {} |
33 | 32 | streamer = Json::Streamer.parser |
| 33 | + allow(streamer).to receive(:<<) |
34 | 34 |
|
35 | | - expect(streamer.parser).to receive(:<<).with(data) |
| 35 | + streamer << {} |
36 | 36 |
|
37 | | - streamer << data |
| 37 | + expect(streamer).to have_received(:<<).with({}) |
38 | 38 | end |
39 | 39 | end |
40 | 40 |
|
41 | 41 | RSpec.shared_examples 'an iterable object' do |
42 | 42 | let(:hash) { example_multi_level_hash } |
43 | 43 |
|
44 | 44 | context 'when no block is passed' do |
45 | | - let(:subject) { streamer.send(method, **params) } |
| 45 | + subject(:send) { streamer.send(method, **params) } |
46 | 46 |
|
47 | 47 | it 'returns an Enumerable' do |
48 | | - expect(subject).to be_a(Enumerable) |
| 48 | + expect(send).to be_a(Enumerable) |
49 | 49 | end |
50 | 50 |
|
51 | 51 | it 'returns array of items that would have been yielded' do |
52 | | - expect(subject).to eq(Array.new(3) { example_hash }) |
| 52 | + expect(send).to eq(Array.new(3) { example_hash }) |
53 | 53 | end |
54 | 54 | end |
55 | 55 |
|
|
63 | 63 |
|
64 | 64 | context 'when an empty block is passed' do |
65 | 65 | it 'returns an empty Enumerable' do |
| 66 | + # rubocop:disable Lint/EmptyBlock |
66 | 67 | unyielded_objects = streamer.send(method, **params) {} |
| 68 | + # rubocop:enable Lint/EmptyBlock |
| 69 | + |
67 | 70 | expect(unyielded_objects).to eq([]) |
68 | 71 | end |
69 | 72 | end |
|
330 | 333 | let(:hash) { example_multi_level_hash } |
331 | 334 |
|
332 | 335 | context 'when no block is passed' do |
333 | | - let(:subject) { streamer.send(method, params) } |
| 336 | + subject(:send) { streamer.send(method, params) } |
334 | 337 |
|
335 | 338 | it 'returns an Enumerable' do |
336 | | - expect(subject).to be_a(Enumerable) |
| 339 | + expect(send).to be_a(Enumerable) |
337 | 340 | end |
338 | 341 |
|
339 | 342 | it 'returns array of items that would have been yielded' do |
340 | | - expect(subject).to eq(Array.new(3) { example_hash }) |
| 343 | + expect(send).to eq(Array.new(3) { example_hash }) |
341 | 344 | end |
342 | 345 | end |
343 | 346 |
|
|
351 | 354 |
|
352 | 355 | context 'when an empty block is passed' do |
353 | 356 | it 'returns an empty Enumerable' do |
| 357 | + # rubocop:disable Lint/EmptyBlock |
354 | 358 | unyielded_objects = streamer.send(method, params) {} |
| 359 | + # rubocop:enable Lint/EmptyBlock |
| 360 | + |
355 | 361 | expect(unyielded_objects).to eq([]) |
356 | 362 | end |
357 | 363 | end |
|
419 | 425 |
|
420 | 426 | describe '#get (generated)' do |
421 | 427 | context 'with JSONs with various nesting level and number of objects per level' do |
| 428 | + # rubocop:disable RSpec/ExampleLength |
422 | 429 | it 'yields all objects on desired level (checking number of yielded objects)' do |
423 | 430 | # Setting these options to high can cause the test to run longer |
424 | 431 | entries_per_level = 2 |
|
437 | 444 | expect(yielded_objects.length).to eq(entries_per_level**(max_level - 1)) |
438 | 445 | end |
439 | 446 | end |
| 447 | + # rubocop:enable RSpec/ExampleLength |
440 | 448 | end |
441 | 449 | end |
442 | 450 | end |
|
0 commit comments