thrift 0.10.0.0 → 0.14.2

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 (54) hide show
  1. checksums.yaml +5 -5
  2. data/lib/thrift/processor.rb +10 -1
  3. data/lib/thrift/protocol/base_protocol.rb +11 -3
  4. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  5. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  6. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  7. data/lib/thrift/protocol/json_protocol.rb +9 -1
  8. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  9. data/lib/thrift/server/base_server.rb +8 -2
  10. data/lib/thrift/server/simple_server.rb +5 -1
  11. data/lib/thrift/server/thread_pool_server.rb +5 -1
  12. data/lib/thrift/server/threaded_server.rb +5 -1
  13. data/lib/thrift/transport/base_server_transport.rb +1 -1
  14. data/lib/thrift/transport/base_transport.rb +8 -0
  15. data/lib/thrift/transport/buffered_transport.rb +9 -1
  16. data/lib/thrift/transport/framed_transport.rb +9 -1
  17. data/lib/thrift/transport/http_client_transport.rb +6 -0
  18. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  19. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  20. data/lib/thrift/transport/server_socket.rb +6 -1
  21. data/lib/thrift/transport/socket.rb +4 -2
  22. data/lib/thrift/transport/ssl_server_socket.rb +4 -0
  23. data/lib/thrift/transport/ssl_socket.rb +4 -0
  24. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  25. data/lib/thrift/transport/unix_socket.rb +5 -1
  26. data/spec/base_protocol_spec.rb +79 -71
  27. data/spec/base_transport_spec.rb +155 -117
  28. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  29. data/spec/binary_protocol_spec.rb +16 -8
  30. data/spec/binary_protocol_spec_shared.rb +73 -70
  31. data/spec/bytes_spec.rb +38 -38
  32. data/spec/client_spec.rb +41 -42
  33. data/spec/compact_protocol_spec.rb +23 -8
  34. data/spec/exception_spec.rb +54 -54
  35. data/spec/flat_spec.rb +5 -5
  36. data/spec/http_client_spec.rb +64 -38
  37. data/spec/json_protocol_spec.rb +146 -138
  38. data/spec/namespaced_spec.rb +5 -5
  39. data/spec/nonblocking_server_spec.rb +16 -16
  40. data/spec/processor_spec.rb +26 -26
  41. data/spec/serializer_spec.rb +20 -20
  42. data/spec/server_socket_spec.rb +27 -22
  43. data/spec/server_spec.rb +91 -51
  44. data/spec/socket_spec.rb +23 -16
  45. data/spec/socket_spec_shared.rb +31 -31
  46. data/spec/ssl_server_socket_spec.rb +34 -0
  47. data/spec/ssl_socket_spec.rb +26 -22
  48. data/spec/struct_nested_containers_spec.rb +24 -24
  49. data/spec/struct_spec.rb +120 -120
  50. data/spec/thin_http_server_spec.rb +18 -18
  51. data/spec/types_spec.rb +56 -53
  52. data/spec/union_spec.rb +42 -43
  53. data/spec/unix_socket_spec.rb +43 -34
  54. metadata +131 -94
data/spec/flat_spec.rb CHANGED
@@ -32,7 +32,7 @@ describe 'generation' do
32
32
  "other_namespace/referenced_constants.rb",
33
33
  "other_namespace/referenced_types.rb"
34
34
  ].each do |name|
35
- File.exist?(File.join(prefix, name)).should_not be_true
35
+ expect(File.exist?(File.join(prefix, name))).not_to be_truthy
36
36
  end
37
37
  end
38
38
 
@@ -44,19 +44,19 @@ describe 'generation' do
44
44
  "referenced_constants.rb",
45
45
  "referenced_types.rb"
46
46
  ].each do |name|
47
- File.exist?(File.join(prefix, name)).should be_true
47
+ expect(File.exist?(File.join(prefix, name))).to be_truthy
48
48
  end
49
49
  end
50
50
 
51
51
  it "has a service class in the right place" do
52
- defined?(NamespacedSpecNamespace::NamespacedNonblockingService).should be_true
52
+ expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
53
53
  end
54
54
 
55
55
  it "has a struct in the right place" do
56
- defined?(NamespacedSpecNamespace::Hello).should be_true
56
+ expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
57
57
  end
58
58
 
59
59
  it "required an included file" do
60
- defined?(OtherNamespace::SomeEnum).should be_true
60
+ expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
61
61
  end
62
62
  end
@@ -25,28 +25,33 @@ describe 'Thrift::HTTPClientTransport' do
25
25
  before(:each) do
26
26
  @client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
27
27
  end
28
+
29
+ it "should provide a reasonable to_s" do
30
+ @client.to_s == "http://my.domain.com/path/to/service?param=value"
31
+ end
28
32
 
29
33
  it "should always be open" do
30
- @client.should be_open
34
+ expect(@client).to be_open
31
35
  @client.close
32
- @client.should be_open
36
+ expect(@client).to be_open
33
37
  end
34
38
 
35
39
  it "should post via HTTP and return the results" do
36
40
  @client.write "a test"
37
41
  @client.write " frame"
38
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
39
- mock("Net::HTTP").tap do |http|
40
- http.should_receive(:use_ssl=).with(false)
41
- http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
42
- mock("Net::HTTPOK").tap do |response|
43
- response.should_receive(:body).and_return "data"
42
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
43
+ double("Net::HTTP").tap do |http|
44
+ expect(http).to receive(:use_ssl=).with(false)
45
+ expect(http).to receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}) do
46
+ double("Net::HTTPOK").tap do |response|
47
+ expect(response).to receive(:body).and_return "data"
48
+ expect(response).to receive(:code).and_return "200"
44
49
  end
45
50
  end
46
51
  end
47
52
  end
48
53
  @client.flush
49
- @client.read(10).should == "data"
54
+ expect(@client.read(10)).to eq("data")
50
55
  end
51
56
 
52
57
  it "should send custom headers if defined" do
@@ -55,12 +60,13 @@ describe 'Thrift::HTTPClientTransport' do
55
60
  headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
56
61
 
57
62
  @client.add_headers(custom_headers)
58
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
59
- mock("Net::HTTP").tap do |http|
60
- http.should_receive(:use_ssl=).with(false)
61
- http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
62
- mock("Net::HTTPOK").tap do |response|
63
- response.should_receive(:body).and_return "data"
63
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
64
+ double("Net::HTTP").tap do |http|
65
+ expect(http).to receive(:use_ssl=).with(false)
66
+ expect(http).to receive(:post).with("/path/to/service?param=value", "test", headers) do
67
+ double("Net::HTTPOK").tap do |response|
68
+ expect(response).to receive(:body).and_return "data"
69
+ expect(response).to receive(:code).and_return "200"
64
70
  end
65
71
  end
66
72
  end
@@ -71,15 +77,33 @@ describe 'Thrift::HTTPClientTransport' do
71
77
  it 'should reset the outbuf on HTTP failures' do
72
78
  @client.write "test"
73
79
 
74
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
75
- mock("Net::HTTP").tap do |http|
76
- http.should_receive(:use_ssl=).with(false)
77
- http.should_receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
80
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
81
+ double("Net::HTTP").tap do |http|
82
+ expect(http).to receive(:use_ssl=).with(false)
83
+ expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
78
84
  end
79
85
  end
80
86
 
81
87
  @client.flush rescue
82
- @client.instance_variable_get(:@outbuf).should eq(Thrift::Bytes.empty_byte_buffer)
88
+ expect(@client.instance_variable_get(:@outbuf)).to eq(Thrift::Bytes.empty_byte_buffer)
89
+ end
90
+
91
+ it 'should raise TransportError on HTTP failures' do
92
+ @client.write "test"
93
+
94
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
95
+ double("Net::HTTP").tap do |http|
96
+ expect(http).to receive(:use_ssl=).with(false)
97
+ expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) do
98
+ double("Net::HTTPOK").tap do |response|
99
+ expect(response).not_to receive(:body)
100
+ expect(response).to receive(:code).at_least(:once).and_return "503"
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ expect { @client.flush }.to raise_error(Thrift::TransportException)
83
107
  end
84
108
 
85
109
  end
@@ -95,20 +119,21 @@ describe 'Thrift::HTTPClientTransport' do
95
119
 
96
120
  client.write "test"
97
121
 
98
- Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
99
- mock("Net::HTTP").tap do |http|
100
- http.should_receive(:use_ssl=).with(true)
101
- http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
102
- http.should_receive(:post).with(@service_path, "test",
103
- "Content-Type" => "application/x-thrift").and_return do
104
- mock("Net::HTTPOK").tap do |response|
105
- response.should_receive(:body).and_return "data"
122
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
123
+ double("Net::HTTP").tap do |http|
124
+ expect(http).to receive(:use_ssl=).with(true)
125
+ expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
126
+ expect(http).to receive(:post).with(@service_path, "test",
127
+ "Content-Type" => "application/x-thrift") do
128
+ double("Net::HTTPOK").tap do |response|
129
+ expect(response).to receive(:body).and_return "data"
130
+ expect(response).to receive(:code).and_return "200"
106
131
  end
107
132
  end
108
133
  end
109
134
  end
110
135
  client.flush
111
- client.read(4).should == "data"
136
+ expect(client.read(4)).to eq("data")
112
137
  end
113
138
 
114
139
  it "should set SSL verify mode when specified" do
@@ -116,20 +141,21 @@ describe 'Thrift::HTTPClientTransport' do
116
141
  :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
117
142
 
118
143
  client.write "test"
119
- Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
120
- mock("Net::HTTP").tap do |http|
121
- http.should_receive(:use_ssl=).with(true)
122
- http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
123
- http.should_receive(:post).with(@service_path, "test",
124
- "Content-Type" => "application/x-thrift").and_return do
125
- mock("Net::HTTPOK").tap do |response|
126
- response.should_receive(:body).and_return "data"
144
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
145
+ double("Net::HTTP").tap do |http|
146
+ expect(http).to receive(:use_ssl=).with(true)
147
+ expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
148
+ expect(http).to receive(:post).with(@service_path, "test",
149
+ "Content-Type" => "application/x-thrift") do
150
+ double("Net::HTTPOK").tap do |response|
151
+ expect(response).to receive(:body).and_return "data"
152
+ expect(response).to receive(:code).and_return "200"
127
153
  end
128
154
  end
129
155
  end
130
156
  end
131
157
  client.flush
132
- client.read(4).should == "data"
158
+ expect(client.read(4)).to eq("data")
133
159
  end
134
160
  end
135
161
  end
@@ -30,257 +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=\""
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=\""
247
+ expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
248
248
  end
249
249
 
250
250
  it "should write long binary" do
251
251
  @prot.write_binary((0...256).to_a.pack('C*'))
252
- @trans.read(@trans.available).should == "\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\""
252
+ expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
253
253
  end
254
254
 
255
255
  it "should get type name for type id" do
256
256
  expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
257
257
  expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError)
258
- @prot.get_type_name_for_type_id(Thrift::Types::BOOL).should == "tf"
259
- @prot.get_type_name_for_type_id(Thrift::Types::BYTE).should == "i8"
260
- @prot.get_type_name_for_type_id(Thrift::Types::DOUBLE).should == "dbl"
261
- @prot.get_type_name_for_type_id(Thrift::Types::I16).should == "i16"
262
- @prot.get_type_name_for_type_id(Thrift::Types::I32).should == "i32"
263
- @prot.get_type_name_for_type_id(Thrift::Types::I64).should == "i64"
264
- @prot.get_type_name_for_type_id(Thrift::Types::STRING).should == "str"
265
- @prot.get_type_name_for_type_id(Thrift::Types::STRUCT).should == "rec"
266
- @prot.get_type_name_for_type_id(Thrift::Types::MAP).should == "map"
267
- @prot.get_type_name_for_type_id(Thrift::Types::SET).should == "set"
268
- @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")
269
269
  end
270
270
 
271
271
  it "should get type id for type name" do
272
272
  expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError)
273
- @prot.get_type_id_for_type_name("tf").should == Thrift::Types::BOOL
274
- @prot.get_type_id_for_type_name("i8").should == Thrift::Types::BYTE
275
- @prot.get_type_id_for_type_name("dbl").should == Thrift::Types::DOUBLE
276
- @prot.get_type_id_for_type_name("i16").should == Thrift::Types::I16
277
- @prot.get_type_id_for_type_name("i32").should == Thrift::Types::I32
278
- @prot.get_type_id_for_type_name("i64").should == Thrift::Types::I64
279
- @prot.get_type_id_for_type_name("str").should == Thrift::Types::STRING
280
- @prot.get_type_id_for_type_name("rec").should == Thrift::Types::STRUCT
281
- @prot.get_type_id_for_type_name("map").should == Thrift::Types::MAP
282
- @prot.get_type_id_for_type_name("set").should == Thrift::Types::SET
283
- @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)
284
284
  end
285
285
 
286
286
  it "should read json syntax char" do
@@ -292,31 +292,31 @@ describe 'JsonProtocol' do
292
292
 
293
293
  it "should read json escape char" do
294
294
  @trans.write('0054')
295
- @prot.read_json_escape_char.should == 'T'
295
+ expect(@prot.read_json_escape_char).to eq('T')
296
296
 
297
297
  @trans.write("\"\\\"\"")
298
- @prot.read_json_string(false).should == "\""
298
+ expect(@prot.read_json_string(false)).to eq("\"")
299
299
 
300
300
  @trans.write("\"\\\\\"")
301
- @prot.read_json_string(false).should == "\\"
301
+ expect(@prot.read_json_string(false)).to eq("\\")
302
302
 
303
303
  @trans.write("\"\\/\"")
304
- @prot.read_json_string(false).should == "\/"
304
+ expect(@prot.read_json_string(false)).to eq("\/")
305
305
 
306
306
  @trans.write("\"\\b\"")
307
- @prot.read_json_string(false).should == "\b"
307
+ expect(@prot.read_json_string(false)).to eq("\b")
308
308
 
309
309
  @trans.write("\"\\f\"")
310
- @prot.read_json_string(false).should == "\f"
310
+ expect(@prot.read_json_string(false)).to eq("\f")
311
311
 
312
312
  @trans.write("\"\\n\"")
313
- @prot.read_json_string(false).should == "\n"
313
+ expect(@prot.read_json_string(false)).to eq("\n")
314
314
 
315
315
  @trans.write("\"\\r\"")
316
- @prot.read_json_string(false).should == "\r"
316
+ expect(@prot.read_json_string(false)).to eq("\r")
317
317
 
318
318
  @trans.write("\"\\t\"")
319
- @prot.read_json_string(false).should == "\t"
319
+ expect(@prot.read_json_string(false)).to eq("\t")
320
320
  end
321
321
 
322
322
  it "should read json string" do
@@ -324,36 +324,36 @@ describe 'JsonProtocol' do
324
324
  expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
325
325
 
326
326
  @trans.write("\"this is a test string\"")
327
- @prot.read_json_string.should == "this is a test string"
327
+ expect(@prot.read_json_string).to eq("this is a test string")
328
328
  end
329
329
 
330
330
  it "should read json base64" do
331
331
  @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
332
- @prot.read_json_base64.should == "this is a test string"
332
+ expect(@prot.read_json_base64).to eq("this is a test string")
333
333
  end
334
334
 
335
335
  it "should is json numeric" do
336
- @prot.is_json_numeric("A").should == false
337
- @prot.is_json_numeric("+").should == true
338
- @prot.is_json_numeric("-").should == true
339
- @prot.is_json_numeric(".").should == true
340
- @prot.is_json_numeric("0").should == true
341
- @prot.is_json_numeric("1").should == true
342
- @prot.is_json_numeric("2").should == true
343
- @prot.is_json_numeric("3").should == true
344
- @prot.is_json_numeric("4").should == true
345
- @prot.is_json_numeric("5").should == true
346
- @prot.is_json_numeric("6").should == true
347
- @prot.is_json_numeric("7").should == true
348
- @prot.is_json_numeric("8").should == true
349
- @prot.is_json_numeric("9").should == true
350
- @prot.is_json_numeric("E").should == true
351
- @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)
352
352
  end
353
353
 
354
354
  it "should read json numeric chars" do
355
355
  @trans.write("1.453E45T")
356
- @prot.read_json_numeric_chars.should == "1.453E45"
356
+ expect(@prot.read_json_numeric_chars).to eq("1.453E45")
357
357
  end
358
358
 
359
359
  it "should read json integer" do
@@ -362,7 +362,7 @@ describe 'JsonProtocol' do
362
362
  @prot.read_string
363
363
 
364
364
  @trans.write("1453T")
365
- @prot.read_json_integer.should == 1453
365
+ expect(@prot.read_json_integer).to eq(1453)
366
366
  end
367
367
 
368
368
  it "should read json double" do
@@ -374,37 +374,37 @@ describe 'JsonProtocol' do
374
374
  expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
375
375
 
376
376
  @trans.write("1.453e01\"\"")
377
- @prot.read_json_double.should == 14.53
377
+ expect(@prot.read_json_double).to eq(14.53)
378
378
  @prot.read_string
379
379
 
380
380
  @trans.write("\"NaN\"")
381
- @prot.read_json_double.nan?.should == true
381
+ expect(@prot.read_json_double.nan?).to eq(true)
382
382
 
383
383
  @trans.write("\"Infinity\"")
384
- @prot.read_json_double.should == +1.0/0.0
384
+ expect(@prot.read_json_double).to eq(+1.0/0.0)
385
385
 
386
386
  @trans.write("\"-Infinity\"")
387
- @prot.read_json_double.should == -1.0/0.0
387
+ expect(@prot.read_json_double).to eq(-1.0/0.0)
388
388
  end
389
389
 
390
390
  it "should read json object start" do
391
391
  @trans.write("{")
392
- @prot.read_json_object_start.should == nil
392
+ expect(@prot.read_json_object_start).to eq(nil)
393
393
  end
394
394
 
395
395
  it "should read json object end" do
396
396
  @trans.write("}")
397
- @prot.read_json_object_end.should == nil
397
+ expect(@prot.read_json_object_end).to eq(nil)
398
398
  end
399
399
 
400
400
  it "should read json array start" do
401
401
  @trans.write("[")
402
- @prot.read_json_array_start.should == nil
402
+ expect(@prot.read_json_array_start).to eq(nil)
403
403
  end
404
404
 
405
405
  it "should read json array end" do
406
406
  @trans.write("]")
407
- @prot.read_json_array_end.should == nil
407
+ expect(@prot.read_json_array_end).to eq(nil)
408
408
  end
409
409
 
410
410
  it "should read_message_begin" do
@@ -412,133 +412,141 @@ describe 'JsonProtocol' do
412
412
  expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
413
413
 
414
414
  @trans.write("[1,\"name\",12,32\"\"")
415
- @prot.read_message_begin.should == ["name", 12, 32]
415
+ expect(@prot.read_message_begin).to eq(["name", 12, 32])
416
416
  end
417
417
 
418
418
  it "should read message end" do
419
419
  @trans.write("]")
420
- @prot.read_message_end.should == nil
420
+ expect(@prot.read_message_end).to eq(nil)
421
421
  end
422
422
 
423
423
  it "should read struct begin" do
424
424
  @trans.write("{")
425
- @prot.read_struct_begin.should == nil
425
+ expect(@prot.read_struct_begin).to eq(nil)
426
426
  end
427
427
 
428
428
  it "should read struct end" do
429
429
  @trans.write("}")
430
- @prot.read_struct_end.should == nil
430
+ expect(@prot.read_struct_end).to eq(nil)
431
431
  end
432
432
 
433
433
  it "should read field begin" do
434
434
  @trans.write("1{\"rec\"")
435
- @prot.read_field_begin.should == [nil, 12, 1]
435
+ expect(@prot.read_field_begin).to eq([nil, 12, 1])
436
436
  end
437
437
 
438
438
  it "should read field end" do
439
439
  @trans.write("}")
440
- @prot.read_field_end.should == nil
440
+ expect(@prot.read_field_end).to eq(nil)
441
441
  end
442
442
 
443
443
  it "should read map begin" do
444
444
  @trans.write("[\"rec\",\"lst\",2,{")
445
- @prot.read_map_begin.should == [12, 15, 2]
445
+ expect(@prot.read_map_begin).to eq([12, 15, 2])
446
446
  end
447
447
 
448
448
  it "should read map end" do
449
449
  @trans.write("}]")
450
- @prot.read_map_end.should == nil
450
+ expect(@prot.read_map_end).to eq(nil)
451
451
  end
452
452
 
453
453
  it "should read list begin" do
454
454
  @trans.write("[\"rec\",2\"\"")
455
- @prot.read_list_begin.should == [12, 2]
455
+ expect(@prot.read_list_begin).to eq([12, 2])
456
456
  end
457
457
 
458
458
  it "should read list end" do
459
459
  @trans.write("]")
460
- @prot.read_list_end.should == nil
460
+ expect(@prot.read_list_end).to eq(nil)
461
461
  end
462
462
 
463
463
  it "should read set begin" do
464
464
  @trans.write("[\"rec\",2\"\"")
465
- @prot.read_set_begin.should == [12, 2]
465
+ expect(@prot.read_set_begin).to eq([12, 2])
466
466
  end
467
467
 
468
468
  it "should read set end" do
469
469
  @trans.write("]")
470
- @prot.read_set_end.should == nil
470
+ expect(@prot.read_set_end).to eq(nil)
471
471
  end
472
472
 
473
473
  it "should read bool" do
474
474
  @trans.write("0\"\"")
475
- @prot.read_bool.should == false
475
+ expect(@prot.read_bool).to eq(false)
476
476
  @prot.read_string
477
477
 
478
478
  @trans.write("1\"\"")
479
- @prot.read_bool.should == true
479
+ expect(@prot.read_bool).to eq(true)
480
480
  end
481
481
 
482
482
  it "should read byte" do
483
483
  @trans.write("60\"\"")
484
- @prot.read_byte.should == 60
484
+ expect(@prot.read_byte).to eq(60)
485
485
  end
486
486
 
487
487
  it "should read i16" do
488
488
  @trans.write("1000\"\"")
489
- @prot.read_i16.should == 1000
489
+ expect(@prot.read_i16).to eq(1000)
490
490
  end
491
491
 
492
492
  it "should read i32" do
493
493
  @trans.write("3000000000\"\"")
494
- @prot.read_i32.should == 3000000000
494
+ expect(@prot.read_i32).to eq(3000000000)
495
495
  end
496
496
 
497
497
  it "should read i64" do
498
498
  @trans.write("6000000000\"\"")
499
- @prot.read_i64.should == 6000000000
499
+ expect(@prot.read_i64).to eq(6000000000)
500
500
  end
501
501
 
502
502
  it "should read double" do
503
503
  @trans.write("12.23\"\"")
504
- @prot.read_double.should == 12.23
504
+ expect(@prot.read_double).to eq(12.23)
505
505
  end
506
506
 
507
507
  if RUBY_VERSION >= '1.9'
508
508
  it 'should read string' do
509
509
  @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
510
510
  a = @prot.read_string
511
- a.should == 'this is a test string'
512
- 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)
513
513
  end
514
514
 
515
515
  it 'should read string with unicode characters' do
516
516
  @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
517
517
  a = @prot.read_string
518
- a.should == "this is a test string with unicode characters: \u20AC \u20AD"
519
- 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)
520
520
  end
521
521
  else
522
522
  it 'should read string' do
523
523
  @trans.write('"this is a test string"')
524
- @prot.read_string.should == 'this is a test string'
524
+ expect(@prot.read_string).to eq('this is a test string')
525
525
  end
526
526
  end
527
527
 
528
528
  it "should read binary" do
529
529
  @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
530
- @prot.read_binary.should == "this is a test string"
530
+ expect(@prot.read_binary).to eq("this is a test string")
531
531
  end
532
532
 
533
533
  it "should read long binary" do
534
534
  @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
535
- @prot.read_binary.bytes.to_a.should == (0...256).to_a
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)")
536
540
  end
537
541
  end
538
542
 
539
543
  describe Thrift::JsonProtocolFactory do
540
544
  it "should create a JsonProtocol" do
541
- 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")
542
550
  end
543
551
  end
544
552
  end