thrift 0.11.0.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/lib/thrift/protocol/base_protocol.rb +11 -3
  3. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  4. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  5. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  6. data/lib/thrift/protocol/json_protocol.rb +8 -0
  7. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  8. data/lib/thrift/server/base_server.rb +8 -2
  9. data/lib/thrift/server/simple_server.rb +5 -1
  10. data/lib/thrift/server/thread_pool_server.rb +5 -1
  11. data/lib/thrift/server/threaded_server.rb +5 -1
  12. data/lib/thrift/transport/base_server_transport.rb +1 -1
  13. data/lib/thrift/transport/base_transport.rb +8 -0
  14. data/lib/thrift/transport/buffered_transport.rb +9 -1
  15. data/lib/thrift/transport/framed_transport.rb +9 -1
  16. data/lib/thrift/transport/http_client_transport.rb +4 -0
  17. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  18. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  19. data/lib/thrift/transport/server_socket.rb +6 -1
  20. data/lib/thrift/transport/socket.rb +4 -2
  21. data/lib/thrift/transport/ssl_server_socket.rb +4 -0
  22. data/lib/thrift/transport/ssl_socket.rb +4 -0
  23. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  24. data/lib/thrift/transport/unix_socket.rb +5 -1
  25. data/spec/base_protocol_spec.rb +79 -71
  26. data/spec/base_transport_spec.rb +155 -117
  27. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  28. data/spec/binary_protocol_spec.rb +16 -8
  29. data/spec/binary_protocol_spec_shared.rb +73 -70
  30. data/spec/bytes_spec.rb +38 -38
  31. data/spec/client_spec.rb +41 -42
  32. data/spec/compact_protocol_spec.rb +23 -8
  33. data/spec/exception_spec.rb +54 -54
  34. data/spec/flat_spec.rb +5 -5
  35. data/spec/http_client_spec.rb +42 -38
  36. data/spec/json_protocol_spec.rb +146 -138
  37. data/spec/namespaced_spec.rb +5 -5
  38. data/spec/nonblocking_server_spec.rb +16 -16
  39. data/spec/processor_spec.rb +26 -26
  40. data/spec/serializer_spec.rb +20 -20
  41. data/spec/server_socket_spec.rb +27 -22
  42. data/spec/server_spec.rb +91 -52
  43. data/spec/socket_spec.rb +23 -16
  44. data/spec/socket_spec_shared.rb +31 -31
  45. data/spec/ssl_server_socket_spec.rb +34 -0
  46. data/spec/ssl_socket_spec.rb +26 -22
  47. data/spec/struct_nested_containers_spec.rb +24 -24
  48. data/spec/struct_spec.rb +120 -120
  49. data/spec/thin_http_server_spec.rb +18 -18
  50. data/spec/types_spec.rb +56 -53
  51. data/spec/union_spec.rb +42 -43
  52. data/spec/unix_socket_spec.rb +43 -34
  53. metadata +134 -154
  54. data/benchmark/gen-rb/benchmark_constants.rb +0 -11
  55. data/benchmark/gen-rb/benchmark_service.rb +0 -80
  56. data/benchmark/gen-rb/benchmark_types.rb +0 -10
  57. data/spec/gen-rb/base/base_service.rb +0 -80
  58. data/spec/gen-rb/base/base_service_constants.rb +0 -11
  59. data/spec/gen-rb/base/base_service_types.rb +0 -26
  60. data/spec/gen-rb/extended/extended_service.rb +0 -78
  61. data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
  62. data/spec/gen-rb/extended/extended_service_types.rb +0 -12
  63. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -272
  64. data/spec/gen-rb/flat/referenced_constants.rb +0 -11
  65. data/spec/gen-rb/flat/referenced_types.rb +0 -17
  66. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
  67. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
  68. data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -272
  69. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
  70. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
  71. data/spec/gen-rb/nonblocking_service.rb +0 -272
  72. data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
  73. data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
  74. data/spec/gen-rb/thrift_spec_constants.rb +0 -11
  75. data/spec/gen-rb/thrift_spec_types.rb +0 -538
  76. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -278
  77. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -781
  78. data/test/debug_proto/gen-rb/empty_service.rb +0 -28
  79. data/test/debug_proto/gen-rb/inherited.rb +0 -83
  80. data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -86
  81. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -85
  82. data/test/debug_proto/gen-rb/srv.rb +0 -395
@@ -23,24 +23,24 @@ require 'thrift/server/thin_http_server'
23
23
 
24
24
  describe Thrift::ThinHTTPServer do
25
25
 
26
- let(:processor) { mock('processor') }
26
+ let(:processor) { double('processor') }
27
27
 
28
28
  describe "#initialize" do
29
29
 
30
30
  context "when using the defaults" do
31
31
 
32
32
  it "binds to port 80, with host 0.0.0.0, a path of '/'" do
33
- Thin::Server.should_receive(:new).with('0.0.0.0', 80, an_instance_of(Rack::Builder))
33
+ expect(Thin::Server).to receive(:new).with('0.0.0.0', 80, an_instance_of(Rack::Builder))
34
34
  Thrift::ThinHTTPServer.new(processor)
35
35
  end
36
36
 
37
37
  it 'creates a ThinHTTPServer::RackApplicationContext' do
38
- Thrift::ThinHTTPServer::RackApplication.should_receive(:for).with("/", processor, an_instance_of(Thrift::BinaryProtocolFactory)).and_return(anything)
38
+ expect(Thrift::ThinHTTPServer::RackApplication).to receive(:for).with("/", processor, an_instance_of(Thrift::BinaryProtocolFactory)).and_return(anything)
39
39
  Thrift::ThinHTTPServer.new(processor)
40
40
  end
41
41
 
42
42
  it "uses the BinaryProtocolFactory" do
43
- Thrift::BinaryProtocolFactory.should_receive(:new)
43
+ expect(Thrift::BinaryProtocolFactory).to receive(:new)
44
44
  Thrift::ThinHTTPServer.new(processor)
45
45
  end
46
46
 
@@ -52,7 +52,7 @@ describe Thrift::ThinHTTPServer do
52
52
  ip = "192.168.0.1"
53
53
  port = 3000
54
54
  path = "/thin"
55
- Thin::Server.should_receive(:new).with(ip, port, an_instance_of(Rack::Builder))
55
+ expect(Thin::Server).to receive(:new).with(ip, port, an_instance_of(Rack::Builder))
56
56
  Thrift::ThinHTTPServer.new(processor,
57
57
  :ip => ip,
58
58
  :port => port,
@@ -60,7 +60,7 @@ describe Thrift::ThinHTTPServer do
60
60
  end
61
61
 
62
62
  it 'creates a ThinHTTPServer::RackApplicationContext with a different protocol factory' do
63
- Thrift::ThinHTTPServer::RackApplication.should_receive(:for).with("/", processor, an_instance_of(Thrift::JsonProtocolFactory)).and_return(anything)
63
+ expect(Thrift::ThinHTTPServer::RackApplication).to receive(:for).with("/", processor, an_instance_of(Thrift::JsonProtocolFactory)).and_return(anything)
64
64
  Thrift::ThinHTTPServer.new(processor,
65
65
  :protocol_factory => Thrift::JsonProtocolFactory.new)
66
66
  end
@@ -72,12 +72,12 @@ describe Thrift::ThinHTTPServer do
72
72
  describe "#serve" do
73
73
 
74
74
  it 'starts the Thin server' do
75
- underlying_thin_server = mock('thin server', :start => true)
76
- Thin::Server.stub(:new).and_return(underlying_thin_server)
75
+ underlying_thin_server = double('thin server', :start => true)
76
+ allow(Thin::Server).to receive(:new).and_return(underlying_thin_server)
77
77
 
78
78
  thin_thrift_server = Thrift::ThinHTTPServer.new(processor)
79
79
 
80
- underlying_thin_server.should_receive(:start)
80
+ expect(underlying_thin_server).to receive(:start)
81
81
  thin_thrift_server.serve
82
82
  end
83
83
  end
@@ -87,8 +87,8 @@ end
87
87
  describe Thrift::ThinHTTPServer::RackApplication do
88
88
  include Rack::Test::Methods
89
89
 
90
- let(:processor) { mock('processor') }
91
- let(:protocol_factory) { mock('protocol factory') }
90
+ let(:processor) { double('processor') }
91
+ let(:protocol_factory) { double('protocol factory') }
92
92
 
93
93
  def app
94
94
  Thrift::ThinHTTPServer::RackApplication.for("/", processor, protocol_factory)
@@ -99,13 +99,13 @@ describe Thrift::ThinHTTPServer::RackApplication do
99
99
  it 'receives a non-POST' do
100
100
  header('Content-Type', "application/x-thrift")
101
101
  get "/"
102
- last_response.status.should be 404
102
+ expect(last_response.status).to be 404
103
103
  end
104
104
 
105
105
  it 'receives a header other than application/x-thrift' do
106
106
  header('Content-Type', "application/json")
107
107
  post "/"
108
- last_response.status.should be 404
108
+ expect(last_response.status).to be 404
109
109
  end
110
110
 
111
111
  end
@@ -113,26 +113,26 @@ describe Thrift::ThinHTTPServer::RackApplication do
113
113
  context "200 response" do
114
114
 
115
115
  before do
116
- protocol_factory.stub(:get_protocol)
117
- processor.stub(:process)
116
+ allow(protocol_factory).to receive(:get_protocol)
117
+ allow(processor).to receive(:process)
118
118
  end
119
119
 
120
120
  it 'creates an IOStreamTransport' do
121
121
  header('Content-Type', "application/x-thrift")
122
- Thrift::IOStreamTransport.should_receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
122
+ expect(Thrift::IOStreamTransport).to receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
123
123
  post "/"
124
124
  end
125
125
 
126
126
  it 'fetches the right protocol based on the Transport' do
127
127
  header('Content-Type', "application/x-thrift")
128
- protocol_factory.should_receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
128
+ expect(protocol_factory).to receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
129
129
  post "/"
130
130
  end
131
131
 
132
132
  it 'status code 200' do
133
133
  header('Content-Type', "application/x-thrift")
134
134
  post "/"
135
- last_response.ok?.should be_true
135
+ expect(last_response.ok?).to be_truthy
136
136
  end
137
137
 
138
138
  end
@@ -31,85 +31,88 @@ describe Thrift::Types do
31
31
 
32
32
  context 'type checking' do
33
33
  it "should return the proper name for each type" do
34
- Thrift.type_name(Thrift::Types::I16).should == "Types::I16"
35
- Thrift.type_name(Thrift::Types::VOID).should == "Types::VOID"
36
- Thrift.type_name(Thrift::Types::LIST).should == "Types::LIST"
37
- Thrift.type_name(42).should be_nil
34
+ expect(Thrift.type_name(Thrift::Types::I16)).to eq("Types::I16")
35
+ expect(Thrift.type_name(Thrift::Types::VOID)).to eq("Types::VOID")
36
+ expect(Thrift.type_name(Thrift::Types::LIST)).to eq("Types::LIST")
37
+ expect(Thrift.type_name(42)).to be_nil
38
38
  end
39
39
 
40
40
  it "should check types properly" do
41
41
  # lambda { Thrift.check_type(nil, Thrift::Types::STOP) }.should raise_error(Thrift::TypeError)
42
- lambda { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.should raise_error(Thrift::TypeError)
43
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.should_not raise_error(Thrift::TypeError)
44
- lambda { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.should raise_error(Thrift::TypeError)
45
- lambda { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.should_not raise_error(Thrift::TypeError)
46
- lambda { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.should raise_error(Thrift::TypeError)
47
- lambda { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.should_not raise_error(Thrift::TypeError)
48
- lambda { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.should_not raise_error(Thrift::TypeError)
49
- lambda { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.should_not raise_error(Thrift::TypeError)
50
- lambda { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.should_not raise_error(Thrift::TypeError)
51
- lambda { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.should raise_error(Thrift::TypeError)
52
- lambda { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.should_not raise_error(Thrift::TypeError)
53
- lambda { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.should raise_error(Thrift::TypeError)
54
- lambda { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.should_not raise_error(Thrift::TypeError)
55
- lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError)
42
+ expect { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.to raise_error(Thrift::TypeError)
43
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.not_to raise_error
44
+ expect { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.to raise_error(Thrift::TypeError)
45
+ expect { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.not_to raise_error
46
+ expect { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.to raise_error(Thrift::TypeError)
47
+ expect { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.not_to raise_error
48
+ expect { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.not_to raise_error
49
+ expect { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.not_to raise_error
50
+ expect { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.not_to raise_error
51
+ expect { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.to raise_error(Thrift::TypeError)
52
+ expect { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.not_to raise_error
53
+ expect { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.to raise_error(Thrift::TypeError)
54
+ expect { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.not_to raise_error
55
+ expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError)
56
56
  hello = SpecNamespace::Hello.new
57
- lambda { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(Thrift::TypeError)
58
- lambda { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.should raise_error(Thrift::TypeError)
59
- lambda { Thrift.check_type({:foo => 1}, {:type => Thrift::Types::MAP}, :foo) }.should_not raise_error(Thrift::TypeError)
60
- lambda { Thrift.check_type([1], {:type => Thrift::Types::MAP}, :foo) }.should raise_error(Thrift::TypeError)
61
- lambda { Thrift.check_type([1], {:type => Thrift::Types::LIST}, :foo) }.should_not raise_error(Thrift::TypeError)
62
- lambda { Thrift.check_type({:foo => 1}, {:type => Thrift::Types::LIST}, :foo) }.should raise_error(Thrift::TypeError)
63
- lambda { Thrift.check_type(Set.new([1,2]), {:type => Thrift::Types::SET}, :foo) }.should_not raise_error(Thrift::TypeError)
64
- lambda { Thrift.check_type([1,2], {:type => Thrift::Types::SET}, :foo) }.should raise_error(Thrift::TypeError)
65
- lambda { Thrift.check_type({:foo => true}, {:type => Thrift::Types::SET}, :foo) }.should raise_error(Thrift::TypeError)
57
+ expect { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.not_to raise_error
58
+ expect { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.to raise_error(Thrift::TypeError)
59
+ field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
60
+ expect { Thrift.check_type({1 => "one"}, field, :foo) }.not_to raise_error
61
+ expect { Thrift.check_type([1], field, :foo) }.to raise_error(Thrift::TypeError)
62
+ field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
63
+ expect { Thrift.check_type([1], field, :foo) }.not_to raise_error
64
+ expect { Thrift.check_type({:foo => 1}, field, :foo) }.to raise_error(Thrift::TypeError)
65
+ field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
66
+ expect { Thrift.check_type(Set.new([1,2]), field, :foo) }.not_to raise_error
67
+ expect { Thrift.check_type([1,2], field, :foo) }.to raise_error(Thrift::TypeError)
68
+ expect { Thrift.check_type({:foo => true}, field, :foo) }.to raise_error(Thrift::TypeError)
66
69
  end
67
70
 
68
71
  it "should error out if nil is passed and skip_types is false" do
69
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.should raise_error(Thrift::TypeError)
70
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.should raise_error(Thrift::TypeError)
71
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.should raise_error(Thrift::TypeError)
72
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.should raise_error(Thrift::TypeError)
73
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.should raise_error(Thrift::TypeError)
74
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.should raise_error(Thrift::TypeError)
75
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.should raise_error(Thrift::TypeError)
76
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.should raise_error(Thrift::TypeError)
77
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.should raise_error(Thrift::TypeError)
78
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.should raise_error(Thrift::TypeError)
79
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.should raise_error(Thrift::TypeError)
72
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.to raise_error(Thrift::TypeError)
73
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.to raise_error(Thrift::TypeError)
74
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.to raise_error(Thrift::TypeError)
75
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.to raise_error(Thrift::TypeError)
76
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.to raise_error(Thrift::TypeError)
77
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.to raise_error(Thrift::TypeError)
78
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.to raise_error(Thrift::TypeError)
79
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.to raise_error(Thrift::TypeError)
80
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.to raise_error(Thrift::TypeError)
81
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.to raise_error(Thrift::TypeError)
82
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.to raise_error(Thrift::TypeError)
80
83
  end
81
84
 
82
85
  it "should check element types on containers" do
83
86
  field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
84
- lambda { Thrift.check_type([1, 2], field, :foo) }.should_not raise_error(Thrift::TypeError)
85
- lambda { Thrift.check_type([1, nil, 2], field, :foo) }.should raise_error(Thrift::TypeError)
87
+ expect { Thrift.check_type([1, 2], field, :foo) }.not_to raise_error
88
+ expect { Thrift.check_type([1, nil, 2], field, :foo) }.to raise_error(Thrift::TypeError)
86
89
  field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
87
- lambda { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.should_not raise_error(Thrift::TypeError)
88
- lambda { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.should raise_error(Thrift::TypeError)
89
- lambda { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.should raise_error(Thrift::TypeError)
90
+ expect { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.not_to raise_error
91
+ expect { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.to raise_error(Thrift::TypeError)
92
+ expect { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.to raise_error(Thrift::TypeError)
90
93
  field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
91
- lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(Thrift::TypeError)
92
- lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(Thrift::TypeError)
93
- lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(Thrift::TypeError)
94
+ expect { Thrift.check_type(Set.new([1, 2]), field, :foo) }.not_to raise_error
95
+ expect { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
96
+ expect { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
94
97
 
95
98
  field = {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}
96
- lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(Thrift::TypeError)
99
+ expect { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.to raise_error(Thrift::TypeError)
97
100
  end
98
101
 
99
102
  it "should give the Thrift::TypeError a readable message" do
100
- msg = "Expected Types::STRING, received Fixnum for field foo"
101
- lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError, msg)
102
- msg = "Expected Types::STRING, received Fixnum for field foo.element"
103
+ msg = /Expected Types::STRING, received (Integer|Fixnum) for field foo/
104
+ expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError, msg)
105
+ msg = /Expected Types::STRING, received (Integer|Fixnum) for field foo.element/
103
106
  field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
104
- lambda { Thrift.check_type([3], field, :foo) }.should raise_error(Thrift::TypeError, msg)
107
+ expect { Thrift.check_type([3], field, :foo) }.to raise_error(Thrift::TypeError, msg)
105
108
  msg = "Expected Types::I32, received NilClass for field foo.element.key"
106
109
  field = {:type => Thrift::Types::LIST,
107
110
  :element => {:type => Thrift::Types::MAP,
108
111
  :key => {:type => Thrift::Types::I32},
109
112
  :value => {:type => Thrift::Types::I32}}}
110
- lambda { Thrift.check_type([{nil => 3}], field, :foo) }.should raise_error(Thrift::TypeError, msg)
113
+ expect { Thrift.check_type([{nil => 3}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
111
114
  msg = "Expected Types::I32, received NilClass for field foo.element.value"
112
- lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should raise_error(Thrift::TypeError, msg)
115
+ expect { Thrift.check_type([{1 => nil}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
113
116
  end
114
117
  end
115
118
  end
@@ -24,85 +24,84 @@ describe 'Union' do
24
24
  describe Thrift::Union do
25
25
  it "should return nil value in unset union" do
26
26
  union = SpecNamespace::My_union.new
27
- union.get_set_field.should == nil
28
- union.get_value.should == nil
27
+ expect(union.get_set_field).to eq(nil)
28
+ expect(union.get_value).to eq(nil)
29
29
  end
30
30
 
31
31
  it "should set a field and be accessible through get_value and the named field accessor" do
32
32
  union = SpecNamespace::My_union.new
33
33
  union.integer32 = 25
34
- union.get_set_field.should == :integer32
35
- union.get_value.should == 25
36
- union.integer32.should == 25
34
+ expect(union.get_set_field).to eq(:integer32)
35
+ expect(union.get_value).to eq(25)
36
+ expect(union.integer32).to eq(25)
37
37
  end
38
38
 
39
39
  it "should work correctly when instantiated with static field constructors" do
40
40
  union = SpecNamespace::My_union.integer32(5)
41
- union.get_set_field.should == :integer32
42
- union.integer32.should == 5
41
+ expect(union.get_set_field).to eq(:integer32)
42
+ expect(union.integer32).to eq(5)
43
43
  end
44
44
 
45
45
  it "should raise for wrong set field" do
46
46
  union = SpecNamespace::My_union.new
47
47
  union.integer32 = 25
48
- lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
48
+ expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
49
49
  end
50
50
 
51
51
  it "should raise for wrong set field when hash initialized and type checking is off" do
52
52
  Thrift.type_checking = false
53
53
  union = SpecNamespace::My_union.new({incorrect_field: :incorrect})
54
- example = lambda { Thrift::Serializer.new.serialize(union) }
55
- example.should raise_error(RuntimeError, "set_field is not valid for this union!")
54
+ expect { Thrift::Serializer.new.serialize(union) }.to raise_error(RuntimeError, "set_field is not valid for this union!")
56
55
  end
57
56
 
58
57
  it "should not be equal to nil" do
59
58
  union = SpecNamespace::My_union.new
60
- union.should_not == nil
59
+ expect(union).not_to eq(nil)
61
60
  end
62
61
 
63
62
  it "should not be equal with an empty String" do
64
63
  union = SpecNamespace::My_union.new
65
- union.should_not == ''
64
+ expect(union).not_to eq('')
66
65
  end
67
66
 
68
67
  it "should not equate two different unions, i32 vs. string" do
69
68
  union = SpecNamespace::My_union.new(:integer32, 25)
70
69
  other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
71
- union.should_not == other_union
70
+ expect(union).not_to eq(other_union)
72
71
  end
73
72
 
74
73
  it "should properly reset setfield and setvalue" do
75
74
  union = SpecNamespace::My_union.new(:integer32, 25)
76
- union.get_set_field.should == :integer32
75
+ expect(union.get_set_field).to eq(:integer32)
77
76
  union.some_characters = "blah!"
78
- union.get_set_field.should == :some_characters
79
- union.get_value.should == "blah!"
80
- lambda { union.integer32 }.should raise_error(RuntimeError, "integer32 is not union's set field.")
77
+ expect(union.get_set_field).to eq(:some_characters)
78
+ expect(union.get_value).to eq("blah!")
79
+ expect { union.integer32 }.to raise_error(RuntimeError, "integer32 is not union's set field.")
81
80
  end
82
81
 
83
82
  it "should not equate two different unions with different values" do
84
83
  union = SpecNamespace::My_union.new(:integer32, 25)
85
84
  other_union = SpecNamespace::My_union.new(:integer32, 400)
86
- union.should_not == other_union
85
+ expect(union).not_to eq(other_union)
87
86
  end
88
87
 
89
88
  it "should not equate two different unions with different fields" do
90
89
  union = SpecNamespace::My_union.new(:integer32, 25)
91
90
  other_union = SpecNamespace::My_union.new(:other_i32, 25)
92
- union.should_not == other_union
91
+ expect(union).not_to eq(other_union)
93
92
  end
94
93
 
95
94
  it "should inspect properly" do
96
95
  union = SpecNamespace::My_union.new(:integer32, 25)
97
- union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
96
+ expect(union.inspect).to eq("<SpecNamespace::My_union integer32: 25>")
98
97
  end
99
98
 
100
99
  it "should not allow setting with instance_variable_set" do
101
100
  union = SpecNamespace::My_union.new(:integer32, 27)
102
101
  union.instance_variable_set(:@some_characters, "hallo!")
103
- union.get_set_field.should == :integer32
104
- union.get_value.should == 27
105
- lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
102
+ expect(union.get_set_field).to eq(:integer32)
103
+ expect(union.get_value).to eq(27)
104
+ expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
106
105
  end
107
106
 
108
107
  it "should serialize to binary correctly" do
@@ -114,7 +113,7 @@ describe 'Union' do
114
113
 
115
114
  other_union = SpecNamespace::My_union.new(:integer32, 25)
116
115
  other_union.read(proto)
117
- other_union.should == union
116
+ expect(other_union).to eq(union)
118
117
  end
119
118
 
120
119
  it "should serialize to json correctly" do
@@ -126,24 +125,24 @@ describe 'Union' do
126
125
 
127
126
  other_union = SpecNamespace::My_union.new(:integer32, 25)
128
127
  other_union.read(proto)
129
- other_union.should == union
128
+ expect(other_union).to eq(union)
130
129
  end
131
130
 
132
131
  it "should raise when validating unset union" do
133
132
  union = SpecNamespace::My_union.new
134
- lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")
133
+ expect { union.validate }.to raise_error(StandardError, "Union fields are not set.")
135
134
 
136
135
  other_union = SpecNamespace::My_union.new(:integer32, 1)
137
- lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
136
+ expect { other_union.validate }.not_to raise_error
138
137
  end
139
138
 
140
139
  it "should validate an enum field properly" do
141
140
  union = SpecNamespace::TestUnion.new(:enum_field, 3)
142
- union.get_set_field.should == :enum_field
143
- lambda { union.validate }.should raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
141
+ expect(union.get_set_field).to eq(:enum_field)
142
+ expect { union.validate }.to raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
144
143
 
145
144
  other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
146
- lambda { other_union.validate }.should_not raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
145
+ expect { other_union.validate }.not_to raise_error
147
146
  end
148
147
 
149
148
  it "should properly serialize and match structs with a union" do
@@ -158,37 +157,37 @@ describe 'Union' do
158
157
  other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
159
158
  swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
160
159
 
161
- swu2.should_not == swu
160
+ expect(swu2).not_to eq(swu)
162
161
 
163
162
  swu2.read(proto)
164
- swu2.should == swu
163
+ expect(swu2).to eq(swu)
165
164
  end
166
165
 
167
166
  it "should support old style constructor" do
168
167
  union = SpecNamespace::My_union.new(:integer32 => 26)
169
- union.get_set_field.should == :integer32
170
- union.get_value.should == 26
168
+ expect(union.get_set_field).to eq(:integer32)
169
+ expect(union.get_value).to eq(26)
171
170
  end
172
171
 
173
172
  it "should not throw an error when inspected and unset" do
174
- lambda{SpecNamespace::TestUnion.new().inspect}.should_not raise_error
173
+ expect{SpecNamespace::TestUnion.new().inspect}.not_to raise_error
175
174
  end
176
175
 
177
176
  it "should print enum value name when inspected" do
178
- SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
177
+ expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect).to eq("<SpecNamespace::My_union some_enum: ONE (0)>")
179
178
 
180
- SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
179
+ expect(SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect).to eq("<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>")
181
180
  end
182
181
 
183
182
  it "should offer field? methods" do
184
- SpecNamespace::My_union.new.some_enum?.should be_false
185
- SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?.should be_true
186
- SpecNamespace::My_union.new(:im_true => false).im_true?.should be_true
187
- SpecNamespace::My_union.new(:im_true => true).im_true?.should be_true
183
+ expect(SpecNamespace::My_union.new.some_enum?).to be_falsey
184
+ expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?).to be_truthy
185
+ expect(SpecNamespace::My_union.new(:im_true => false).im_true?).to be_truthy
186
+ expect(SpecNamespace::My_union.new(:im_true => true).im_true?).to be_truthy
188
187
  end
189
188
 
190
189
  it "should pretty print binary fields" do
191
- SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
190
+ expect(SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect).to eq("<SpecNamespace::TestUnion binary_field: 010203>")
192
191
  end
193
192
 
194
193
  it "should be comparable" do
@@ -207,7 +206,7 @@ describe 'Union' do
207
206
  for y in 0..3
208
207
  for x in 0..3
209
208
  # puts "#{objs[y].inspect} <=> #{objs[x].inspect} should == #{relationships[y][x]}"
210
- (objs[y] <=> objs[x]).should == relationships[y][x]
209
+ expect(objs[y] <=> objs[x]).to eq(relationships[y][x])
211
210
  end
212
211
  end
213
212
  end