mrpin-rocketamf 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,116 +1,118 @@
1
- require "spec_helper.rb"
1
+ require 'spec_helper.rb'
2
2
 
3
3
  describe RocketAMF::Ext::FastClassMapping do
4
4
  before :each do
5
5
  RocketAMF::Ext::FastClassMapping.reset
6
6
  RocketAMF::Ext::FastClassMapping.define do |m|
7
- m.map :as => 'ASClass', :ruby => 'ClassMappingTest'
7
+ m.map :as => 'ASClass', ruby: 'ClassMappingTest'
8
8
  end
9
9
  @mapper = RocketAMF::Ext::FastClassMapping.new
10
10
  end
11
11
 
12
- describe "class name mapping" do
13
- it "should allow resetting of mappings back to defaults" do
12
+ describe 'class name mapping' do
13
+ it 'should allow resetting of mappings back to defaults' do
14
14
  @mapper.get_as_class_name('ClassMappingTest').should_not be_nil
15
15
  RocketAMF::Ext::FastClassMapping.reset
16
16
  @mapper = RocketAMF::Ext::FastClassMapping.new
17
17
  @mapper.get_as_class_name('ClassMappingTest').should be_nil
18
- @mapper.get_as_class_name('RocketAMF::Values::AcknowledgeMessage').should_not be_nil
18
+ @mapper.get_as_class_name('RocketAMF::Types::AcknowledgeMessage').should_not be_nil
19
19
  end
20
20
 
21
- it "should return AS class name for ruby objects" do
21
+ it 'should return AS class name for ruby objects' do
22
22
  @mapper.get_as_class_name(ClassMappingTest.new).should == 'ASClass'
23
23
  @mapper.get_as_class_name('ClassMappingTest').should == 'ASClass'
24
- @mapper.get_as_class_name(RocketAMF::Values::TypedHash.new('ClassMappingTest')).should == 'ASClass'
24
+ @mapper.get_as_class_name(RocketAMF::Types::TypedHash.new('ClassMappingTest')).should == 'ASClass'
25
25
  @mapper.get_as_class_name('BadClass').should be_nil
26
26
  end
27
27
 
28
- it "should instantiate a ruby class" do
28
+ it 'should instantiate a ruby class' do
29
29
  @mapper.get_ruby_obj('ASClass').should be_a(ClassMappingTest)
30
30
  end
31
31
 
32
- it "should properly instantiate namespaced classes" do
33
- RocketAMF::Ext::FastClassMapping.mappings.map :as => 'ASClass', :ruby => 'ANamespace::TestRubyClass'
32
+ it 'should properly instantiate namespaced classes' do
33
+ RocketAMF::Ext::FastClassMapping.mappings.map :as => 'ASClass', ruby: 'ANamespace::TestRubyClass'
34
34
  @mapper = RocketAMF::Ext::FastClassMapping.new
35
35
  @mapper.get_ruby_obj('ASClass').should be_a(ANamespace::TestRubyClass)
36
36
  end
37
37
 
38
- it "should return a hash with original type if not mapped" do
38
+ it 'should return a hash with original type if not mapped' do
39
39
  obj = @mapper.get_ruby_obj('UnmappedClass')
40
- obj.should be_a(RocketAMF::Values::TypedHash)
40
+ obj.should be_a(RocketAMF::Types::TypedHash)
41
41
  obj.type.should == 'UnmappedClass'
42
42
  end
43
43
 
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
- ]
44
+ it 'should map special classes from AS by default' do
45
+ as_classes =
46
+ %w(
47
+ flex.messaging.messages.AcknowledgeMessage
48
+ flex.messaging.messages.CommandMessage
49
+ flex.messaging.messages.RemotingMessage
50
+ )
50
51
 
51
52
  as_classes.each do |as_class|
52
- @mapper.get_ruby_obj(as_class).should_not be_a(RocketAMF::Values::TypedHash)
53
+ @mapper.get_ruby_obj(as_class).should_not be_a(RocketAMF::Types::TypedHash)
53
54
  end
54
55
  end
55
56
 
56
- it "should map special classes from ruby by default" do
57
- ruby_classes = [
58
- 'RocketAMF::Values::AcknowledgeMessage',
59
- 'RocketAMF::Values::ErrorMessage'
60
- ]
57
+ it 'should map special classes from ruby by default' do
58
+ ruby_classes =
59
+ %w(
60
+ RocketAMF::Types::AcknowledgeMessage
61
+ RocketAMF::Types::ErrorMessage
62
+ )
61
63
 
62
64
  ruby_classes.each do |obj|
63
65
  @mapper.get_as_class_name(obj).should_not be_nil
64
66
  end
65
67
  end
66
68
 
67
- it "should allow config modification" do
68
- RocketAMF::Ext::FastClassMapping.mappings.map :as => 'SecondClass', :ruby => 'ClassMappingTest'
69
+ it 'should allow config modification' do
70
+ RocketAMF::Ext::FastClassMapping.mappings.map :as => 'SecondClass', ruby: 'ClassMappingTest'
69
71
  @mapper = RocketAMF::Ext::FastClassMapping.new
70
72
  @mapper.get_as_class_name(ClassMappingTest.new).should == 'SecondClass'
71
73
  end
72
74
  end
73
75
 
74
- describe "ruby object populator" do
75
- it "should populate a ruby class" do
76
+ describe 'ruby object populator' do
77
+ it 'should populate a ruby class' do
76
78
  obj = @mapper.populate_ruby_obj ClassMappingTest.new, {:prop_a => 'Data'}
77
79
  obj.prop_a.should == 'Data'
78
80
  end
79
81
 
80
- it "should populate a typed hash" do
81
- obj = @mapper.populate_ruby_obj RocketAMF::Values::TypedHash.new('UnmappedClass'), {'prop_a' => 'Data'}
82
+ it 'should populate a typed hash' do
83
+ obj = @mapper.populate_ruby_obj RocketAMF::Types::TypedHash.new('UnmappedClass'), {'prop_a' => 'Data'}
82
84
  obj['prop_a'].should == 'Data'
83
85
  end
84
86
  end
85
87
 
86
- describe "property extractor" do
88
+ describe 'property extractor' do
87
89
  # Use symbol keys for properties in Ruby >1.9
88
90
  def prop_hash hash
89
91
  out = {}
90
92
  if RUBY_VERSION =~ /^1\.8/
91
- hash.each {|k,v| out[k.to_s] = v}
93
+ hash.each { |k, v| out[k.to_s] = v }
92
94
  else
93
- hash.each {|k,v| out[k.to_sym] = v}
95
+ hash.each { |k, v| out[k.to_sym] = v }
94
96
  end
95
97
  out
96
98
  end
97
99
 
98
- it "should return hash without modification" do
99
- hash = {:a => 'test1', 'b' => 'test2'}
100
+ it 'should return hash without modification' do
101
+ hash = {:a => 'test1', 'b' => 'test2'}
100
102
  props = @mapper.props_for_serialization(hash)
101
103
  props.should === hash
102
104
  end
103
105
 
104
- it "should extract object properties" do
105
- obj = ClassMappingTest.new
106
+ it 'should extract object properties' do
107
+ obj = ClassMappingTest.new
106
108
  obj.prop_a = 'Test A'
107
109
 
108
110
  hash = @mapper.props_for_serialization obj
109
111
  hash.should == prop_hash({'prop_a' => 'Test A', 'prop_b' => nil})
110
112
  end
111
113
 
112
- it "should extract inherited object properties" do
113
- obj = ClassMappingTest2.new
114
+ it 'should extract inherited object properties' do
115
+ obj = ClassMappingTest2.new
114
116
  obj.prop_a = 'Test A'
115
117
  obj.prop_c = 'Test C'
116
118
 
@@ -118,26 +120,30 @@ describe RocketAMF::Ext::FastClassMapping do
118
120
  hash.should == prop_hash({'prop_a' => 'Test A', 'prop_b' => nil, 'prop_c' => 'Test C'})
119
121
  end
120
122
 
121
- it "should cache property lookups by instance" do
122
- class ClassMappingTest3; attr_accessor :prop_a; end;
123
+ it 'should cache property lookups by instance' do
124
+ class ClassMappingTest3;
125
+ attr_accessor :prop_a;
126
+ end;
123
127
 
124
128
  # Cache properties
125
- obj = ClassMappingTest3.new
129
+ obj = ClassMappingTest3.new
126
130
  hash = @mapper.props_for_serialization obj
127
131
 
128
132
  # Add a method to ClassMappingTest3
129
- class ClassMappingTest3; attr_accessor :prop_b; end;
133
+ class ClassMappingTest3;
134
+ attr_accessor :prop_b;
135
+ end;
130
136
 
131
137
  # Test property list does not have new property
132
- obj = ClassMappingTest3.new
138
+ obj = ClassMappingTest3.new
133
139
  obj.prop_a = 'Test A'
134
140
  obj.prop_b = 'Test B'
135
- hash = @mapper.props_for_serialization obj
141
+ hash = @mapper.props_for_serialization obj
136
142
  hash.should == prop_hash({'prop_a' => 'Test A'})
137
143
 
138
144
  # Test that new class mapper *does* have new property (cache per instance)
139
145
  @mapper = RocketAMF::Ext::FastClassMapping.new
140
- hash = @mapper.props_for_serialization obj
146
+ hash = @mapper.props_for_serialization obj
141
147
  hash.should == prop_hash({'prop_a' => 'Test A', 'prop_b' => 'Test B'})
142
148
  end
143
149
  end
@@ -0,0 +1,4 @@
1
+ class ClassMappingTest
2
+ attr_accessor :prop_a
3
+ attr_accessor :prop_b
4
+ end
@@ -0,0 +1,3 @@
1
+ class ClassMappingTest2 < ClassMappingTest
2
+ attr_accessor :prop_c
3
+ end
@@ -0,0 +1,24 @@
1
+ class ExternalizableTest
2
+ include RocketAMF::Pure::IOHelperRead
3
+ include RocketAMF::Pure::IOHelperWrite
4
+
5
+ attr_accessor :one, :two
6
+
7
+ #
8
+ # Methods
9
+ #
10
+
11
+ def encode_amf(serializer)
12
+ serializer.write_object(self, nil, {class_name: 'ExternalizableTest', dynamic: false, externalizable: true, members: []})
13
+ end
14
+
15
+ def read_external(deserializer)
16
+ @one = read_double(deserializer.source)
17
+ @two = read_double(deserializer.source)
18
+ end
19
+
20
+ def write_external(serializer)
21
+ serializer.stream << pack_double(@one)
22
+ serializer.stream << pack_double(@two)
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ def request_fixture(binary_path)
2
+ data = File.open(File.dirname(__FILE__) + '/../fixtures/request/' + binary_path, 'rb').read
3
+ data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
4
+ data
5
+ end
6
+
7
+ def object_fixture(binary_path)
8
+ data = File.open(File.dirname(__FILE__) + '/../fixtures/objects/' + binary_path, 'rb').read
9
+ data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
10
+ data
11
+ end
12
+
13
+ def first_request_eq(object_fixture, value)
14
+ input = object_fixture(object_fixture)
15
+ output = RocketAMF.deserialize(input)
16
+
17
+ request = output[:requests][0]
18
+
19
+ expect(request).to eq(value)
20
+ end
21
+
22
+ def get_first_request(object_fixture)
23
+ input = object_fixture(object_fixture)
24
+ output = RocketAMF.deserialize(input)
25
+
26
+ requests = output[:requests]
27
+ requests[0]
28
+ end
@@ -0,0 +1,4 @@
1
+ class OtherClass;
2
+ attr_accessor :bar
3
+ attr_accessor :foo
4
+ end
@@ -0,0 +1,4 @@
1
+ class RubyClass;
2
+ attr_accessor :baz
3
+ attr_accessor :foo
4
+ end
@@ -0,0 +1,4 @@
1
+ module ANamespace
2
+ class TestRubyClass
3
+ end
4
+ end
@@ -1,229 +1,128 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "spec_helper.rb"
3
+ require 'spec_helper.rb'
4
4
  require 'rexml/document'
5
5
  require 'bigdecimal'
6
6
  require 'rational'
7
7
 
8
- describe "when serializing" do
8
+ describe 'when serializing' do
9
9
  before :each do
10
- RocketAMF::ClassMapper.reset
10
+ RocketAMF::CLASS_MAPPER.reset
11
11
  end
12
12
 
13
- it "should raise exception with invalid version number" do
14
- lambda {
15
- RocketAMF.serialize("", 5)
16
- }.should raise_error("unsupported version 5")
17
- end
18
-
19
- describe "AMF0" do
20
- it "should serialize nils" do
21
- output = RocketAMF.serialize(nil, 0)
22
- output.should == object_fixture('amf0-null.bin')
23
- end
24
-
25
- it "should serialize booleans" do
26
- output = RocketAMF.serialize(true, 0)
27
- output.should === object_fixture('amf0-boolean.bin')
28
- end
29
-
30
- it "should serialize numbers" do
31
- output = RocketAMF.serialize(3.5, 0)
32
- output.should == object_fixture('amf0-number.bin')
33
- end
34
-
35
- it "should serialize Numeric conformers" do
36
- output = RocketAMF.serialize(BigDecimal.new("3.5"), 0)
37
- output.should == object_fixture('amf0-number.bin')
38
- end
39
-
40
- it "should serialize strings" do
41
- output = RocketAMF.serialize("this is a テスト", 0)
42
- output.should == object_fixture('amf0-string.bin')
43
- end
44
-
45
- it "should serialize frozen strings" do
46
- output = RocketAMF.serialize("this is a テスト".freeze, 0)
47
- output.should == object_fixture('amf0-string.bin')
48
- end
49
-
50
- it "should serialize arrays" do
51
- output = RocketAMF.serialize(['a', 'b', 'c', 'd'], 0)
52
- output.should == object_fixture('amf0-strict-array.bin')
53
- end
54
-
55
- it "should serialize references" do
56
- obj = OtherClass.new
57
- obj.foo = "baz"
58
- obj.bar = 3.14
59
-
60
- output = RocketAMF.serialize({'0' => obj, '1' => obj}, 0)
61
- output.should == object_fixture('amf0-ref-test.bin')
62
- end
63
-
64
- it "should serialize Time objects" do
65
- output = RocketAMF.serialize(Time.utc(2003, 2, 13, 5), 0)
66
- output.bytesize.should == 11
67
- output[0,9].should == object_fixture('amf0-time.bin')[0,9] # Ignore TZ
68
- end
69
-
70
- it "should serialize Date objects" do
71
- output = RocketAMF.serialize(Date.civil(2020, 5, 30), 0)
72
- output.bytesize.should == 11
73
- output[0,9].should == object_fixture('amf0-date.bin')[0,9] # Ignore TZ
74
- end
75
-
76
- it "should serialize DateTime objects" do
77
- output = RocketAMF.serialize(DateTime.civil(2003, 2, 13, 5), 0)
78
- output.bytesize.should == 11
79
- output[0,9].should == object_fixture('amf0-time.bin')[0,9] # Ignore TZ
80
- end
81
-
82
- it "should serialize hashes as objects" do
83
- output = RocketAMF.serialize({:baz => nil, "foo" => "bar"}, 0)
84
- output.should == object_fixture('amf0-untyped-object.bin')
85
- end
86
-
87
- it "should serialize unmapped objects" do
88
- obj = RubyClass.new
89
- obj.foo = "bar"
90
-
91
- output = RocketAMF.serialize(obj, 0)
92
- output.should == object_fixture('amf0-untyped-object.bin')
93
- end
94
-
95
- it "should serialize mapped objects" do
96
- obj = RubyClass.new
97
- obj.foo = "bar"
98
- RocketAMF::ClassMapper.define {|m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass'}
99
-
100
- output = RocketAMF.serialize(obj, 0)
101
- output.should == object_fixture('amf0-typed-object.bin')
102
- end
103
-
104
- describe "and handling encodings", :if => "".respond_to?(:force_encoding) do
105
- it "should support multiple encodings" do
106
- shift_str = "\x53\x68\x69\x66\x74\x20\x83\x65\x83\x58\x83\x67".force_encoding("Shift_JIS") # "Shift テスト"
107
- utf_str = "\x55\x54\x46\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding("UTF-8") # "UTF テスト"
108
- output = RocketAMF.serialize({:shift => shift_str, :utf => utf_str, :zed => 5}, 0)
109
- output.should == object_fixture("amf0-complex-encoded-string.bin")
110
- end
111
- end
112
- end
113
-
114
- describe "AMF3" do
115
- describe "simple messages" do
116
- it "should serialize a null" do
117
- expected = object_fixture("amf3-null.bin")
118
- output = RocketAMF.serialize(nil, 3)
119
- output.should == expected
13
+ describe 'AMF3' do
14
+ describe 'simple messages' do
15
+ it 'should serialize a null' do
16
+ expected = object_fixture('amf3-null.bin')
17
+ output = RocketAMF.serialize(nil)
18
+ expect(output).to eq(expected)
120
19
  end
121
20
 
122
- it "should serialize a false" do
123
- expected = object_fixture("amf3-false.bin")
124
- output = RocketAMF.serialize(false, 3)
125
- output.should == expected
21
+ it 'should serialize a false' do
22
+ expected = object_fixture('amf3-false.bin')
23
+ output = RocketAMF.serialize(false)
24
+ expect(output).to eq(expected)
126
25
  end
127
26
 
128
- it "should serialize a true" do
129
- expected = object_fixture("amf3-true.bin")
130
- output = RocketAMF.serialize(true, 3)
131
- output.should == expected
27
+ it 'should serialize a true' do
28
+ expected = object_fixture('amf3-true.bin')
29
+ output = RocketAMF.serialize(true)
30
+ expect(output).to eq(expected)
132
31
  end
133
32
 
134
- it "should serialize integers" do
135
- expected = object_fixture("amf3-max.bin")
136
- input = RocketAMF::MAX_INTEGER
137
- output = RocketAMF.serialize(input, 3)
138
- output.should == expected
33
+ it 'should serialize integers' do
34
+ expected = object_fixture('amf3-max.bin')
35
+ input = RocketAMF::MAX_INTEGER
36
+ output = RocketAMF.serialize(input)
37
+ expect(output).to eq(expected)
139
38
 
140
- expected = object_fixture("amf3-0.bin")
141
- output = RocketAMF.serialize(0, 3)
142
- output.should == expected
39
+ expected = object_fixture('amf3-0.bin')
40
+ output = RocketAMF.serialize(0)
41
+ expect(output).to eq(expected)
143
42
 
144
- expected = object_fixture("amf3-min.bin")
145
- input = RocketAMF::MIN_INTEGER
146
- output = RocketAMF.serialize(input, 3)
147
- output.should == expected
43
+ expected = object_fixture('amf3-min.bin')
44
+ input = RocketAMF::MIN_INTEGER
45
+ output = RocketAMF.serialize(input)
46
+ expect(output).to eq(expected)
148
47
  end
149
48
 
150
- it "should serialize large integers" do
151
- expected = object_fixture("amf3-large-max.bin")
152
- input = RocketAMF::MAX_INTEGER + 1
153
- output = RocketAMF.serialize(input, 3)
154
- output.should == expected
49
+ it 'should serialize large integers' do
50
+ expected = object_fixture('amf3-large-max.bin')
51
+ input = RocketAMF::MAX_INTEGER + 1
52
+ output = RocketAMF.serialize(input)
53
+ expect(output).to eq(expected)
155
54
 
156
- expected = object_fixture("amf3-large-min.bin")
157
- input = RocketAMF::MIN_INTEGER - 1
158
- output = RocketAMF.serialize(input, 3)
159
- output.should == expected
55
+ expected = object_fixture('amf3-large-min.bin')
56
+ input = RocketAMF::MIN_INTEGER - 1
57
+ output = RocketAMF.serialize(input)
58
+ expect(output).to eq(expected)
160
59
  end
161
60
 
162
- it "should serialize floats" do
163
- expected = object_fixture("amf3-float.bin")
164
- input = 3.5
165
- output = RocketAMF.serialize(input, 3)
166
- output.should == expected
61
+ it 'should serialize floats' do
62
+ expected = object_fixture('amf3-float.bin')
63
+ input = 3.5
64
+ output = RocketAMF.serialize(input)
65
+ expect(output).to eq(expected)
167
66
  end
168
67
 
169
- it "should serialize BigNums" do
170
- expected = object_fixture("amf3-bigNum.bin")
171
- input = 2**1000
172
- output = RocketAMF.serialize(input, 3)
173
- output.should == expected
68
+ it 'should serialize BigNums' do
69
+ expected = object_fixture('amf3-bigNum.bin')
70
+ input = 2**1000
71
+ output = RocketAMF.serialize(input)
72
+ expect(output).to eq(expected)
174
73
  end
175
74
 
176
- it "should serialize float Numeric conformers" do
177
- expected = object_fixture("amf3-float.bin")
178
- input = Rational(7, 2) # 3.5
179
- output = RocketAMF.serialize(input, 3)
180
- output.should == expected
75
+ it 'should serialize float Numeric conformers' do
76
+ expected = object_fixture('amf3-float.bin')
77
+ input = Rational(7, 2) # 3.5
78
+ output = RocketAMF.serialize(input)
79
+ expect(output).to eq(expected)
181
80
  end
182
81
 
183
- it "should serialize a simple string" do
184
- expected = object_fixture("amf3-string.bin")
185
- input = "String . String"
186
- output = RocketAMF.serialize(input, 3)
187
- output.should == expected
82
+ it 'should serialize a simple string' do
83
+ expected = object_fixture('amf3-string.bin')
84
+ input = 'String . String'
85
+ output = RocketAMF.serialize(input)
86
+ expect(output).to eq(expected)
188
87
  end
189
88
 
190
- it "should serialize a frozen string" do
191
- expected = object_fixture("amf3-string.bin")
192
- input = "String . String".freeze
193
- output = RocketAMF.serialize(input, 3)
194
- output.should == expected
89
+ it 'should serialize a frozen string' do
90
+ expected = object_fixture('amf3-string.bin')
91
+ input = 'String . String'.freeze
92
+ output = RocketAMF.serialize(input)
93
+ expect(output).to eq(expected)
195
94
  end
196
95
 
197
- it "should serialize a symbol as a string" do
198
- expected = object_fixture("amf3-symbol.bin")
199
- output = RocketAMF.serialize(:foo, 3)
200
- output.should == expected
96
+ it 'should serialize a symbol as a string' do
97
+ expected = object_fixture('amf3-symbol.bin')
98
+ output = RocketAMF.serialize(:foo)
99
+ expect(output).to eq(expected)
201
100
  end
202
101
 
203
- it "should serialize Time objects" do
204
- expected = object_fixture("amf3-date.bin")
205
- input = Time.utc 1970, 1, 1, 0
206
- output = RocketAMF.serialize(input, 3)
207
- output.should == expected
102
+ it 'should serialize Time objects' do
103
+ expected = object_fixture('amf3-date.bin')
104
+ input = Time.utc 1970, 1, 1, 0
105
+ output = RocketAMF.serialize(input)
106
+ expect(output).to eq(expected)
208
107
  end
209
108
 
210
- it "should serialize Date objects" do
211
- expected = object_fixture("amf3-date.bin")
212
- input = Date.civil 1970, 1, 1, 0
213
- output = RocketAMF.serialize(input, 3)
214
- output.should == expected
109
+ it 'should serialize Date objects' do
110
+ expected = object_fixture('amf3-date.bin')
111
+ input = Date.civil 1970, 1, 1, 0
112
+ output = RocketAMF.serialize(input)
113
+ expect(output).to eq(expected)
215
114
  end
216
115
 
217
- it "should serialize DateTime objects" do
218
- expected = object_fixture("amf3-date.bin")
219
- input = DateTime.civil 1970, 1, 1, 0
220
- output = RocketAMF.serialize(input, 3)
221
- output.should == expected
116
+ it 'should serialize DateTime objects' do
117
+ expected = object_fixture('amf3-date.bin')
118
+ input = DateTime.civil 1970, 1, 1, 0
119
+ output = RocketAMF.serialize(input)
120
+ expect(output).to eq(expected)
222
121
  end
223
122
  end
224
123
 
225
- describe "objects" do
226
- it "should serialize an unmapped object as a dynamic anonymous object" do
124
+ describe 'objects' do
125
+ it 'should serialize an unmapped object as a dynamic anonymous object' do
227
126
  class NonMappedObject
228
127
  def another_public_property
229
128
  'a_public_value'
@@ -233,221 +132,229 @@ describe "when serializing" do
233
132
  attr_accessor :property_one
234
133
  attr_writer :read_only_prop
235
134
 
236
- def method_with_arg arg='foo'
135
+ def method_with_arg(arg = 'foo')
237
136
  arg
238
137
  end
239
138
  end
240
- obj = NonMappedObject.new
139
+ obj = NonMappedObject.new
241
140
  obj.property_one = 'foo'
242
141
  obj.nil_property = nil
243
142
 
244
- expected = object_fixture("amf3-dynamic-object.bin")
245
- input = obj
246
- output = RocketAMF.serialize(input, 3)
247
- output.should == expected
143
+ expected = object_fixture('amf3-dynamic-object.bin')
144
+ input = obj
145
+ output = RocketAMF.serialize(input)
146
+ expect(output).to eq(expected)
248
147
  end
249
148
 
250
- it "should serialize externalizable objects" do
251
- a = ExternalizableTest.new
149
+ it 'should serialize externalizable objects' do
150
+ a = ExternalizableTest.new
252
151
  a.one = 5
253
152
  a.two = 7
254
- b = ExternalizableTest.new
153
+ b = ExternalizableTest.new
255
154
  b.one = 13
256
155
  b.two = 5
257
- obj = [a, b]
156
+ obj = [a, b]
258
157
 
259
- expected = object_fixture("amf3-externalizable.bin")
260
- input = obj
261
- output = RocketAMF.serialize(input, 3)
262
- output.should == expected
158
+ expected = object_fixture('amf3-externalizable.bin')
159
+ input = obj
160
+ output = RocketAMF.serialize(input)
161
+ expect(output).to eq(expected)
263
162
  end
264
163
 
265
- it "should serialize a hash as a dynamic anonymous object" do
266
- hash = {}
164
+ it 'should serialize a hash as a dynamic anonymous object' do
165
+ hash = {}
267
166
  hash[:answer] = 42
268
- hash['foo'] = "bar"
167
+ hash['foo'] = 'bar'
269
168
 
270
- expected = object_fixture("amf3-hash.bin")
271
- input = hash
272
- output = RocketAMF.serialize(input, 3)
273
- output.should == expected
169
+ expected = object_fixture('amf3-hash.bin')
170
+ input = hash
171
+ output = RocketAMF.serialize(input)
172
+ expect(output).to eq(expected)
274
173
  end
275
174
 
276
- it "should serialize an empty array" do
277
- expected = object_fixture("amf3-empty-array.bin")
278
- input = []
279
- output = RocketAMF.serialize(input, 3)
280
- output.should == expected
175
+ it 'should serialize an empty array' do
176
+ expected = object_fixture('amf3-empty-array.bin')
177
+ input = []
178
+ output = RocketAMF.serialize(input)
179
+ expect(output).to eq(expected)
281
180
  end
282
181
 
283
- it "should serialize an array of primatives" do
284
- expected = object_fixture("amf3-primitive-array.bin")
285
- input = [1, 2, 3, 4, 5]
286
- output = RocketAMF.serialize(input, 3)
287
- output.should == expected
182
+ it 'should serialize an array of primatives' do
183
+ expected = object_fixture('amf3-primitive-array.bin')
184
+ input = [1, 2, 3, 4, 5]
185
+ output = RocketAMF.serialize(input)
186
+ expect(output).to eq(expected)
288
187
  end
289
188
 
290
- it "should serialize an array of mixed objects" do
291
- h1 = {:foo_one => "bar_one"}
292
- h2 = {:foo_two => ""}
189
+ it 'should serialize an array of mixed objects' do
190
+ h1 = {:foo_one => 'bar_one'}
191
+ h2 = {:foo_two => ''}
293
192
  class SimpleObj
294
193
  attr_accessor :foo_three
295
194
  end
296
- so1 = SimpleObj.new
195
+ so1 = SimpleObj.new
297
196
  so1.foo_three = 42
298
197
 
299
- expected = object_fixture("amf3-mixed-array.bin")
300
- input = [h1, h2, so1, {}, [h1, h2, so1], [], 42, "", [], "", {}, "bar_one", so1]
301
- output = RocketAMF.serialize(input, 3)
302
- output.should == expected
198
+ expected = object_fixture('amf3-mixed-array.bin')
199
+ input = [h1, h2, so1, {}, [h1, h2, so1], [], 42, '', [], '', {}, 'bar_one', so1]
200
+ output = RocketAMF.serialize(input)
201
+ expect(output).to eq(expected)
303
202
  end
304
203
 
305
- it "should serialize an array as an array collection" do
306
- expected = object_fixture('amf3-array-collection.bin')
204
+ it 'should serialize an array as an array collection' do
205
+ expected = object_fixture('amf3-array-collection.bin')
307
206
 
308
207
  # Test global
309
- RocketAMF::ClassMapper.use_array_collection = true
310
- input = ["foo", "bar"]
311
- output = RocketAMF.serialize(input, 3)
312
- output.should == expected
313
- RocketAMF::ClassMapper.use_array_collection = false
208
+ RocketAMF::CLASS_MAPPER.use_array_collection = true
209
+ input = %w( foo bar )
210
+ output = RocketAMF.serialize(input)
211
+ expect(output).to eq(expected)
212
+ RocketAMF::CLASS_MAPPER.use_array_collection = false
314
213
 
315
214
  # Test override
316
- input = ["foo", "bar"]
317
- input.is_array_collection = true
318
- output = RocketAMF.serialize(input, 3)
319
- output.should == expected
215
+ input = %w( foo bar )
216
+ input.is_array_collection = true
217
+ output = RocketAMF.serialize(input)
218
+ expect(output).to eq(expected)
320
219
  end
321
220
 
322
- it "should serialize a complex set of array collections" do
323
- RocketAMF::ClassMapper.define {|m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass'}
221
+ it 'should serialize a complex set of array collections' do
222
+ RocketAMF::CLASS_MAPPER.define { |m| m.map :as => 'org.amf.ASClass', :ruby => 'RubyClass' }
324
223
  expected = object_fixture('amf3-complex-array-collection.bin')
325
224
 
326
- a = ["foo", "bar"]
225
+ a = %w(foo bar)
327
226
  a.is_array_collection = true
328
- obj1 = RubyClass.new
329
- obj1.foo = "bar"
330
- def obj1.encode_amf serializer
331
- serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => ["baz", "foo"]})
227
+ obj1 = RubyClass.new
228
+ obj1.foo = 'bar'
229
+
230
+ def obj1.encode_amf(serializer)
231
+ serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, members: %w( baz foo )})
332
232
  end
333
- obj2 = RubyClass.new
334
- obj2.foo = "asdf"
335
- def obj2.encode_amf serializer
336
- serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => ["baz", "foo"]})
233
+
234
+ obj2 = RubyClass.new
235
+ obj2.foo = 'asdf'
236
+
237
+ def obj2.encode_amf(serializer)
238
+ serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, members: %w( baz foo )})
337
239
  end
338
- b = [obj1, obj2]
240
+
241
+ b = [obj1, obj2]
339
242
  b.is_array_collection = true
340
- input = [a, b, b]
243
+ input = [a, b, b]
341
244
 
342
- output = RocketAMF.serialize(input, 3)
343
- output.should == expected
245
+ output = RocketAMF.serialize(input)
246
+ expect(output).to eq(expected)
344
247
  end
345
248
 
346
- it "should serialize a byte array" do
347
- expected = object_fixture("amf3-byte-array.bin")
348
- str = "\000\003これtest\100"
349
- str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
350
- input = StringIO.new(str)
351
- output = RocketAMF.serialize(input, 3)
352
- output.should == expected
249
+ it 'should serialize a byte array' do
250
+ expected = object_fixture('amf3-byte-array.bin')
251
+ str = "\000\003これtest\100"
252
+ str.force_encoding('ASCII-8BIT') if str.respond_to?(:force_encoding)
253
+ input = StringIO.new(str)
254
+ output = RocketAMF.serialize(input)
255
+ expect(output).to eq(expected)
353
256
  end
354
257
  end
355
258
 
356
- describe "and implementing the AMF Spec" do
357
- it "should keep references of duplicate strings" do
259
+ describe 'and implementing the AMF Spec' do
260
+ it 'should keep references of duplicate strings' do
358
261
  class StringCarrier
359
262
  attr_accessor :str
360
263
  end
361
- foo = "foo"
362
- bar = "str"
363
- sc = StringCarrier.new
264
+ foo = 'foo'
265
+ bar = 'str'
266
+ sc = StringCarrier.new
364
267
  sc.str = foo
365
268
 
366
- expected = object_fixture("amf3-string-ref.bin")
367
- input = [foo, bar, foo, bar, foo, sc]
368
- output = RocketAMF.serialize(input, 3)
369
- output.should == expected
269
+ expected = object_fixture('amf3-string-ref.bin')
270
+ input = [foo, bar, foo, bar, foo, sc]
271
+ output = RocketAMF.serialize(input)
272
+ expect(output).to eq(expected)
370
273
  end
371
274
 
372
- it "should not reference the empty string" do
373
- expected = object_fixture("amf3-empty-string-ref.bin")
374
- input = ""
375
- output = RocketAMF.serialize([input,input], 3)
376
- output.should == expected
275
+ it 'should not reference the empty string' do
276
+ expected = object_fixture('amf3-empty-string-ref.bin')
277
+ input = ''
278
+ output = RocketAMF.serialize([input, input])
279
+ expect(output).to eq(expected)
377
280
  end
378
281
 
379
- it "should keep references of duplicate dates" do
380
- expected = object_fixture("amf3-date-ref.bin")
381
- input = Time.utc 1970, 1, 1, 0
382
- output = RocketAMF.serialize([input,input], 3)
383
- output.should == expected
282
+ it 'should keep references of duplicate dates' do
283
+ expected = object_fixture('amf3-date-ref.bin')
284
+ input = Time.utc 1970, 1, 1, 0
285
+ output = RocketAMF.serialize([input, input])
286
+ expect(output).to eq(expected)
384
287
  end
385
288
 
386
- it "should keep reference of duplicate objects" do
289
+ it 'should keep reference of duplicate objects' do
387
290
  class SimpleReferenceableObj
388
291
  attr_accessor :foo
389
292
  end
390
- obj1 = SimpleReferenceableObj.new
293
+ obj1 = SimpleReferenceableObj.new
391
294
  obj1.foo = :bar
392
- obj2 = SimpleReferenceableObj.new
295
+ obj2 = SimpleReferenceableObj.new
393
296
  obj2.foo = obj1.foo
394
297
 
395
- expected = object_fixture("amf3-object-ref.bin")
396
- input = [[obj1, obj2], "bar", [obj1, obj2]]
397
- output = RocketAMF.serialize(input, 3)
398
- output.should == expected
298
+ expected = object_fixture('amf3-object-ref.bin')
299
+ input = [[obj1, obj2], 'bar', [obj1, obj2]]
300
+ output = RocketAMF.serialize(input)
301
+ expect(output).to eq(expected)
399
302
  end
400
303
 
401
- it "should keep reference of duplicate object traits" do
402
- obj1 = RubyClass.new
403
- obj1.foo = "foo"
404
- def obj1.encode_amf serializer
405
- serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => ["baz", "foo"]})
304
+ it 'should keep reference of duplicate object traits' do
305
+ obj1 = RubyClass.new
306
+ obj1.foo = 'foo'
307
+
308
+ def obj1.encode_amf(serializer)
309
+ serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => %w( baz foo )})
406
310
  end
407
- obj2 = RubyClass.new
408
- obj2.foo = "bar"
409
- def obj2.encode_amf serializer
410
- serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => ["baz", "foo"]})
311
+
312
+ obj2 = RubyClass.new
313
+ obj2.foo = 'bar'
314
+
315
+ def obj2.encode_amf(serializer)
316
+ serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => %w( baz foo )})
411
317
  end
318
+
412
319
  input = [obj1, obj2]
413
320
 
414
- expected = object_fixture("amf3-trait-ref.bin")
415
- output = RocketAMF.serialize(input, 3)
416
- output.should == expected
321
+ expected = object_fixture('amf3-trait-ref.bin')
322
+ output = RocketAMF.serialize(input)
323
+ expect(output).to eq(expected)
417
324
  end
418
325
 
419
- it "should keep references of duplicate arrays" do
420
- a = [1,2,3]
326
+ it 'should keep references of duplicate arrays' do
327
+ a = [1, 2, 3]
421
328
  b = %w{ a b c }
422
329
 
423
- expected = object_fixture("amf3-array-ref.bin")
424
- input = [a, b, a, b]
425
- output = RocketAMF.serialize(input, 3)
426
- output.should == expected
330
+ expected = object_fixture('amf3-array-ref.bin')
331
+ input = [a, b, a, b]
332
+ output = RocketAMF.serialize(input)
333
+ expect(output).to eq(expected)
427
334
  end
428
335
 
429
- it "should not keep references of duplicate empty arrays unless the object_id matches" do
336
+ it 'should not keep references of duplicate empty arrays unless the object_id matches' do
430
337
  a = []
431
338
  b = []
432
- a.should == b
433
- a.object_id.should_not == b.object_id
339
+ expect(a).to eq(b)
340
+ expect(a.object_id).not_to eq(b.object_id)
434
341
 
435
- expected = object_fixture("amf3-empty-array-ref.bin")
436
- input = [a,b,a,b]
437
- output = RocketAMF.serialize(input, 3)
438
- output.should == expected
342
+ expected = object_fixture('amf3-empty-array-ref.bin')
343
+ input = [a, b, a, b]
344
+ output = RocketAMF.serialize(input)
345
+ expect(output).to eq(expected)
439
346
  end
440
347
 
441
- it "should keep references of duplicate byte arrays" do
442
- b = StringIO.new "ASDF"
348
+ it 'should keep references of duplicate byte arrays' do
349
+ b = StringIO.new 'ASDF'
443
350
 
444
- expected = object_fixture("amf3-byte-array-ref.bin")
445
- input = [b, b]
446
- output = RocketAMF.serialize(input, 3)
447
- output.should == expected
351
+ expected = object_fixture('amf3-byte-array-ref.bin')
352
+ input = [b, b]
353
+ output = RocketAMF.serialize(input)
354
+ expect(output).to eq(expected)
448
355
  end
449
356
 
450
- it "should serialize a deep object graph with circular references" do
357
+ it 'should serialize a deep object graph with circular references' do
451
358
  class GraphMember
452
359
  attr_accessor :children
453
360
  attr_accessor :parent
@@ -456,7 +363,7 @@ describe "when serializing" do
456
363
  self.children = []
457
364
  end
458
365
 
459
- def add_child child
366
+ def add_child(child)
460
367
  children << child
461
368
  child.parent = self
462
369
  child
@@ -464,39 +371,41 @@ describe "when serializing" do
464
371
  end
465
372
 
466
373
  parent = GraphMember.new
467
- level_1_child_1 = parent.add_child GraphMember.new
468
- level_1_child_2 = parent.add_child GraphMember.new
374
+ #level_1_child_1
375
+ parent.add_child(GraphMember.new)
376
+ #level_1_child_2
377
+ parent.add_child(GraphMember.new)
469
378
 
470
- expected = object_fixture("amf3-graph-member.bin")
471
- input = parent
472
- output = RocketAMF.serialize(input, 3)
473
- output.should == expected
379
+ expected = object_fixture('amf3-graph-member.bin')
380
+ input = parent
381
+ output = RocketAMF.serialize(input)
382
+ expect(output).to eq(expected)
474
383
  end
475
384
  end
476
385
 
477
- describe "and handling encodings", :if => "".respond_to?(:force_encoding) do
478
- it "should support multiple encodings" do
479
- shift_str = "\x53\x68\x69\x66\x74\x20\x83\x65\x83\x58\x83\x67".force_encoding("Shift_JIS") # "Shift テスト"
480
- utf_str = "\x55\x54\x46\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding("UTF-8") # "UTF テスト"
481
- output = RocketAMF.serialize([5, shift_str, utf_str, 5], 3)
482
- output.should == object_fixture("amf3-complex-encoded-string-array.bin")
386
+ describe 'and handling encodings', if: ''.respond_to?(:force_encoding) do
387
+ it 'should support multiple encodings' do
388
+ shift_str = "\x53\x68\x69\x66\x74\x20\x83\x65\x83\x58\x83\x67".force_encoding('Shift_JIS') # 'Shift テスト'
389
+ utf_str = "\x55\x54\x46\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8') # 'UTF テスト'
390
+ output = RocketAMF.serialize([5, shift_str, utf_str, 5])
391
+ expect(output).to eq(object_fixture('amf3-complex-encoded-string-array.bin'))
483
392
  end
484
393
 
485
- it "should keep references of duplicate strings with different encodings" do
486
- # String is "this is a テスト"
487
- shift_str = "\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\x83\x65\x83\x58\x83\x67".force_encoding("Shift_JIS")
488
- utf_str = "\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding("UTF-8")
394
+ it 'should keep references of duplicate strings with different encodings' do
395
+ # String is 'this is a テスト'
396
+ shift_str = "\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\x83\x65\x83\x58\x83\x67".force_encoding('Shift_JIS')
397
+ utf_str = "\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
489
398
 
490
- expected = object_fixture("amf3-encoded-string-ref.bin")
491
- output = RocketAMF.serialize([shift_str, utf_str], 3)
492
- output.should == expected
399
+ expected = object_fixture('amf3-encoded-string-ref.bin')
400
+ output = RocketAMF.serialize([shift_str, utf_str])
401
+ expect(output).to eq(expected)
493
402
  end
494
403
 
495
- it "should handle inappropriate UTF-8 characters in byte arrays" do
496
- str = "\xff\xff\xff".force_encoding("ASCII-8BIT")
404
+ it 'should handle inappropriate UTF-8 characters in byte arrays' do
405
+ str = "\xff\xff\xff".force_encoding('ASCII-8BIT')
497
406
  str.freeze # For added amusement
498
- output = RocketAMF.serialize(StringIO.new(str), 3)
499
- output.should == "\x0c\x07\xff\xff\xff".force_encoding("ASCII-8BIT")
407
+ output = RocketAMF.serialize(StringIO.new(str))
408
+ expect(output).to eq("\x0c\x07\xff\xff\xff".force_encoding('ASCII-8BIT'))
500
409
  end
501
410
  end
502
411
  end