Sha256: d1572418e6eefd50663cb968e07e7c2b56bd21e6b6294d03b129f6f6c237cca0

Contents?: true

Size: 932 Bytes

Versions: 6

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

shared_examples_for 'a serializer' do
  let(:trie) { Rambling::Trie.create }
  let(:tmp_path) { File.join ::SPEC_ROOT, 'tmp' }
  let(:filepath) { File.join tmp_path, "trie-root.#{format}" }
  let(:content) { trie.root }

  before do
    trie.concat %w(a few words to validate that load and dump are working)
    FileUtils.rm_f filepath
  end

  describe '#dump' do
    before do
      serializer.dump content, filepath
    end

    it 'creates the file with the provided path' do
      expect(File.exist? filepath).to be true
    end

    it 'converts the contents to the appropriate format' do
      expect(File.read(filepath).size).to be_within(10).of formatted_content.size
    end
  end

  describe '#load' do
    before do
      serializer.dump content, filepath
    end

    it 'loads the dumped object back into memory' do
      expect(serializer.load filepath).to eq content
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rambling-trie-2.3.0 spec/support/shared_examples/a_serializer.rb
rambling-trie-2.2.1 spec/support/shared_examples/a_serializer.rb
rambling-trie-2.2.0 spec/support/shared_examples/a_serializer.rb
rambling-trie-opal-2.1.1.1 spec/support/shared_examples/a_serializer.rb
rambling-trie-opal-2.1.1 spec/support/shared_examples/a_serializer.rb
rambling-trie-2.1.1 spec/support/shared_examples/a_serializer.rb