Sha256: b100057c9318bb4c700e8839f0cedb288c191fcc5a313795c928bd14a2b7dbb9

Contents?: true

Size: 1.02 KB

Versions: 22

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'

describe Betterlog::Log::Event do
  describe '#as_json' do
    it 'dups hash before returning it' do
      event = described_class.new
      expect(event.as_json).not_to equal event.instance_variable_get(:@data)
    end
  end

  describe '#to_json' do
    it 'can deal with circular arrays' do
      circular_array = [].tap { |arr| arr << arr }
      event = described_class.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 = described_class.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 = described_class.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

22 entries across 22 versions & 1 rubygems

Version Path
betterlog-2.0.4 spec/betterlog/log/event_spec.rb
betterlog-2.0.3 spec/betterlog/log/event_spec.rb
betterlog-2.0.2 spec/betterlog/log/event_spec.rb
betterlog-2.0.1 spec/betterlog/log/event_spec.rb
betterlog-2.0.0 spec/betterlog/log/event_spec.rb
betterlog-1.1.1 spec/betterlog/log/event_spec.rb
betterlog-1.1.0 spec/betterlog/log/event_spec.rb
betterlog-1.0.0 spec/betterlog/log/event_spec.rb
betterlog-0.20.3 spec/betterlog/log/event_spec.rb
betterlog-0.20.2 spec/betterlog/log/event_spec.rb
betterlog-0.20.1 spec/betterlog/log/event_spec.rb
betterlog-0.20.0 spec/betterlog/log/event_spec.rb
betterlog-0.19.0 spec/betterlog/log/event_spec.rb
betterlog-0.18.0 spec/betterlog/log/event_spec.rb
betterlog-0.15.2 spec/betterlog/log/event_spec.rb
betterlog-0.15.1 spec/betterlog/log/event_spec.rb
betterlog-0.15.0 spec/betterlog/log/event_spec.rb
betterlog-0.14.1 spec/betterlog/log/event_spec.rb
betterlog-0.14.0 spec/betterlog/log/event_spec.rb
betterlog-0.13.1 spec/betterlog/log/event_spec.rb