diff --git a/spec/segment/analytics/message_batch_spec.rb b/spec/segment/analytics/message_batch_spec.rb index 5f7b2fd..8dd5370 100644 --- a/spec/segment/analytics/message_batch_spec.rb +++ b/spec/segment/analytics/message_batch_spec.rb @@ -1,38 +1,43 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" module Segment class Analytics describe MessageBatch do subject { described_class.new(100) } - describe '#<<' do - it 'appends messages' do - subject << { 'a' => 'b' } + describe "#<<" do + it "appends messages" do + expect(subject.length).to eq(0) + + subject << {"a" => "b"} + expect(subject.length).to eq(1) end - it 'rejects messages that exceed the maximum allowed size' do + it "rejects messages that exceed the maximum allowed size" do max_bytes = Defaults::Message::MAX_BYTES - message = { 'a' => 'b' * max_bytes } + message = {"a" => "b" * max_bytes} + + expect(subject.length).to eq(0) - subject << message - expect(subject.length).to eq(0).and_raise(JSONGenerationError.new("Message Exceeded Maximum Allowed Size")) + expect { subject << message }.to raise_error(MessageBatch::JSONGenerationError) + .with_message("Message Exceeded Maximum Allowed Size") end end - describe '#full?' do - it 'returns true once item count is exceeded' do - 99.times { subject << { a: 'b' } } + describe "#full?" do + it "returns true once item count is exceeded" do + 99.times { subject << {a: "b"} } expect(subject.full?).to be(false) - subject << { a: 'b' } + subject << {a: "b"} expect(subject.full?).to be(true) end - it 'returns true once max size is almost exceeded' do - message = { a: 'b' * (Defaults::Message::MAX_BYTES - 10) } + it "returns true once max size is almost exceeded" do + message = {a: "b" * (Defaults::Message::MAX_BYTES - 10)} message_size = message.to_json.bytesize