Skip to content

Commit

Permalink
Add unserialization specs
Browse files Browse the repository at this point in the history
  • Loading branch information
divoxx committed Oct 2, 2009
1 parent 3474196 commit 61053d4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
spec.spec_opts = ["--options spec/spec.opts"]
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
Expand Down
1 change: 0 additions & 1 deletion spec/php_serialization/parser.rb

This file was deleted.

3 changes: 3 additions & 0 deletions spec/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--diff u
--color
--format profile
52 changes: 52 additions & 0 deletions spec/unserialization_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require File.dirname(__FILE__) + "/spec_helper"

describe "Unserialization" do
it "should unserialize a integer" do
PhpSerialization.load("i:10;").should == 10
end

it "should unserialize a string" do
PhpSerialization.load('s:4:"Name";').should == "Name"
end

it "should unserialize true" do
PhpSerialization.load('b:1;').should == true
end

it "should unserialize false" do
PhpSerialization.load('b:0;').should == false
end

it "should unserialize nil" do
PhpSerialization.load('N;').should == nil
end

it "should unzerialize an array" do
PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";};').should == [true, "foo"]
end

it "should unserialize a hash" do
PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;};').should == {"name" => "Rodrigo", "age" => 23}
end

it "should unserialize object with class existant" do
class Person
attr_accessor :name, :age
end

person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;};')
person.should be_instance_of(Person)
person.name.should == "Rodrigo"
person.age.should == 23


Object.send(:remove_const, :Person)
end

it "should unserialize object without class as a struct" do
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;};')
person.should be_instance_of(Struct::Person)
person.name.should == "Rodrigo"
person.age.should == 23
end
end

0 comments on commit 61053d4

Please sign in to comment.