Sha256: 8efcd0a989dc2e37d7fbc3788851ff5cf8fe8715f73155f4c4a1202ffd60f52a

Contents?: true

Size: 1.66 KB

Versions: 15

Compression:

Stored size: 1.66 KB

Contents

# encoding: utf-8
require File.dirname(__FILE__) + '/../spec_helper'

describe Dragonfly::Serializer do
  
  include Dragonfly::Serializer
  
  [
    'a',
    'sdhflasd',
    '/2010/03/01/hello.png',
    '//..',
    'whats/up.egg.frog',
    '£ñçùí;'
  ].each do |string|
    it "should encode #{string.inspect} properly with no padding/line break" do
      b64_encode(string).should_not =~ /\n|=/
    end
    it "should correctly encode and decode #{string.inspect} to the same string" do
      str = b64_decode(b64_encode(string))
      str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
      str.should == string
    end
  end
  
  [
    :hello,
    nil,
    true,
    4,
    2.3,
    'wassup man',
    [3,4,5],
    {:wo => 'there'},
    [{:this => 'should', :work => [3, 5.3, nil, {false => 'egg'}]}, [], true]
  ].each do |object|
    it "should correctly marshal encode #{object.inspect} properly with no padding/line break" do
      encoded = marshal_encode(object)
      # raise encoded.index("\n").inspect
      encoded.should be_a(String)
      encoded.should_not =~ /\n|=/
    end
    it "should correctly marshal encode and decode #{object.inspect} to the same object" do
      marshal_decode(marshal_encode(object)).should == object
    end
  end
  
  describe "marshal_decode" do
    it "should raise an error if the string passed in is empty" do
      lambda{
        marshal_decode('')
      }.should raise_error(Dragonfly::Serializer::BadString)
    end
    it "should raise an error if the string passed in is gobbledeegook" do
      lambda{
        marshal_decode('ahasdkjfhasdkfjh')
      }.should raise_error(Dragonfly::Serializer::BadString)
    end
  end
  
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
dragonfly-0.8.5 spec/dragonfly/serializer_spec.rb
dragonfly-0.8.4 spec/dragonfly/serializer_spec.rb
fog-dragonfly-0.8.2 spec/dragonfly/serializer_spec.rb
dragonfly-0.8.2 spec/dragonfly/serializer_spec.rb
fog-dragonfly-0.8.1 spec/dragonfly/serializer_spec.rb
dragonfly-0.8.1 spec/dragonfly/serializer_spec.rb
dragonfly-0.8.0 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.7 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.6 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.5 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.4 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.3 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.2 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.1 spec/dragonfly/serializer_spec.rb
dragonfly-0.7.0 spec/dragonfly/serializer_spec.rb