mrpin-rocketamf 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +1 -1
  3. data/Rakefile +7 -7
  4. data/benchmark.rb +44 -37
  5. data/ext/rocketamf_ext/class_mapping.c +11 -11
  6. data/ext/rocketamf_ext/remoting.c +1 -1
  7. data/lib/rocketamf.rb +41 -98
  8. data/lib/rocketamf/constants.rb +20 -20
  9. data/lib/rocketamf/errors.rb +2 -0
  10. data/lib/rocketamf/errors/amf_error.rb +5 -0
  11. data/lib/rocketamf/errors/amf_error_incomplete.rb +5 -0
  12. data/lib/rocketamf/ext.rb +0 -6
  13. data/lib/rocketamf/extensions.rb +4 -4
  14. data/lib/rocketamf/{class_mapping.rb → mapping/class_mapping.rb} +70 -103
  15. data/lib/rocketamf/mapping/mapping_set.rb +63 -0
  16. data/lib/rocketamf/pure.rb +1 -9
  17. data/lib/rocketamf/pure/deserializer.rb +234 -262
  18. data/lib/rocketamf/pure/helpers/io_helper_base.rb +19 -0
  19. data/lib/rocketamf/pure/helpers/io_helper_read.rb +67 -0
  20. data/lib/rocketamf/pure/helpers/io_helper_write.rb +48 -0
  21. data/lib/rocketamf/pure/helpers/object_cache.rb +20 -0
  22. data/lib/rocketamf/pure/helpers/string_cache.rb +14 -0
  23. data/lib/rocketamf/pure/serializer.rb +138 -271
  24. data/lib/rocketamf/types.rb +1 -0
  25. data/lib/rocketamf/{values → types}/typed_hash.rb +12 -2
  26. data/mrpin-rocketamf.gemspec +27 -16
  27. data/spec/class_mapping_spec.rb +59 -52
  28. data/spec/deserializer_spec.rb +164 -328
  29. data/spec/fast_class_mapping_spec.rb +52 -46
  30. data/spec/helpers/class_mapping_test.rb +4 -0
  31. data/spec/helpers/class_mapping_test2.rb +3 -0
  32. data/spec/helpers/externalizable_test.rb +24 -0
  33. data/spec/helpers/fixtures.rb +28 -0
  34. data/spec/helpers/other_class.rb +4 -0
  35. data/spec/helpers/ruby_class.rb +4 -0
  36. data/spec/helpers/test_ruby_class.rb +4 -0
  37. data/spec/serializer_spec.rb +248 -339
  38. data/spec/spec_helper.rb +4 -49
  39. metadata +47 -53
  40. data/lib/rocketamf/pure/io_helpers.rb +0 -94
  41. data/lib/rocketamf/pure/remoting.rb +0 -117
  42. data/lib/rocketamf/remoting.rb +0 -196
  43. data/lib/rocketamf/values/messages.rb +0 -214
  44. data/spec/fixtures/objects/amf0-boolean.bin +0 -1
  45. data/spec/fixtures/objects/amf0-complex-encoded-string.bin +0 -0
  46. data/spec/fixtures/objects/amf0-date.bin +0 -0
  47. data/spec/fixtures/objects/amf0-ecma-ordinal-array.bin +0 -0
  48. data/spec/fixtures/objects/amf0-empty-string-key-hash.bin +0 -0
  49. data/spec/fixtures/objects/amf0-hash.bin +0 -0
  50. data/spec/fixtures/objects/amf0-null.bin +0 -1
  51. data/spec/fixtures/objects/amf0-number.bin +0 -0
  52. data/spec/fixtures/objects/amf0-object.bin +0 -0
  53. data/spec/fixtures/objects/amf0-ref-test.bin +0 -0
  54. data/spec/fixtures/objects/amf0-strict-array.bin +0 -0
  55. data/spec/fixtures/objects/amf0-string.bin +0 -0
  56. data/spec/fixtures/objects/amf0-time.bin +0 -0
  57. data/spec/fixtures/objects/amf0-typed-object.bin +0 -0
  58. data/spec/fixtures/objects/amf0-undefined.bin +0 -1
  59. data/spec/fixtures/objects/amf0-untyped-object.bin +0 -0
  60. data/spec/fixtures/objects/amf0-xml-doc.bin +0 -0
  61. data/spec/messages_spec.rb +0 -39
  62. data/spec/remoting_spec.rb +0 -196
@@ -0,0 +1 @@
1
+ require 'rocketamf/types/typed_hash'
@@ -1,11 +1,21 @@
1
1
  module RocketAMF
2
- module Values #:nodoc:
2
+ module Types #:nodoc:
3
+
3
4
  # Hash-like object that can store a type string. Used to preserve type information
4
5
  # for unmapped objects after deserialization.
5
6
  class TypedHash < Hash
7
+
8
+ #
9
+ # Properties
10
+ #
11
+
6
12
  attr_reader :type
7
13
 
8
- def initialize type
14
+ #
15
+ # Methods
16
+ #
17
+
18
+ def initialize(type)
9
19
  @type = type
10
20
  end
11
21
  end
@@ -1,22 +1,33 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = 'mrpin-rocketamf'
5
- s.version = '1.0.4'
6
- s.platform = Gem::Platform::RUBY
7
- s.authors = ['Jacob Henry', 'Stephen Augenstein', "Joc O'Connor"]
8
- s.email = ['perl.programmer@gmail.com']
9
- s.homepage = 'https://github.com/mrpin/mrpin-rocketamf'
10
- s.summary = 'Fast AMF serializer/deserializer with remoting request/response wrappers to simplify integration'
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'mrpin-rocketamf'
5
+ spec.version = '2.0.0'
6
+ spec.platform = Gem::Platform::RUBY
7
+ spec.authors = ['Jacob Henry', 'Stephen Augenstein', "Joc O'Connor", 'Gregory Tkach']
8
+ spec.email = %w(gregory.tkach@gmail.com)
9
+ spec.homepage = 'https://github.com/mrpin/mrpin-rocketamf'
10
+ spec.license = 'MIT'
11
+ spec.summary = 'Fast AMF3 serializer/deserializer'
12
+ spec.description = 'Fast AMF3 serializer/deserializer with remoting request/response wrappers to simplify integration'
11
13
 
12
- s.files = Dir[*['README.rdoc', 'benchmark.rb', 'mrpin-rocketamf.gemspec', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.{rb,bin,opts}', 'ext/**/*.{c,h,rb}']]
13
- s.test_files = Dir[*['spec/**/*_spec.rb']]
14
- s.extensions = Dir[*["ext/**/extconf.rb"]]
15
- s.require_paths = ["lib"]
14
+ files = []
15
+ files << 'README.rdoc'
16
+ files << 'benchmark.rb'
17
+ files << 'mrpin-rocketamf.gemspec'
18
+ files << 'Rakefile'
19
+ files << 'lib/**/*.rb'
20
+ files << 'spec/**/*.{rb,bin,opts}'
21
+ files << 'ext/**/*.{c,h,rb}'
16
22
 
17
- s.add_development_dependency 'rake-compiler'
23
+ spec.files = Dir[*files]
24
+ spec.test_files = Dir[*['spec/**/*_spec.rb']]
25
+ spec.extensions = Dir[*['ext/**/extconf.rb']]
26
+ spec.require_paths = ['lib']
18
27
 
19
- s.has_rdoc = true
20
- s.extra_rdoc_files = ['README.rdoc']
21
- s.rdoc_options = ['--line-numbers', '--main', 'README.rdoc']
28
+ spec.add_development_dependency 'rake-compiler', '~> 0'
29
+
30
+ spec.has_rdoc = true
31
+ spec.extra_rdoc_files = %w( README.rdoc )
32
+ spec.rdoc_options = %w(--line-numbers --main README.rdoc)
22
33
  end
@@ -1,110 +1,117 @@
1
- require "spec_helper.rb"
1
+ require 'spec_helper.rb'
2
2
 
3
3
  describe RocketAMF::ClassMapping do
4
4
  before :each do
5
5
  RocketAMF::ClassMapping.reset
6
6
  RocketAMF::ClassMapping.define do |m|
7
- m.map :as => 'ASClass', :ruby => 'ClassMappingTest'
7
+ m.map as: 'ASClass', ruby: 'ClassMappingTest'
8
8
  end
9
9
  @mapper = RocketAMF::ClassMapping.new
10
10
  end
11
11
 
12
- describe "class name mapping" do
13
- it "should allow resetting of mappings back to defaults" do
14
- @mapper.get_as_class_name('ClassMappingTest').should_not be_nil
12
+ describe 'class name mapping' do
13
+ it 'should allow resetting of mappings back to defaults' do
14
+ expect(@mapper.get_as_class_name('ClassMappingTest')).not_to be_nil
15
+
15
16
  RocketAMF::ClassMapping.reset
17
+
16
18
  @mapper = RocketAMF::ClassMapping.new
17
- @mapper.get_as_class_name('ClassMappingTest').should be_nil
18
- @mapper.get_as_class_name('RocketAMF::Values::AcknowledgeMessage').should_not be_nil
19
+ expect(@mapper.get_as_class_name('ClassMappingTest')).to be_nil
20
+ expect(@mapper.get_as_class_name('RocketAMF::Types::AcknowledgeMessage')).not_to be_nil
19
21
  end
20
22
 
21
- it "should return AS class name for ruby objects" do
22
- @mapper.get_as_class_name(ClassMappingTest.new).should == 'ASClass'
23
- @mapper.get_as_class_name('ClassMappingTest').should == 'ASClass'
24
- @mapper.get_as_class_name(RocketAMF::Values::TypedHash.new('ClassMappingTest')).should == 'ASClass'
25
- @mapper.get_as_class_name('BadClass').should be_nil
23
+ it 'should return AS class name for ruby objects' do
24
+ expect(@mapper.get_as_class_name(ClassMappingTest.new)).to eq('ASClass')
25
+ expect(@mapper.get_as_class_name('ClassMappingTest')).to eq('ASClass')
26
+ expect(@mapper.get_as_class_name(RocketAMF::Types::TypedHash.new('ClassMappingTest'))).to eq('ASClass')
27
+ expect(@mapper.get_as_class_name('BadClass')).to be_nil
26
28
  end
27
29
 
28
- it "should instantiate a ruby class" do
29
- @mapper.get_ruby_obj('ASClass').should be_a(ClassMappingTest)
30
+ it 'should instantiate a ruby class' do
31
+ expect(@mapper.get_ruby_obj('ASClass')).to be_a(ClassMappingTest)
30
32
  end
31
33
 
32
- it "should properly instantiate namespaced classes" do
33
- RocketAMF::ClassMapping.mappings.map :as => 'ASClass', :ruby => 'ANamespace::TestRubyClass'
34
+ it 'should properly instantiate namespaced classes' do
35
+ RocketAMF::ClassMapping.mappings.map as: 'ASClass', ruby: 'ANamespace::TestRubyClass'
34
36
  @mapper = RocketAMF::ClassMapping.new
35
- @mapper.get_ruby_obj('ASClass').should be_a(ANamespace::TestRubyClass)
37
+
38
+ expect(@mapper.get_ruby_obj('ASClass')).to be_a(ANamespace::TestRubyClass)
36
39
  end
37
40
 
38
- it "should return a hash with original type if not mapped" do
41
+ it 'should return a hash with original type if not mapped' do
39
42
  obj = @mapper.get_ruby_obj('UnmappedClass')
40
- obj.should be_a(RocketAMF::Values::TypedHash)
41
- obj.type.should == 'UnmappedClass'
43
+
44
+ expect(obj).to be_a(RocketAMF::Types::TypedHash)
45
+ expect(obj.type).to eq('UnmappedClass')
42
46
  end
43
47
 
44
- it "should map special classes from AS by default" do
45
- as_classes = [
46
- 'flex.messaging.messages.AcknowledgeMessage',
47
- 'flex.messaging.messages.CommandMessage',
48
- 'flex.messaging.messages.RemotingMessage'
49
- ]
48
+ it 'should map special classes from AS by default' do
49
+ as_classes =
50
+ %w(
51
+ flex.messaging.messages.AcknowledgeMessage
52
+ flex.messaging.messages.CommandMessage
53
+ flex.messaging.messages.RemotingMessage
54
+ )
50
55
 
51
56
  as_classes.each do |as_class|
52
- @mapper.get_ruby_obj(as_class).should_not be_a(RocketAMF::Values::TypedHash)
57
+ expect(@mapper.get_ruby_obj(as_class)).not_to be_a(RocketAMF::Types::TypedHash)
53
58
  end
54
59
  end
55
60
 
56
- it "should map special classes from ruby by default" do
57
- ruby_classes = [
58
- 'RocketAMF::Values::AcknowledgeMessage',
59
- 'RocketAMF::Values::ErrorMessage'
60
- ]
61
+ it 'should map special classes from ruby by default' do
62
+ ruby_classes =
63
+ %w(
64
+ RocketAMF::Types::AcknowledgeMessage
65
+ RocketAMF::Types::ErrorMessage
66
+ )
61
67
 
62
68
  ruby_classes.each do |obj|
63
- @mapper.get_as_class_name(obj).should_not be_nil
69
+ expect(@mapper.get_as_class_name(obj)).not_to be_nil
64
70
  end
65
71
  end
66
72
 
67
- it "should allow config modification" do
68
- RocketAMF::ClassMapping.mappings.map :as => 'SecondClass', :ruby => 'ClassMappingTest'
73
+ it 'should allow config modification' do
74
+ RocketAMF::ClassMapping.mappings.map as: 'SecondClass', ruby: 'ClassMappingTest'
69
75
  @mapper = RocketAMF::ClassMapping.new
70
- @mapper.get_as_class_name(ClassMappingTest.new).should == 'SecondClass'
76
+
77
+ expect(@mapper.get_as_class_name(ClassMappingTest.new)).to eq('SecondClass')
71
78
  end
72
79
  end
73
80
 
74
- describe "ruby object populator" do
75
- it "should populate a ruby class" do
81
+ describe 'ruby object populator' do
82
+ it 'should populate a ruby class' do
76
83
  obj = @mapper.populate_ruby_obj ClassMappingTest.new, {:prop_a => 'Data'}
77
- obj.prop_a.should == 'Data'
84
+ expect(obj.prop_a).to eq('Data')
78
85
  end
79
86
 
80
- it "should populate a typed hash" do
81
- obj = @mapper.populate_ruby_obj RocketAMF::Values::TypedHash.new('UnmappedClass'), {:prop_a => 'Data'}
82
- obj[:prop_a].should == 'Data'
87
+ it 'should populate a typed hash' do
88
+ obj = @mapper.populate_ruby_obj RocketAMF::Types::TypedHash.new('UnmappedClass'), {prop_a: 'Data'}
89
+ expect(obj[:prop_a]).to eq('Data')
83
90
  end
84
91
  end
85
92
 
86
- describe "property extractor" do
87
- it "should extract hash properties" do
88
- hash = {:a => 'test1', 'b' => 'test2'}
93
+ describe 'property extractor' do
94
+ it 'should extract hash properties' do
95
+ hash = {a: 'test1', 'b' => 'test2'}
89
96
  props = @mapper.props_for_serialization(hash)
90
- props.should == {'a' => 'test1', 'b' => 'test2'}
97
+ expect(props).to eq({'a' => 'test1', 'b' => 'test2'})
91
98
  end
92
99
 
93
- it "should extract object properties" do
94
- obj = ClassMappingTest.new
100
+ it 'should extract object properties' do
101
+ obj = ClassMappingTest.new
95
102
  obj.prop_a = 'Test A'
96
103
 
97
104
  hash = @mapper.props_for_serialization obj
98
- hash.should == {'prop_a' => 'Test A', 'prop_b' => nil}
105
+ expect(hash).to eq({'prop_a' => 'Test A', 'prop_b' => nil})
99
106
  end
100
107
 
101
- it "should extract inherited object properties" do
102
- obj = ClassMappingTest2.new
108
+ it 'should extract inherited object properties' do
109
+ obj = ClassMappingTest2.new
103
110
  obj.prop_a = 'Test A'
104
111
  obj.prop_c = 'Test C'
105
112
 
106
113
  hash = @mapper.props_for_serialization obj
107
- hash.should == {'prop_a' => 'Test A', 'prop_b' => nil, 'prop_c' => 'Test C'}
114
+ expect(hash).to eq({'prop_a' => 'Test A', 'prop_b' => nil, 'prop_c' => 'Test C'})
108
115
  end
109
116
  end
110
117
  end
@@ -1,444 +1,280 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "spec_helper.rb"
3
+ require 'spec_helper.rb'
4
4
 
5
- describe "when deserializing" do
5
+ describe 'when deserializing' do
6
6
  before :each do
7
- RocketAMF::ClassMapper.reset
7
+ RocketAMF::CLASS_MAPPER.reset
8
8
  end
9
9
 
10
- it "should raise exception with invalid version number" do
11
- lambda {
12
- RocketAMF.deserialize("", 5)
13
- }.should raise_error("unsupported version 5")
14
- end
15
-
16
- describe "AMF0" do
17
- it "should update source pos if source is a StringIO object" do
18
- input = StringIO.new(object_fixture('amf0-number.bin'))
19
- input.pos.should == 0
20
- output = RocketAMF.deserialize(input, 0)
21
- input.pos.should == 9
22
- end
23
-
24
- it "should deserialize numbers" do
25
- input = object_fixture('amf0-number.bin')
26
- output = RocketAMF.deserialize(input, 0)
27
- output.should == 3.5
28
- end
29
-
30
- it "should deserialize booleans" do
31
- input = object_fixture('amf0-boolean.bin')
32
- output = RocketAMF.deserialize(input, 0)
33
- output.should === true
34
- end
35
-
36
- it "should deserialize UTF8 strings" do
37
- input = object_fixture('amf0-string.bin')
38
- output = RocketAMF.deserialize(input, 0)
39
- output.should == "this is a テスト"
40
- end
41
-
42
- it "should deserialize nulls" do
43
- input = object_fixture('amf0-null.bin')
44
- output = RocketAMF.deserialize(input, 0)
45
- output.should == nil
46
- end
47
-
48
- it "should deserialize undefineds" do
49
- input = object_fixture('amf0-undefined.bin')
50
- output = RocketAMF.deserialize(input, 0)
51
- output.should == nil
52
- end
53
-
54
- it "should deserialize hashes" do
55
- input = object_fixture('amf0-hash.bin')
56
- output = RocketAMF.deserialize(input, 0)
57
- output.should == {'a' => 'b', 'c' => 'd'}
58
- end
59
-
60
- it "should deserialize hashes with empty string keys" do
61
- input = object_fixture('amf0-empty-string-key-hash.bin')
62
- output = RocketAMF.deserialize(input, 0)
63
- output.should == {'a' => 'b', 'c' => 'd', '' => 'last'}
64
- end
65
-
66
- it "should deserialize arrays from flash player" do
67
- # Even Array is serialized as a "hash"
68
- input = object_fixture('amf0-ecma-ordinal-array.bin')
69
- output = RocketAMF.deserialize(input, 0)
70
- output.should == {'0' => 'a', '1' => 'b', '2' => 'c', '3' => 'd'}
71
- end
72
-
73
- it "should deserialize strict arrays" do
74
- input = object_fixture('amf0-strict-array.bin')
75
- output = RocketAMF.deserialize(input, 0)
76
- output.should == ['a', 'b', 'c', 'd']
77
- end
78
-
79
- it "should deserialize dates" do
80
- input = object_fixture('amf0-time.bin')
81
- output = RocketAMF.deserialize(input, 0)
82
- output.should == Time.utc(2003, 2, 13, 5)
83
- end
84
-
85
- it "should deserialize an XML document" do
86
- input = object_fixture('amf0-xml-doc.bin')
87
- output = RocketAMF.deserialize(input, 0)
88
- output.should == '<parent><child prop="test" /></parent>'
89
- end
90
-
91
- it "should deserialize anonymous objects" do
92
- input = object_fixture('amf0-object.bin')
93
- output = RocketAMF.deserialize(input, 0)
94
- output.should == {'foo' => 'baz', 'bar' => 3.14}
95
- output.type.should == ""
96
- end
97
-
98
- it "should deserialize an unmapped object as a dynamic anonymous object" do
99
- input = object_fixture("amf0-typed-object.bin")
100
- output = RocketAMF.deserialize(input, 0)
101
-
102
- output.type.should == 'org.amf.ASClass'
103
- output.should == {'foo' => 'bar', 'baz' => nil}
104
- end
105
-
106
- it "should deserialize a mapped object as a mapped ruby class instance" do
107
- RocketAMF::ClassMapper.define {|m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass'}
108
-
109
- input = object_fixture("amf0-typed-object.bin")
110
- output = RocketAMF.deserialize(input, 0)
111
-
112
- output.should be_a(RubyClass)
113
- output.foo.should == 'bar'
114
- output.baz.should == nil
115
- end
10
+ describe 'AMF3' do
11
+ it 'should update source pos if source is a StringIO object' do
12
+ input = StringIO.new(object_fixture('amf3-null.bin'))
13
+ expect(input.pos).to eq(0)
116
14
 
117
- it "should deserialize references properly" do
118
- input = object_fixture('amf0-ref-test.bin')
119
- output = RocketAMF.deserialize(input, 0)
120
- output.length.should == 2
121
- output["0"].should === output["1"]
122
- end
123
- end
15
+ RocketAMF.deserialize(input)
124
16
 
125
- describe "AMF3" do
126
- it "should update source pos if source is a StringIO object" do
127
- input = StringIO.new(object_fixture('amf3-null.bin'))
128
- input.pos.should == 0
129
- output = RocketAMF.deserialize(input, 3)
130
- input.pos.should == 1
17
+ expect(input.pos).to eq(1)
131
18
  end
132
19
 
133
- describe "simple messages" do
134
- it "should deserialize a null" do
135
- input = object_fixture("amf3-null.bin")
136
- output = RocketAMF.deserialize(input, 3)
137
- output.should == nil
20
+ describe 'simple messages' do
21
+ it 'should deserialize a null' do
22
+ first_request_eq('amf3-null.bin', nil)
138
23
  end
139
24
 
140
- it "should deserialize a false" do
141
- input = object_fixture("amf3-false.bin")
142
- output = RocketAMF.deserialize(input, 3)
143
- output.should == false
25
+ it 'should deserialize a false' do
26
+ first_request_eq('amf3-false.bin', false)
144
27
  end
145
28
 
146
- it "should deserialize a true" do
147
- input = object_fixture("amf3-true.bin")
148
- output = RocketAMF.deserialize(input, 3)
149
- output.should == true
29
+ it 'should deserialize a true' do
30
+ first_request_eq('amf3-true.bin', true)
150
31
  end
151
32
 
152
- it "should deserialize integers" do
153
- input = object_fixture("amf3-max.bin")
154
- output = RocketAMF.deserialize(input, 3)
155
- output.should == RocketAMF::MAX_INTEGER
156
-
157
- input = object_fixture("amf3-0.bin")
158
- output = RocketAMF.deserialize(input, 3)
159
- output.should == 0
160
-
161
- input = object_fixture("amf3-min.bin")
162
- output = RocketAMF.deserialize(input, 3)
163
- output.should == RocketAMF::MIN_INTEGER
33
+ it 'should deserialize integers' do
34
+ first_request_eq('amf3-max.bin', RocketAMF::MAX_INTEGER)
35
+ first_request_eq('amf3-0.bin', 0)
36
+ first_request_eq('amf3-min.bin', RocketAMF::MIN_INTEGER)
164
37
  end
165
38
 
166
- it "should deserialize large integers" do
167
- input = object_fixture("amf3-large-max.bin")
168
- output = RocketAMF.deserialize(input, 3)
169
- output.should == RocketAMF::MAX_INTEGER + 1
170
-
171
- input = object_fixture("amf3-large-min.bin")
172
- output = RocketAMF.deserialize(input, 3)
173
- output.should == RocketAMF::MIN_INTEGER - 1
39
+ it 'should deserialize large integers' do
40
+ first_request_eq('amf3-large-max.bin', RocketAMF::MAX_INTEGER + 1.0)
41
+ first_request_eq('amf3-large-min.bin', RocketAMF::MIN_INTEGER - 1.0)
174
42
  end
175
43
 
176
- it "should deserialize BigNums" do
177
- input = object_fixture("amf3-bignum.bin")
178
- output = RocketAMF.deserialize(input, 3)
179
- output.should == 2**1000
44
+ it 'should deserialize BigNums' do
45
+ first_request_eq('amf3-bignum.bin', 2.0**1000)
180
46
  end
181
47
 
182
- it "should deserialize a simple string" do
183
- input = object_fixture("amf3-string.bin")
184
- output = RocketAMF.deserialize(input, 3)
185
- output.should == "String . String"
48
+ it 'should deserialize a simple string' do
49
+ first_request_eq('amf3-string.bin', 'String . String')
186
50
  end
187
51
 
188
- it "should deserialize a symbol as a string" do
189
- input = object_fixture("amf3-symbol.bin")
190
- output = RocketAMF.deserialize(input, 3)
191
- output.should == "foo"
52
+ it 'should deserialize a symbol as a string' do
53
+ first_request_eq('amf3-symbol.bin', 'foo')
192
54
  end
193
55
 
194
- it "should deserialize dates" do
195
- input = object_fixture("amf3-date.bin")
196
- output = RocketAMF.deserialize(input, 3)
197
- output.should == Time.at(0)
56
+ it 'should deserialize dates' do
57
+ first_request_eq('amf3-date.bin', Time.at(0))
198
58
  end
199
59
 
200
- it "should deserialize XML" do
60
+ it 'should deserialize XML' do
201
61
  # XMLDocument tag
202
- input = object_fixture("amf3-xml-doc.bin")
203
- output = RocketAMF.deserialize(input, 3)
204
- output.should == '<parent><child prop="test" /></parent>'
62
+ first_request_eq('amf3-xml-doc.bin', '<parent><child prop="test" /></parent>')
205
63
 
206
64
  # XML tag
207
- input = object_fixture("amf3-xml.bin")
208
- output = RocketAMF.deserialize(input, 3)
209
- output.should == '<parent><child prop="test"/></parent>'
65
+ first_request_eq('amf3-xml.bin', '<parent><child prop="test"/></parent>')
210
66
  end
211
67
  end
212
68
 
213
- describe "objects" do
214
- it "should deserialize an unmapped object as a dynamic anonymous object" do
215
- input = object_fixture("amf3-dynamic-object.bin")
216
- output = RocketAMF.deserialize(input, 3)
69
+ describe 'objects' do
70
+ it 'should deserialize an unmapped object as a dynamic anonymous object' do
71
+
72
+ value =
73
+ {
74
+ 'property_one' => 'foo',
75
+ 'nil_property' => nil,
76
+ 'another_public_property' => 'a_public_value'
77
+ }
217
78
 
218
- expected = {
219
- 'property_one' => 'foo',
220
- 'nil_property' => nil,
221
- 'another_public_property' => 'a_public_value'
222
- }
223
- output.should == expected
224
- output.type.should == ""
79
+ request = get_first_request('amf3-dynamic-object.bin')
80
+
81
+ expect(request).to match(value)
82
+ expect(request.type).to eq('')
225
83
  end
226
84
 
227
- it "should deserialize a mapped object as a mapped ruby class instance" do
228
- RocketAMF::ClassMapper.define {|m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass'}
85
+ it 'should deserialize a mapped object as a mapped ruby class instance' do
86
+ RocketAMF::CLASS_MAPPER.define { |m| m.map :as => 'org.amf.ASClass', ruby: 'RubyClass' }
229
87
 
230
- input = object_fixture("amf3-typed-object.bin")
231
- output = RocketAMF.deserialize(input, 3)
88
+ request = get_first_request('amf3-typed-object.bin')
232
89
 
233
- output.should be_a(RubyClass)
234
- output.foo.should == 'bar'
235
- output.baz.should == nil
90
+ expect(request).to be_a(RubyClass)
91
+ expect(request.foo).to eq('bar')
92
+ expect(request.baz).to eq(nil)
236
93
  end
237
94
 
238
- it "should deserialize externalizable objects" do
239
- RocketAMF::ClassMapper.define {|m| m.map :as => 'ExternalizableTest', :ruby => 'ExternalizableTest'}
95
+ it 'should deserialize externalizable objects' do
96
+ RocketAMF::CLASS_MAPPER.define { |m| m.map :as => 'ExternalizableTest', ruby: 'ExternalizableTest' }
240
97
 
241
- input = object_fixture("amf3-externalizable.bin")
242
- output = RocketAMF.deserialize(input, 3)
98
+ request = get_first_request('amf3-externalizable.bin')
243
99
 
244
- output.length.should == 2
245
- output[0].one.should == 5
246
- output[1].two.should == 5
100
+ expect(request.length).to eq(2)
101
+ expect(request[0].one).to eq(5)
102
+ expect(request[1].two).to eq(5)
247
103
  end
248
104
 
249
- it "should deserialize a hash as a dynamic anonymous object" do
250
- input = object_fixture("amf3-hash.bin")
251
- output = RocketAMF.deserialize(input, 3)
252
- output.should == {'foo' => "bar", 'answer' => 42}
105
+ it 'should deserialize a hash as a dynamic anonymous object' do
106
+ first_request_eq('amf3-hash.bin', {'foo' => 'bar', 'answer' => 42})
253
107
  end
254
108
 
255
- it "should deserialize an empty array" do
256
- input = object_fixture("amf3-empty-array.bin")
257
- output = RocketAMF.deserialize(input, 3)
258
- output.should == []
109
+ it 'should deserialize an empty array' do
110
+ request = get_first_request('amf3-empty-array.bin')
111
+ expect(request).to match_array([])
259
112
  end
260
113
 
261
- it "should deserialize an array of primitives" do
262
- input = object_fixture("amf3-primitive-array.bin")
263
- output = RocketAMF.deserialize(input, 3)
264
- output.should == [1,2,3,4,5]
114
+ it 'should deserialize an array of primitives' do
115
+ request = get_first_request('amf3-primitive-array.bin')
116
+ expect(request).to match_array([1, 2, 3, 4, 5])
265
117
  end
266
118
 
267
- it "should deserialize an associative array" do
268
- input = object_fixture("amf3-associative-array.bin")
269
- output = RocketAMF.deserialize(input, 3)
270
- output.should == {0=>"bar1", 1=>"bar2", 2=>"bar3", "asdf"=>"fdsa", "foo"=>"bar", "42"=>"bar"}
119
+ it 'should deserialize an associative array' do
120
+ request = get_first_request('amf3-associative-array.bin')
121
+ expect(request).to match({0 => 'bar1', 1 => 'bar2', 2 => 'bar3', 'asdf' => 'fdsa', 'foo' => 'bar', '42' => 'bar'})
271
122
  end
272
123
 
273
- it "should deserialize an array of mixed objects" do
274
- input = object_fixture("amf3-mixed-array.bin")
275
- output = RocketAMF.deserialize(input, 3)
124
+ it 'should deserialize an array of mixed objects' do
125
+ request = get_first_request('amf3-mixed-array.bin')
276
126
 
277
- h1 = {'foo_one' => "bar_one"}
278
- h2 = {'foo_two' => ""}
127
+ h1 = {'foo_one' => 'bar_one'}
128
+ h2 = {'foo_two' => ''}
279
129
  so1 = {'foo_three' => 42}
280
- output.should == [h1, h2, so1, {}, [h1, h2, so1], [], 42, "", [], "", {}, "bar_one", so1]
130
+ expect(request).to match_array([h1, h2, so1, {}, [h1, h2, so1], [], 42, '', [], '', {}, 'bar_one', so1])
281
131
  end
282
132
 
283
- it "should deserialize an array collection as an array" do
284
- input = object_fixture("amf3-array-collection.bin")
285
- output = RocketAMF.deserialize(input, 3)
133
+ it 'should deserialize an array collection as an array' do
134
+ request = get_first_request('amf3-array-collection.bin')
286
135
 
287
- output.class.should == Array
288
- output.should == ["foo", "bar"]
136
+ expect(request.class).to eq(Array)
137
+ expect(request).to match_array(%w( foo bar ))
289
138
  end
290
139
 
291
- it "should deserialize a complex set of array collections" do
292
- RocketAMF::ClassMapper.define {|m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass'}
293
- input = object_fixture('amf3-complex-array-collection.bin')
140
+ it 'should deserialize a complex set of array collections' do
141
+ RocketAMF::CLASS_MAPPER.define { |m| m.map :as => 'org.amf.ASClass', ruby: 'RubyClass' }
294
142
 
295
- output = RocketAMF.deserialize(input, 3)
143
+ request = get_first_request('amf3-complex-array-collection.bin')
296
144
 
297
- output[0].should == ["foo", "bar"]
298
- output[1][0].should be_a(RubyClass)
299
- output[1][1].should be_a(RubyClass)
300
- output[2].should === output[1]
145
+ expect(request[0]).to match_array(%w( foo bar ))
146
+ expect(request[1][0]).to be_a(RubyClass)
147
+ expect(request[1][1]).to be_a(RubyClass)
148
+ expect(request[2]).to eq(request[1])
301
149
  end
302
150
 
303
- it "should deserialize a byte array" do
304
- input = object_fixture("amf3-byte-array.bin")
305
- output = RocketAMF.deserialize(input, 3)
151
+ it 'should deserialize a byte array' do
152
+ request = get_first_request('amf3-byte-array.bin')
306
153
 
307
- output.should be_a(StringIO)
154
+ expect(request).to be_a(StringIO)
308
155
  expected = "\000\003これtest\100"
309
- expected.force_encoding("ASCII-8BIT") if expected.respond_to?(:force_encoding)
310
- output.string.should == expected
156
+ expected.force_encoding('ASCII-8BIT') if expected.respond_to?(:force_encoding)
157
+ expect(request.string).to eq(expected)
311
158
  end
312
159
 
313
- it "should deserialize an empty dictionary" do
314
- input = object_fixture("amf3-empty-dictionary.bin")
315
- output = RocketAMF.deserialize(input, 3)
316
- output.should == {}
160
+ it 'should deserialize an empty dictionary' do
161
+ request = get_first_request('amf3-empty-dictionary.bin')
162
+ expect(request).to match({})
317
163
  end
318
164
 
319
- it "should deserialize a dictionary" do
320
- input = object_fixture("amf3-dictionary.bin")
321
- output = RocketAMF.deserialize(input, 3)
165
+ it 'should deserialize a dictionary' do
166
+ request = get_first_request('amf3-dictionary.bin')
167
+
168
+ keys = request.keys
169
+ expect(keys.length).to eq(2)
170
+ obj_key, str_key = keys[0].is_a?(RocketAMF::Types::TypedHash) ? [keys[0], keys[1]] : [keys[1], keys[0]]
322
171
 
323
- keys = output.keys
324
- keys.length.should == 2
325
- obj_key, str_key = keys[0].is_a?(RocketAMF::Values::TypedHash) ? [keys[0], keys[1]] : [keys[1], keys[0]]
326
- obj_key.type.should == 'org.amf.ASClass'
327
- output[obj_key].should == "asdf2"
328
- str_key.should == "bar"
329
- output[str_key].should == "asdf1"
172
+ expect(obj_key.type).to eq('org.amf.ASClass')
173
+ expect(request[obj_key]).to eq('asdf2')
174
+ expect(str_key).to eq('bar')
175
+ expect(request[str_key]).to eq('asdf1')
330
176
  end
331
177
 
332
- it "should deserialize Vector.<int>" do
333
- input = object_fixture('amf3-vector-int.bin')
334
- output = RocketAMF.deserialize(input, 3)
335
- output.should == [4, -20, 12]
178
+ it 'should deserialize Vector.<int>' do
179
+ request = get_first_request('amf3-vector-int.bin')
180
+ expect(request).to match_array([4, -20, 12])
336
181
  end
337
182
 
338
- it "should deserialize Vector.<uint>" do
339
- input = object_fixture('amf3-vector-uint.bin')
340
- output = RocketAMF.deserialize(input, 3)
341
- output.should == [4, 20, 12]
183
+ it 'should deserialize Vector.<uint>' do
184
+ request = get_first_request('amf3-vector-uint.bin')
185
+ expect(request).to match_array([4, 20, 12])
342
186
  end
343
187
 
344
- it "should deserialize Vector.<Number>" do
345
- input = object_fixture('amf3-vector-double.bin')
346
- output = RocketAMF.deserialize(input, 3)
347
- output.should == [4.3, -20.6]
188
+ it 'should deserialize Vector.<Number>' do
189
+ output = get_first_request('amf3-vector-double.bin')
190
+ expect(output).to match_array([4.3, -20.6])
348
191
  end
349
192
 
350
- it "should deserialize Vector.<Object>" do
351
- input = object_fixture('amf3-vector-object.bin')
352
- output = RocketAMF.deserialize(input, 3)
353
- output[0]['foo'].should == 'foo'
354
- output[1].type.should == 'org.amf.ASClass'
355
- output[2]['foo'].should == 'baz'
193
+ it 'should deserialize Vector.<Object>' do
194
+ output = get_first_request('amf3-vector-object.bin')
195
+
196
+ expect(output[0]['foo']).to eq('foo')
197
+ expect(output[1].type).to eq('org.amf.ASClass')
198
+ expect(output[2]['foo']).to eq('baz')
356
199
  end
357
200
  end
358
201
 
359
- describe "and implementing the AMF Spec" do
360
- it "should keep references of duplicate strings" do
361
- input = object_fixture("amf3-string-ref.bin")
362
- output = RocketAMF.deserialize(input, 3)
202
+ describe 'and implementing the AMF Spec' do
203
+ it 'should keep references of duplicate strings' do
204
+ output = get_first_request('amf3-string-ref.bin')
363
205
 
364
- foo = "foo"
365
- bar = "str"
366
- output.should == [foo, bar, foo, bar, foo, {'str' => "foo"}]
206
+ foo = 'foo'
207
+ bar = 'str'
208
+ expect(output).to match_array([foo, bar, foo, bar, foo, {'str' => 'foo'}])
367
209
  end
368
210
 
369
- it "should not reference the empty string" do
370
- input = object_fixture("amf3-empty-string-ref.bin")
371
- output = RocketAMF.deserialize(input, 3)
372
- output.should == ["",""]
211
+ it 'should not reference the empty string' do
212
+ output = get_first_request('amf3-empty-string-ref.bin')
213
+ expect(output).to match_array(['', ''])
373
214
  end
374
215
 
375
- it "should keep references of duplicate dates" do
376
- input = object_fixture("amf3-date-ref.bin")
377
- output = RocketAMF.deserialize(input, 3)
216
+ it 'should keep references of duplicate dates' do
217
+ output = get_first_request('amf3-date-ref.bin')
378
218
 
379
- output[0].should == Time.at(0)
380
- output[0].should equal(output[1])
219
+ expect(output[0]).to eq(Time.at(0))
220
+ expect(output[0]).to eq(output[1])
381
221
  # Expected object:
382
- # [DateTime.parse "1/1/1970", DateTime.parse "1/1/1970"]
222
+ # [DateTime.parse '1/1/1970', DateTime.parse '1/1/1970']
383
223
  end
384
224
 
385
- it "should keep reference of duplicate objects" do
386
- input = object_fixture("amf3-object-ref.bin")
387
- output = RocketAMF.deserialize(input, 3)
225
+ it 'should keep reference of duplicate objects' do
226
+ output = get_first_request('amf3-object-ref.bin')
388
227
 
389
- obj1 = {'foo' => "bar"}
228
+ obj1 = {'foo' => 'bar'}
390
229
  obj2 = {'foo' => obj1['foo']}
391
- output.should == [[obj1, obj2], "bar", [obj1, obj2]]
230
+
231
+ expect(output).to match_array([[obj1, obj2], 'bar', [obj1, obj2]])
392
232
  end
393
233
 
394
- it "should keep reference of duplicate object traits" do
395
- RocketAMF::ClassMapper.define {|m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass'}
234
+ it 'should keep reference of duplicate object traits' do
235
+ RocketAMF::CLASS_MAPPER.define { |m| m.map :as => 'org.amf.ASClass', ruby: 'RubyClass' }
396
236
 
397
- input = object_fixture("amf3-trait-ref.bin")
398
- output = RocketAMF.deserialize(input, 3)
237
+ output = get_first_request('amf3-trait-ref.bin')
399
238
 
400
- output[0].foo.should == "foo"
401
- output[1].foo.should == "bar"
239
+ expect(output[0].foo).to eq('foo')
240
+ expect(output[1].foo).to eq('bar')
402
241
  end
403
242
 
404
- it "should keep references of duplicate arrays" do
405
- input = object_fixture("amf3-array-ref.bin")
406
- output = RocketAMF.deserialize(input, 3)
243
+ it 'should keep references of duplicate arrays' do
244
+ output = get_first_request('amf3-array-ref.bin')
407
245
 
408
- a = [1,2,3]
246
+ a = [1, 2, 3]
409
247
  b = %w{ a b c }
410
- output.should == [a, b, a, b]
248
+ expect(output).to match_array([a, b, a, b])
411
249
  end
412
250
 
413
- it "should not keep references of duplicate empty arrays unless the object_id matches" do
414
- input = object_fixture("amf3-empty-array-ref.bin")
415
- output = RocketAMF.deserialize(input, 3)
251
+ it 'should not keep references of duplicate empty arrays unless the object_id matches' do
252
+ output = get_first_request('amf3-empty-array-ref.bin')
416
253
 
417
254
  a = []
418
255
  b = []
419
- output.should == [a,b,a,b]
256
+ expect(output).to match_array([a, b, a, b])
420
257
  end
421
258
 
422
- it "should keep references of duplicate XML and XMLDocuments" do
423
- input = object_fixture("amf3-xml-ref.bin")
424
- output = RocketAMF.deserialize(input, 3)
425
- output.should == ['<parent><child prop="test"/></parent>', '<parent><child prop="test"/></parent>']
259
+ it 'should keep references of duplicate XML and XMLDocuments' do
260
+ request = get_first_request('amf3-xml-ref.bin')
261
+ expect(request).to match_array(['<parent><child prop="test"/></parent>', '<parent><child prop="test"/></parent>'])
426
262
  end
427
263
 
428
- it "should keep references of duplicate byte arrays" do
429
- input = object_fixture("amf3-byte-array-ref.bin")
430
- output = RocketAMF.deserialize(input, 3)
431
- output[0].object_id.should == output[1].object_id
432
- output[0].string.should == "ASDF"
264
+ it 'should keep references of duplicate byte arrays' do
265
+ output = get_first_request('amf3-byte-array-ref.bin')
266
+
267
+ expect(output[0].object_id).to eq(output[1].object_id)
268
+ expect(output[0].string).to eq('ASDF')
433
269
  end
434
270
 
435
- it "should deserialize a deep object graph with circular references" do
436
- input = object_fixture("amf3-graph-member.bin")
437
- output = RocketAMF.deserialize(input, 3)
271
+ it 'should deserialize a deep object graph with circular references' do
272
+
273
+ output = get_first_request('amf3-graph-member.bin')
438
274
 
439
- output['children'][0]['parent'].should === output
440
- output['parent'].should === nil
441
- output['children'].length.should == 2
275
+ expect(output['children'][0]['parent']).to eq(output)
276
+ expect(output['parent']).to eq(nil)
277
+ expect(output['children'].length).to eq(2)
442
278
  # Expected object:
443
279
  # parent = Hash.new
444
280
  # child1 = Hash.new