thrift 0.9.3.0 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/ext/compact_protocol.c +1 -0
  3. data/ext/struct.c +14 -1
  4. data/ext/thrift_native.c +17 -0
  5. data/lib/thrift/client.rb +10 -2
  6. data/lib/thrift/processor.rb +10 -3
  7. data/lib/thrift/protocol/base_protocol.rb +11 -3
  8. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  9. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  10. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  11. data/lib/thrift/protocol/json_protocol.rb +21 -4
  12. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  13. data/lib/thrift/server/base_server.rb +8 -2
  14. data/lib/thrift/server/simple_server.rb +5 -1
  15. data/lib/thrift/server/thread_pool_server.rb +5 -1
  16. data/lib/thrift/server/threaded_server.rb +5 -1
  17. data/lib/thrift/transport/base_server_transport.rb +1 -1
  18. data/lib/thrift/transport/base_transport.rb +8 -0
  19. data/lib/thrift/transport/buffered_transport.rb +9 -1
  20. data/lib/thrift/transport/framed_transport.rb +9 -1
  21. data/lib/thrift/transport/http_client_transport.rb +7 -0
  22. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  23. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  24. data/lib/thrift/transport/server_socket.rb +6 -1
  25. data/lib/thrift/transport/socket.rb +21 -17
  26. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  27. data/lib/thrift/transport/ssl_socket.rb +51 -0
  28. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  29. data/lib/thrift/transport/unix_socket.rb +5 -1
  30. data/lib/thrift.rb +6 -4
  31. data/spec/base_protocol_spec.rb +79 -71
  32. data/spec/base_transport_spec.rb +155 -117
  33. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  34. data/spec/binary_protocol_spec.rb +16 -8
  35. data/spec/binary_protocol_spec_shared.rb +75 -72
  36. data/spec/bytes_spec.rb +38 -38
  37. data/spec/client_spec.rb +43 -42
  38. data/spec/compact_protocol_spec.rb +32 -17
  39. data/spec/exception_spec.rb +54 -54
  40. data/spec/flat_spec.rb +5 -5
  41. data/spec/http_client_spec.rb +74 -33
  42. data/spec/json_protocol_spec.rb +170 -131
  43. data/spec/namespaced_spec.rb +5 -5
  44. data/spec/nonblocking_server_spec.rb +16 -16
  45. data/spec/processor_spec.rb +26 -26
  46. data/spec/serializer_spec.rb +20 -20
  47. data/spec/server_socket_spec.rb +27 -22
  48. data/spec/server_spec.rb +91 -51
  49. data/spec/socket_spec.rb +23 -16
  50. data/spec/socket_spec_shared.rb +31 -31
  51. data/spec/spec_helper.rb +6 -1
  52. data/spec/ssl_server_socket_spec.rb +34 -0
  53. data/spec/ssl_socket_spec.rb +78 -0
  54. data/spec/struct_nested_containers_spec.rb +24 -24
  55. data/spec/struct_spec.rb +120 -120
  56. data/spec/thin_http_server_spec.rb +18 -18
  57. data/spec/types_spec.rb +56 -53
  58. data/spec/union_spec.rb +47 -41
  59. data/spec/unix_socket_spec.rb +43 -34
  60. metadata +195 -146
@@ -30,252 +30,257 @@ describe 'JsonProtocol' do
30
30
 
31
31
  it "should write json escaped char" do
32
32
  @prot.write_json_escape_char("\n")
33
- @trans.read(@trans.available).should == '\u000a'
33
+ expect(@trans.read(@trans.available)).to eq('\u000a')
34
34
 
35
35
  @prot.write_json_escape_char(" ")
36
- @trans.read(@trans.available).should == '\u0020'
36
+ expect(@trans.read(@trans.available)).to eq('\u0020')
37
37
  end
38
38
 
39
39
  it "should write json char" do
40
40
  @prot.write_json_char("\n")
41
- @trans.read(@trans.available).should == '\\n'
41
+ expect(@trans.read(@trans.available)).to eq('\\n')
42
42
 
43
43
  @prot.write_json_char(" ")
44
- @trans.read(@trans.available).should == ' '
44
+ expect(@trans.read(@trans.available)).to eq(' ')
45
45
 
46
46
  @prot.write_json_char("\\")
47
- @trans.read(@trans.available).should == "\\\\"
47
+ expect(@trans.read(@trans.available)).to eq("\\\\")
48
48
 
49
49
  @prot.write_json_char("@")
50
- @trans.read(@trans.available).should == '@'
50
+ expect(@trans.read(@trans.available)).to eq('@')
51
51
  end
52
52
 
53
53
  it "should write json string" do
54
54
  @prot.write_json_string("this is a \\ json\nstring")
55
- @trans.read(@trans.available).should == "\"this is a \\\\ json\\nstring\""
55
+ expect(@trans.read(@trans.available)).to eq("\"this is a \\\\ json\\nstring\"")
56
56
  end
57
57
 
58
58
  it "should write json base64" do
59
59
  @prot.write_json_base64("this is a base64 string")
60
- @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
60
+ expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
61
61
  end
62
62
 
63
63
  it "should write json integer" do
64
64
  @prot.write_json_integer(45)
65
- @trans.read(@trans.available).should == "45"
65
+ expect(@trans.read(@trans.available)).to eq("45")
66
66
 
67
67
  @prot.write_json_integer(33000)
68
- @trans.read(@trans.available).should == "33000"
68
+ expect(@trans.read(@trans.available)).to eq("33000")
69
69
 
70
70
  @prot.write_json_integer(3000000000)
71
- @trans.read(@trans.available).should == "3000000000"
71
+ expect(@trans.read(@trans.available)).to eq("3000000000")
72
72
 
73
73
  @prot.write_json_integer(6000000000)
74
- @trans.read(@trans.available).should == "6000000000"
74
+ expect(@trans.read(@trans.available)).to eq("6000000000")
75
75
  end
76
76
 
77
77
  it "should write json double" do
78
78
  @prot.write_json_double(12.3)
79
- @trans.read(@trans.available).should == "12.3"
79
+ expect(@trans.read(@trans.available)).to eq("12.3")
80
80
 
81
81
  @prot.write_json_double(-3.21)
82
- @trans.read(@trans.available).should == "-3.21"
82
+ expect(@trans.read(@trans.available)).to eq("-3.21")
83
83
 
84
84
  @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
85
- @trans.read(@trans.available).should == "\"NaN\""
85
+ expect(@trans.read(@trans.available)).to eq("\"NaN\"")
86
86
 
87
87
  @prot.write_json_double((+1.0/0.0))
88
- @trans.read(@trans.available).should == "\"Infinity\""
88
+ expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
89
89
 
90
90
  @prot.write_json_double((-1.0/0.0))
91
- @trans.read(@trans.available).should == "\"-Infinity\""
91
+ expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
92
92
  end
93
93
 
94
94
  it "should write json object start" do
95
95
  @prot.write_json_object_start
96
- @trans.read(@trans.available).should == "{"
96
+ expect(@trans.read(@trans.available)).to eq("{")
97
97
  end
98
98
 
99
99
  it "should write json object end" do
100
100
  @prot.write_json_object_end
101
- @trans.read(@trans.available).should == "}"
101
+ expect(@trans.read(@trans.available)).to eq("}")
102
102
  end
103
103
 
104
104
  it "should write json array start" do
105
105
  @prot.write_json_array_start
106
- @trans.read(@trans.available).should == "["
106
+ expect(@trans.read(@trans.available)).to eq("[")
107
107
  end
108
108
 
109
109
  it "should write json array end" do
110
110
  @prot.write_json_array_end
111
- @trans.read(@trans.available).should == "]"
111
+ expect(@trans.read(@trans.available)).to eq("]")
112
112
  end
113
113
 
114
114
  it "should write message begin" do
115
115
  @prot.write_message_begin("name", 12, 32)
116
- @trans.read(@trans.available).should == "[1,\"name\",12,32"
116
+ expect(@trans.read(@trans.available)).to eq("[1,\"name\",12,32")
117
117
  end
118
118
 
119
119
  it "should write message end" do
120
120
  @prot.write_message_end
121
- @trans.read(@trans.available).should == "]"
121
+ expect(@trans.read(@trans.available)).to eq("]")
122
122
  end
123
123
 
124
124
  it "should write struct begin" do
125
125
  @prot.write_struct_begin("name")
126
- @trans.read(@trans.available).should == "{"
126
+ expect(@trans.read(@trans.available)).to eq("{")
127
127
  end
128
128
 
129
129
  it "should write struct end" do
130
130
  @prot.write_struct_end
131
- @trans.read(@trans.available).should == "}"
131
+ expect(@trans.read(@trans.available)).to eq("}")
132
132
  end
133
133
 
134
134
  it "should write field begin" do
135
135
  @prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
136
- @trans.read(@trans.available).should == "32{\"rec\""
136
+ expect(@trans.read(@trans.available)).to eq("32{\"rec\"")
137
137
  end
138
138
 
139
139
  it "should write field end" do
140
140
  @prot.write_field_end
141
- @trans.read(@trans.available).should == "}"
141
+ expect(@trans.read(@trans.available)).to eq("}")
142
142
  end
143
143
 
144
144
  it "should write field stop" do
145
145
  @prot.write_field_stop
146
- @trans.read(@trans.available).should == ""
146
+ expect(@trans.read(@trans.available)).to eq("")
147
147
  end
148
148
 
149
149
  it "should write map begin" do
150
150
  @prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
151
- @trans.read(@trans.available).should == "[\"rec\",\"lst\",32,{"
151
+ expect(@trans.read(@trans.available)).to eq("[\"rec\",\"lst\",32,{")
152
152
  end
153
153
 
154
154
  it "should write map end" do
155
155
  @prot.write_map_end
156
- @trans.read(@trans.available).should == "}]"
156
+ expect(@trans.read(@trans.available)).to eq("}]")
157
157
  end
158
158
 
159
159
  it "should write list begin" do
160
160
  @prot.write_list_begin(Thrift::Types::STRUCT, 32)
161
- @trans.read(@trans.available).should == "[\"rec\",32"
161
+ expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
162
162
  end
163
163
 
164
164
  it "should write list end" do
165
165
  @prot.write_list_end
166
- @trans.read(@trans.available).should == "]"
166
+ expect(@trans.read(@trans.available)).to eq("]")
167
167
  end
168
168
 
169
169
  it "should write set begin" do
170
170
  @prot.write_set_begin(Thrift::Types::STRUCT, 32)
171
- @trans.read(@trans.available).should == "[\"rec\",32"
171
+ expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
172
172
  end
173
173
 
174
174
  it "should write set end" do
175
175
  @prot.write_set_end
176
- @trans.read(@trans.available).should == "]"
176
+ expect(@trans.read(@trans.available)).to eq("]")
177
177
  end
178
178
 
179
179
  it "should write bool" do
180
180
  @prot.write_bool(true)
181
- @trans.read(@trans.available).should == "1"
181
+ expect(@trans.read(@trans.available)).to eq("1")
182
182
 
183
183
  @prot.write_bool(false)
184
- @trans.read(@trans.available).should == "0"
184
+ expect(@trans.read(@trans.available)).to eq("0")
185
185
  end
186
186
 
187
187
  it "should write byte" do
188
188
  @prot.write_byte(100)
189
- @trans.read(@trans.available).should == "100"
189
+ expect(@trans.read(@trans.available)).to eq("100")
190
190
  end
191
191
 
192
192
  it "should write i16" do
193
193
  @prot.write_i16(1000)
194
- @trans.read(@trans.available).should == "1000"
194
+ expect(@trans.read(@trans.available)).to eq("1000")
195
195
  end
196
196
 
197
197
  it "should write i32" do
198
198
  @prot.write_i32(3000000000)
199
- @trans.read(@trans.available).should == "3000000000"
199
+ expect(@trans.read(@trans.available)).to eq("3000000000")
200
200
  end
201
201
 
202
202
  it "should write i64" do
203
203
  @prot.write_i64(6000000000)
204
- @trans.read(@trans.available).should == "6000000000"
204
+ expect(@trans.read(@trans.available)).to eq("6000000000")
205
205
  end
206
206
 
207
207
  it "should write double" do
208
208
  @prot.write_double(1.23)
209
- @trans.read(@trans.available).should == "1.23"
209
+ expect(@trans.read(@trans.available)).to eq("1.23")
210
210
 
211
211
  @prot.write_double(-32.1)
212
- @trans.read(@trans.available).should == "-32.1"
212
+ expect(@trans.read(@trans.available)).to eq("-32.1")
213
213
 
214
214
  @prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
215
- @trans.read(@trans.available).should == "\"NaN\""
215
+ expect(@trans.read(@trans.available)).to eq("\"NaN\"")
216
216
 
217
217
  @prot.write_double((+1.0/0.0))
218
- @trans.read(@trans.available).should == "\"Infinity\""
218
+ expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
219
219
 
220
220
  @prot.write_double((-1.0/0.0))
221
- @trans.read(@trans.available).should == "\"-Infinity\""
221
+ expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
222
222
  end
223
223
 
224
224
  if RUBY_VERSION >= '1.9'
225
225
  it 'should write string' do
226
226
  @prot.write_string('this is a test string')
227
227
  a = @trans.read(@trans.available)
228
- a.should == '"this is a test string"'.force_encoding(Encoding::BINARY)
229
- a.encoding.should == Encoding::BINARY
228
+ expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY))
229
+ expect(a.encoding).to eq(Encoding::BINARY)
230
230
  end
231
231
 
232
232
  it 'should write string with unicode characters' do
233
233
  @prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
234
234
  a = @trans.read(@trans.available)
235
- a.should == "\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY)
236
- a.encoding.should == Encoding::BINARY
235
+ expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY))
236
+ expect(a.encoding).to eq(Encoding::BINARY)
237
237
  end
238
238
  else
239
239
  it 'should write string' do
240
240
  @prot.write_string('this is a test string')
241
- @trans.read(@trans.available).should == '"this is a test string"'
241
+ expect(@trans.read(@trans.available)).to eq('"this is a test string"')
242
242
  end
243
243
  end
244
244
 
245
245
  it "should write binary" do
246
246
  @prot.write_binary("this is a base64 string")
247
- @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
247
+ expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
248
+ end
249
+
250
+ it "should write long binary" do
251
+ @prot.write_binary((0...256).to_a.pack('C*'))
252
+ expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
248
253
  end
249
254
 
250
255
  it "should get type name for type id" do
251
256
  expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
252
257
  expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError)
253
- @prot.get_type_name_for_type_id(Thrift::Types::BOOL).should == "tf"
254
- @prot.get_type_name_for_type_id(Thrift::Types::BYTE).should == "i8"
255
- @prot.get_type_name_for_type_id(Thrift::Types::DOUBLE).should == "dbl"
256
- @prot.get_type_name_for_type_id(Thrift::Types::I16).should == "i16"
257
- @prot.get_type_name_for_type_id(Thrift::Types::I32).should == "i32"
258
- @prot.get_type_name_for_type_id(Thrift::Types::I64).should == "i64"
259
- @prot.get_type_name_for_type_id(Thrift::Types::STRING).should == "str"
260
- @prot.get_type_name_for_type_id(Thrift::Types::STRUCT).should == "rec"
261
- @prot.get_type_name_for_type_id(Thrift::Types::MAP).should == "map"
262
- @prot.get_type_name_for_type_id(Thrift::Types::SET).should == "set"
263
- @prot.get_type_name_for_type_id(Thrift::Types::LIST).should == "lst"
258
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::BOOL)).to eq("tf")
259
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::BYTE)).to eq("i8")
260
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE)).to eq("dbl")
261
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::I16)).to eq("i16")
262
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::I32)).to eq("i32")
263
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::I64)).to eq("i64")
264
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::STRING)).to eq("str")
265
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::STRUCT)).to eq("rec")
266
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::MAP)).to eq("map")
267
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::SET)).to eq("set")
268
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::LIST)).to eq("lst")
264
269
  end
265
270
 
266
271
  it "should get type id for type name" do
267
272
  expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError)
268
- @prot.get_type_id_for_type_name("tf").should == Thrift::Types::BOOL
269
- @prot.get_type_id_for_type_name("i8").should == Thrift::Types::BYTE
270
- @prot.get_type_id_for_type_name("dbl").should == Thrift::Types::DOUBLE
271
- @prot.get_type_id_for_type_name("i16").should == Thrift::Types::I16
272
- @prot.get_type_id_for_type_name("i32").should == Thrift::Types::I32
273
- @prot.get_type_id_for_type_name("i64").should == Thrift::Types::I64
274
- @prot.get_type_id_for_type_name("str").should == Thrift::Types::STRING
275
- @prot.get_type_id_for_type_name("rec").should == Thrift::Types::STRUCT
276
- @prot.get_type_id_for_type_name("map").should == Thrift::Types::MAP
277
- @prot.get_type_id_for_type_name("set").should == Thrift::Types::SET
278
- @prot.get_type_id_for_type_name("lst").should == Thrift::Types::LIST
273
+ expect(@prot.get_type_id_for_type_name("tf")).to eq(Thrift::Types::BOOL)
274
+ expect(@prot.get_type_id_for_type_name("i8")).to eq(Thrift::Types::BYTE)
275
+ expect(@prot.get_type_id_for_type_name("dbl")).to eq(Thrift::Types::DOUBLE)
276
+ expect(@prot.get_type_id_for_type_name("i16")).to eq(Thrift::Types::I16)
277
+ expect(@prot.get_type_id_for_type_name("i32")).to eq(Thrift::Types::I32)
278
+ expect(@prot.get_type_id_for_type_name("i64")).to eq(Thrift::Types::I64)
279
+ expect(@prot.get_type_id_for_type_name("str")).to eq(Thrift::Types::STRING)
280
+ expect(@prot.get_type_id_for_type_name("rec")).to eq(Thrift::Types::STRUCT)
281
+ expect(@prot.get_type_id_for_type_name("map")).to eq(Thrift::Types::MAP)
282
+ expect(@prot.get_type_id_for_type_name("set")).to eq(Thrift::Types::SET)
283
+ expect(@prot.get_type_id_for_type_name("lst")).to eq(Thrift::Types::LIST)
279
284
  end
280
285
 
281
286
  it "should read json syntax char" do
@@ -287,47 +292,68 @@ describe 'JsonProtocol' do
287
292
 
288
293
  it "should read json escape char" do
289
294
  @trans.write('0054')
290
- @prot.read_json_escape_char.should == 'T'
295
+ expect(@prot.read_json_escape_char).to eq('T')
296
+
297
+ @trans.write("\"\\\"\"")
298
+ expect(@prot.read_json_string(false)).to eq("\"")
299
+
300
+ @trans.write("\"\\\\\"")
301
+ expect(@prot.read_json_string(false)).to eq("\\")
302
+
303
+ @trans.write("\"\\/\"")
304
+ expect(@prot.read_json_string(false)).to eq("\/")
305
+
306
+ @trans.write("\"\\b\"")
307
+ expect(@prot.read_json_string(false)).to eq("\b")
308
+
309
+ @trans.write("\"\\f\"")
310
+ expect(@prot.read_json_string(false)).to eq("\f")
311
+
312
+ @trans.write("\"\\n\"")
313
+ expect(@prot.read_json_string(false)).to eq("\n")
314
+
315
+ @trans.write("\"\\r\"")
316
+ expect(@prot.read_json_string(false)).to eq("\r")
317
+
318
+ @trans.write("\"\\t\"")
319
+ expect(@prot.read_json_string(false)).to eq("\t")
291
320
  end
292
321
 
293
322
  it "should read json string" do
294
323
  @trans.write("\"\\P")
295
324
  expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
296
325
 
297
- @trans.write("\"\\n\"")
298
- @prot.read_json_string(false).should == "\\n"
299
-
300
326
  @trans.write("\"this is a test string\"")
301
- @prot.read_json_string.should == "this is a test string"
327
+ expect(@prot.read_json_string).to eq("this is a test string")
302
328
  end
303
329
 
304
330
  it "should read json base64" do
305
331
  @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
306
- @prot.read_json_base64.should == "this is a test string"
332
+ expect(@prot.read_json_base64).to eq("this is a test string")
307
333
  end
308
334
 
309
335
  it "should is json numeric" do
310
- @prot.is_json_numeric("A").should == false
311
- @prot.is_json_numeric("+").should == true
312
- @prot.is_json_numeric("-").should == true
313
- @prot.is_json_numeric(".").should == true
314
- @prot.is_json_numeric("0").should == true
315
- @prot.is_json_numeric("1").should == true
316
- @prot.is_json_numeric("2").should == true
317
- @prot.is_json_numeric("3").should == true
318
- @prot.is_json_numeric("4").should == true
319
- @prot.is_json_numeric("5").should == true
320
- @prot.is_json_numeric("6").should == true
321
- @prot.is_json_numeric("7").should == true
322
- @prot.is_json_numeric("8").should == true
323
- @prot.is_json_numeric("9").should == true
324
- @prot.is_json_numeric("E").should == true
325
- @prot.is_json_numeric("e").should == true
336
+ expect(@prot.is_json_numeric("A")).to eq(false)
337
+ expect(@prot.is_json_numeric("+")).to eq(true)
338
+ expect(@prot.is_json_numeric("-")).to eq(true)
339
+ expect(@prot.is_json_numeric(".")).to eq(true)
340
+ expect(@prot.is_json_numeric("0")).to eq(true)
341
+ expect(@prot.is_json_numeric("1")).to eq(true)
342
+ expect(@prot.is_json_numeric("2")).to eq(true)
343
+ expect(@prot.is_json_numeric("3")).to eq(true)
344
+ expect(@prot.is_json_numeric("4")).to eq(true)
345
+ expect(@prot.is_json_numeric("5")).to eq(true)
346
+ expect(@prot.is_json_numeric("6")).to eq(true)
347
+ expect(@prot.is_json_numeric("7")).to eq(true)
348
+ expect(@prot.is_json_numeric("8")).to eq(true)
349
+ expect(@prot.is_json_numeric("9")).to eq(true)
350
+ expect(@prot.is_json_numeric("E")).to eq(true)
351
+ expect(@prot.is_json_numeric("e")).to eq(true)
326
352
  end
327
353
 
328
354
  it "should read json numeric chars" do
329
355
  @trans.write("1.453E45T")
330
- @prot.read_json_numeric_chars.should == "1.453E45"
356
+ expect(@prot.read_json_numeric_chars).to eq("1.453E45")
331
357
  end
332
358
 
333
359
  it "should read json integer" do
@@ -336,7 +362,7 @@ describe 'JsonProtocol' do
336
362
  @prot.read_string
337
363
 
338
364
  @trans.write("1453T")
339
- @prot.read_json_integer.should == 1453
365
+ expect(@prot.read_json_integer).to eq(1453)
340
366
  end
341
367
 
342
368
  it "should read json double" do
@@ -348,37 +374,37 @@ describe 'JsonProtocol' do
348
374
  expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
349
375
 
350
376
  @trans.write("1.453e01\"\"")
351
- @prot.read_json_double.should == 14.53
377
+ expect(@prot.read_json_double).to eq(14.53)
352
378
  @prot.read_string
353
379
 
354
380
  @trans.write("\"NaN\"")
355
- @prot.read_json_double.nan?.should == true
381
+ expect(@prot.read_json_double.nan?).to eq(true)
356
382
 
357
383
  @trans.write("\"Infinity\"")
358
- @prot.read_json_double.should == +1.0/0.0
384
+ expect(@prot.read_json_double).to eq(+1.0/0.0)
359
385
 
360
386
  @trans.write("\"-Infinity\"")
361
- @prot.read_json_double.should == -1.0/0.0
387
+ expect(@prot.read_json_double).to eq(-1.0/0.0)
362
388
  end
363
389
 
364
390
  it "should read json object start" do
365
391
  @trans.write("{")
366
- @prot.read_json_object_start.should == nil
392
+ expect(@prot.read_json_object_start).to eq(nil)
367
393
  end
368
394
 
369
395
  it "should read json object end" do
370
396
  @trans.write("}")
371
- @prot.read_json_object_end.should == nil
397
+ expect(@prot.read_json_object_end).to eq(nil)
372
398
  end
373
399
 
374
400
  it "should read json array start" do
375
401
  @trans.write("[")
376
- @prot.read_json_array_start.should == nil
402
+ expect(@prot.read_json_array_start).to eq(nil)
377
403
  end
378
404
 
379
405
  it "should read json array end" do
380
406
  @trans.write("]")
381
- @prot.read_json_array_end.should == nil
407
+ expect(@prot.read_json_array_end).to eq(nil)
382
408
  end
383
409
 
384
410
  it "should read_message_begin" do
@@ -386,128 +412,141 @@ describe 'JsonProtocol' do
386
412
  expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
387
413
 
388
414
  @trans.write("[1,\"name\",12,32\"\"")
389
- @prot.read_message_begin.should == ["name", 12, 32]
415
+ expect(@prot.read_message_begin).to eq(["name", 12, 32])
390
416
  end
391
417
 
392
418
  it "should read message end" do
393
419
  @trans.write("]")
394
- @prot.read_message_end.should == nil
420
+ expect(@prot.read_message_end).to eq(nil)
395
421
  end
396
422
 
397
423
  it "should read struct begin" do
398
424
  @trans.write("{")
399
- @prot.read_struct_begin.should == nil
425
+ expect(@prot.read_struct_begin).to eq(nil)
400
426
  end
401
427
 
402
428
  it "should read struct end" do
403
429
  @trans.write("}")
404
- @prot.read_struct_end.should == nil
430
+ expect(@prot.read_struct_end).to eq(nil)
405
431
  end
406
432
 
407
433
  it "should read field begin" do
408
434
  @trans.write("1{\"rec\"")
409
- @prot.read_field_begin.should == [nil, 12, 1]
435
+ expect(@prot.read_field_begin).to eq([nil, 12, 1])
410
436
  end
411
437
 
412
438
  it "should read field end" do
413
439
  @trans.write("}")
414
- @prot.read_field_end.should == nil
440
+ expect(@prot.read_field_end).to eq(nil)
415
441
  end
416
442
 
417
443
  it "should read map begin" do
418
444
  @trans.write("[\"rec\",\"lst\",2,{")
419
- @prot.read_map_begin.should == [12, 15, 2]
445
+ expect(@prot.read_map_begin).to eq([12, 15, 2])
420
446
  end
421
447
 
422
448
  it "should read map end" do
423
449
  @trans.write("}]")
424
- @prot.read_map_end.should == nil
450
+ expect(@prot.read_map_end).to eq(nil)
425
451
  end
426
452
 
427
453
  it "should read list begin" do
428
454
  @trans.write("[\"rec\",2\"\"")
429
- @prot.read_list_begin.should == [12, 2]
455
+ expect(@prot.read_list_begin).to eq([12, 2])
430
456
  end
431
457
 
432
458
  it "should read list end" do
433
459
  @trans.write("]")
434
- @prot.read_list_end.should == nil
460
+ expect(@prot.read_list_end).to eq(nil)
435
461
  end
436
462
 
437
463
  it "should read set begin" do
438
464
  @trans.write("[\"rec\",2\"\"")
439
- @prot.read_set_begin.should == [12, 2]
465
+ expect(@prot.read_set_begin).to eq([12, 2])
440
466
  end
441
467
 
442
468
  it "should read set end" do
443
469
  @trans.write("]")
444
- @prot.read_set_end.should == nil
470
+ expect(@prot.read_set_end).to eq(nil)
445
471
  end
446
472
 
447
473
  it "should read bool" do
448
474
  @trans.write("0\"\"")
449
- @prot.read_bool.should == false
475
+ expect(@prot.read_bool).to eq(false)
450
476
  @prot.read_string
451
477
 
452
478
  @trans.write("1\"\"")
453
- @prot.read_bool.should == true
479
+ expect(@prot.read_bool).to eq(true)
454
480
  end
455
481
 
456
482
  it "should read byte" do
457
483
  @trans.write("60\"\"")
458
- @prot.read_byte.should == 60
484
+ expect(@prot.read_byte).to eq(60)
459
485
  end
460
486
 
461
487
  it "should read i16" do
462
488
  @trans.write("1000\"\"")
463
- @prot.read_i16.should == 1000
489
+ expect(@prot.read_i16).to eq(1000)
464
490
  end
465
491
 
466
492
  it "should read i32" do
467
493
  @trans.write("3000000000\"\"")
468
- @prot.read_i32.should == 3000000000
494
+ expect(@prot.read_i32).to eq(3000000000)
469
495
  end
470
496
 
471
497
  it "should read i64" do
472
498
  @trans.write("6000000000\"\"")
473
- @prot.read_i64.should == 6000000000
499
+ expect(@prot.read_i64).to eq(6000000000)
474
500
  end
475
501
 
476
502
  it "should read double" do
477
503
  @trans.write("12.23\"\"")
478
- @prot.read_double.should == 12.23
504
+ expect(@prot.read_double).to eq(12.23)
479
505
  end
480
506
 
481
507
  if RUBY_VERSION >= '1.9'
482
508
  it 'should read string' do
483
509
  @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
484
510
  a = @prot.read_string
485
- a.should == 'this is a test string'
486
- a.encoding.should == Encoding::UTF_8
511
+ expect(a).to eq('this is a test string')
512
+ expect(a.encoding).to eq(Encoding::UTF_8)
487
513
  end
488
514
 
489
515
  it 'should read string with unicode characters' do
490
516
  @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
491
517
  a = @prot.read_string
492
- a.should == "this is a test string with unicode characters: \u20AC \u20AD"
493
- a.encoding.should == Encoding::UTF_8
518
+ expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
519
+ expect(a.encoding).to eq(Encoding::UTF_8)
494
520
  end
495
521
  else
496
522
  it 'should read string' do
497
523
  @trans.write('"this is a test string"')
498
- @prot.read_string.should == 'this is a test string'
524
+ expect(@prot.read_string).to eq('this is a test string')
499
525
  end
500
526
  end
501
527
 
502
528
  it "should read binary" do
503
529
  @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
504
- @prot.read_binary.should == "this is a test string"
530
+ expect(@prot.read_binary).to eq("this is a test string")
531
+ end
532
+
533
+ it "should read long binary" do
534
+ @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
535
+ expect(@prot.read_binary.bytes.to_a).to eq((0...256).to_a)
536
+ end
537
+
538
+ it "should provide a reasonable to_s" do
539
+ expect(@prot.to_s).to eq("json(memory)")
505
540
  end
506
541
  end
507
542
 
508
543
  describe Thrift::JsonProtocolFactory do
509
544
  it "should create a JsonProtocol" do
510
- Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol)
545
+ expect(Thrift::JsonProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::JsonProtocol)
546
+ end
547
+
548
+ it "should provide a reasonable to_s" do
549
+ expect(Thrift::JsonProtocolFactory.new.to_s).to eq("json")
511
550
  end
512
551
  end
513
552
  end