diff --git a/lib/rackstash/buffer_stack.rb b/lib/rackstash/buffer_stack.rb index fbce867..12905b2 100644 --- a/lib/rackstash/buffer_stack.rb +++ b/lib/rackstash/buffer_stack.rb @@ -49,13 +49,18 @@ module Rackstash buffer end - # Remove the top-most Buffer from the internal stack. + # Remove the top-most {Buffer} from the internal stack without flushing it. # - # If there was a buffer on the stack and it has pending data, it is flushed - # to the {#sink} before it is returned. + # @return [Buffer, nil] the poped {Buffer} or `nil` if there was no {Buffer} + # to remove. + def pop + @stack.pop + end + + # Flush and remove the top-most {Buffer} from the internal stack. # - # @return [Buffer, nil] the removed {Buffer} or `nil` if there was no - # {Buffer} to remove + # @return [Buffer, nil] the poped and flushed {Buffer} or `nil` if there was + # no {Buffer} to remove def flush_and_pop buffer = @stack.pop buffer.flush if buffer diff --git a/spec/rackstash/buffer_stack_spec.rb b/spec/rackstash/buffer_stack_spec.rb index b82b93f..e0e2299 100644 --- a/spec/rackstash/buffer_stack_spec.rb +++ b/spec/rackstash/buffer_stack_spec.rb @@ -85,4 +85,30 @@ describe Rackstash::BufferStack do stack.flush_and_pop # no further buffer, thus `#flush` is not called again end end + + describe '#pop' do + it 'removes a buffer from the stack' do + stack.push + expect { stack.pop } + .to change { stack.instance_variable_get(:@stack).count }.from(1).to(0) + end + + it 'does nothing if there is no buffer' do + expect(stack.instance_variable_get(:@stack).count).to eql 0 + expect(stack.pop).to be_nil + end + + it 'returns the pop\'ed Buffer' do + stack.push + expect(stack.pop).to be_a Rackstash::Buffer + expect(stack.pop).to be nil + end + + it 'does not flushes the buffer' do + new_buffer = stack.push + + expect(new_buffer).not_to receive(:flush) + stack.pop + end + end end