Skip to content

Commit

Permalink
Added spec & slightly different snappy check
Browse files Browse the repository at this point in the history
  • Loading branch information
dim authored and tamird committed Oct 8, 2014
1 parent ca6b47e commit 51f1042
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new("spec:unit") do |t|
t.pattern = 'spec/unit/*_spec.rb'
t.pattern = 'spec/unit/**/*_spec.rb'
end

RSpec::Core::RakeTask.new('spec:integration:simple') do |t|
Expand Down
4 changes: 3 additions & 1 deletion lib/poseidon/compression/snappy_codec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ def self.decompress(s)

def self.check!
@checked ||= begin
raise "Snappy compression is not available, please install the 'snappy' gem"
require 'snappy'
true
rescue LoadError
raise "Snappy compression is not available, please install the 'snappy' gem"
end
end

Expand Down
23 changes: 23 additions & 0 deletions spec/unit/compression/snappy_codec_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe Poseidon::Compression::SnappyCodec do

let :data do
%({"a":"val1"}\n{"a":"val2"}\n{"a":"val3"})
end

it "should have an ID" do
expect(described_class.codec_id).to eq(2)
end

it "should compress" do
compressed = described_class.compress(data)
expect(compressed.size).to eq(34)
expect(compressed.encoding).to eq(Encoding::BINARY)
end

it "should decompress" do
original = described_class.decompress(described_class.compress(data))
expect(original).to eq(data)
end
end

0 comments on commit 51f1042

Please sign in to comment.