Skip to content

Commit

Permalink
Final Adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
nd4p90x committed May 28, 2024
1 parent 91a24a5 commit 6ede327
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions spec/segment/analytics/message_batch_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 6ede327

Please sign in to comment.