Skip to content

Commit

Permalink
Ensure all serializer #dump methods return the size of the file (#36)
Browse files Browse the repository at this point in the history
- Add test in `a serializer` shared examples
- Implement method for `Rambling::Trie::Serializers::Zip`
  • Loading branch information
gonzedge committed May 11, 2023
1 parent 6d8bba3 commit 7d7166d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,6 +1,7 @@
# Vim
# Vim / IDEs
*.swp
*.swo
.idea/

# RVM
.rvmrc
Expand Down
2 changes: 2 additions & 0 deletions lib/rambling/trie/serializers/zip.rb
Expand Up @@ -50,6 +50,8 @@ def dump contents, filepath

zip.add filename, entry_path
end

::File.size filepath
end

private
Expand Down
13 changes: 9 additions & 4 deletions spec/support/shared_examples/a_serializer.rb
Expand Up @@ -16,17 +16,22 @@
describe '#dump' do
[true, false].each do |compress_value|
context "with compressed=#{compress_value} trie" do
before do
trie.compress! if compress_value
serializer.dump content, filepath
let(:formatted_content) { format_content.call content }

before { trie.compress! if compress_value }

it 'returns the size in bytes of the file dumped' do
total_bytes = serializer.dump content, filepath
expect(total_bytes).to be_within(20).of formatted_content.size
end

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

it 'converts the contents to the appropriate format' do
formatted_content = format_content.call content
serializer.dump content, filepath
expect(File.size filepath).to be_within(20).of formatted_content.size
end
end
Expand Down

0 comments on commit 7d7166d

Please sign in to comment.