Sha256: d6252040d917ffd582cfe73d6aecd915d150b77171a86d7d26027361a8f0d5bc

Contents?: true

Size: 867 Bytes

Versions: 2

Compression:

Stored size: 867 Bytes

Contents

require 'spec_helper'

describe Betterlog::Log::Event do
  describe '#to_json' do
    it 'can deal with circular arrays' do
      circular_array = [].tap { |arr| arr << arr }
      event = Betterlog::Log::Event.new(array: circular_array)
      expect(event.to_json).to include('"array":["circular"]')
    end

    it 'can deal with circular hashes' do
      circular_hash = {}.tap { |hash| hash['foo'] = hash }
      event = Betterlog::Log::Event.new(hash: circular_hash)
      expect(event.to_json).to include('"hash":{"foo":"circular"}')
    end

    it 'does not replace repeated scalar objects with "circular"' do
      ary = [true, false, nil, 23, 3.14]
      event = Betterlog::Log::Event.new(ary: ary << ary.dup)
      expect(event.to_json).to include(<<~end.strip)
        "ary":[true,false,null,23,3.14,[true,false,null,23,3.14]]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
betterlog-0.7.1 spec/betterlog/log/event_spec.rb
betterlog-0.7.0 spec/betterlog/log/event_spec.rb