thrift 0.9.2.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/ext/binary_protocol_accelerated.c +12 -12
  3. data/ext/compact_protocol.c +1 -0
  4. data/ext/struct.c +14 -1
  5. data/ext/thrift_native.c +17 -0
  6. data/lib/thrift/multiplexed_processor.rb +76 -0
  7. data/lib/thrift/processor.rb +24 -6
  8. data/lib/thrift/protocol/base_protocol.rb +11 -3
  9. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  10. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  11. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  12. data/lib/thrift/protocol/json_protocol.rb +21 -4
  13. data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
  14. data/lib/thrift/protocol/protocol_decorator.rb +194 -0
  15. data/lib/thrift/server/base_server.rb +8 -2
  16. data/lib/thrift/server/simple_server.rb +5 -1
  17. data/lib/thrift/server/thread_pool_server.rb +5 -1
  18. data/lib/thrift/server/threaded_server.rb +5 -1
  19. data/lib/thrift/transport/base_server_transport.rb +1 -1
  20. data/lib/thrift/transport/base_transport.rb +8 -0
  21. data/lib/thrift/transport/buffered_transport.rb +9 -1
  22. data/lib/thrift/transport/framed_transport.rb +9 -1
  23. data/lib/thrift/transport/http_client_transport.rb +7 -0
  24. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  25. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  26. data/lib/thrift/transport/server_socket.rb +6 -1
  27. data/lib/thrift/transport/socket.rb +21 -17
  28. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  29. data/lib/thrift/transport/ssl_socket.rb +51 -0
  30. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  31. data/lib/thrift/transport/unix_socket.rb +5 -1
  32. data/lib/thrift/union.rb +3 -6
  33. data/lib/thrift.rb +8 -4
  34. data/spec/BaseService.thrift +27 -0
  35. data/spec/ExtendedService.thrift +25 -0
  36. data/spec/base_protocol_spec.rb +79 -71
  37. data/spec/base_transport_spec.rb +155 -117
  38. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  39. data/spec/binary_protocol_spec.rb +16 -8
  40. data/spec/binary_protocol_spec_shared.rb +75 -72
  41. data/spec/bytes_spec.rb +38 -38
  42. data/spec/client_spec.rb +41 -42
  43. data/spec/compact_protocol_spec.rb +32 -17
  44. data/spec/exception_spec.rb +54 -54
  45. data/spec/flat_spec.rb +62 -0
  46. data/spec/http_client_spec.rb +74 -33
  47. data/spec/json_protocol_spec.rb +170 -131
  48. data/spec/namespaced_spec.rb +10 -5
  49. data/spec/nonblocking_server_spec.rb +16 -16
  50. data/spec/processor_spec.rb +26 -26
  51. data/spec/serializer_spec.rb +20 -20
  52. data/spec/server_socket_spec.rb +27 -22
  53. data/spec/server_spec.rb +91 -51
  54. data/spec/socket_spec.rb +23 -16
  55. data/spec/socket_spec_shared.rb +31 -31
  56. data/spec/spec_helper.rb +9 -1
  57. data/spec/ssl_server_socket_spec.rb +34 -0
  58. data/spec/ssl_socket_spec.rb +78 -0
  59. data/spec/struct_nested_containers_spec.rb +24 -24
  60. data/spec/struct_spec.rb +120 -120
  61. data/spec/thin_http_server_spec.rb +18 -18
  62. data/spec/types_spec.rb +56 -53
  63. data/spec/union_spec.rb +51 -40
  64. data/spec/unix_socket_spec.rb +43 -34
  65. metadata +205 -143
data/spec/types_spec.rb CHANGED
@@ -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
data/spec/union_spec.rb CHANGED
@@ -24,73 +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
+ end
50
+
51
+ it "should raise for wrong set field when hash initialized and type checking is off" do
52
+ Thrift.type_checking = false
53
+ union = SpecNamespace::My_union.new({incorrect_field: :incorrect})
54
+ expect { Thrift::Serializer.new.serialize(union) }.to raise_error(RuntimeError, "set_field is not valid for this union!")
49
55
  end
50
56
 
51
57
  it "should not be equal to nil" do
52
58
  union = SpecNamespace::My_union.new
53
- union.should_not == nil
59
+ expect(union).not_to eq(nil)
60
+ end
61
+
62
+ it "should not be equal with an empty String" do
63
+ union = SpecNamespace::My_union.new
64
+ expect(union).not_to eq('')
54
65
  end
55
66
 
56
67
  it "should not equate two different unions, i32 vs. string" do
57
68
  union = SpecNamespace::My_union.new(:integer32, 25)
58
69
  other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
59
- union.should_not == other_union
70
+ expect(union).not_to eq(other_union)
60
71
  end
61
72
 
62
73
  it "should properly reset setfield and setvalue" do
63
74
  union = SpecNamespace::My_union.new(:integer32, 25)
64
- union.get_set_field.should == :integer32
75
+ expect(union.get_set_field).to eq(:integer32)
65
76
  union.some_characters = "blah!"
66
- union.get_set_field.should == :some_characters
67
- union.get_value.should == "blah!"
68
- 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.")
69
80
  end
70
81
 
71
82
  it "should not equate two different unions with different values" do
72
83
  union = SpecNamespace::My_union.new(:integer32, 25)
73
84
  other_union = SpecNamespace::My_union.new(:integer32, 400)
74
- union.should_not == other_union
85
+ expect(union).not_to eq(other_union)
75
86
  end
76
87
 
77
88
  it "should not equate two different unions with different fields" do
78
89
  union = SpecNamespace::My_union.new(:integer32, 25)
79
90
  other_union = SpecNamespace::My_union.new(:other_i32, 25)
80
- union.should_not == other_union
91
+ expect(union).not_to eq(other_union)
81
92
  end
82
93
 
83
94
  it "should inspect properly" do
84
95
  union = SpecNamespace::My_union.new(:integer32, 25)
85
- union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
96
+ expect(union.inspect).to eq("<SpecNamespace::My_union integer32: 25>")
86
97
  end
87
98
 
88
99
  it "should not allow setting with instance_variable_set" do
89
100
  union = SpecNamespace::My_union.new(:integer32, 27)
90
101
  union.instance_variable_set(:@some_characters, "hallo!")
91
- union.get_set_field.should == :integer32
92
- union.get_value.should == 27
93
- 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.")
94
105
  end
95
106
 
96
107
  it "should serialize to binary correctly" do
@@ -102,7 +113,7 @@ describe 'Union' do
102
113
 
103
114
  other_union = SpecNamespace::My_union.new(:integer32, 25)
104
115
  other_union.read(proto)
105
- other_union.should == union
116
+ expect(other_union).to eq(union)
106
117
  end
107
118
 
108
119
  it "should serialize to json correctly" do
@@ -114,24 +125,24 @@ describe 'Union' do
114
125
 
115
126
  other_union = SpecNamespace::My_union.new(:integer32, 25)
116
127
  other_union.read(proto)
117
- other_union.should == union
128
+ expect(other_union).to eq(union)
118
129
  end
119
130
 
120
131
  it "should raise when validating unset union" do
121
132
  union = SpecNamespace::My_union.new
122
- 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.")
123
134
 
124
135
  other_union = SpecNamespace::My_union.new(:integer32, 1)
125
- lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
136
+ expect { other_union.validate }.not_to raise_error
126
137
  end
127
138
 
128
139
  it "should validate an enum field properly" do
129
140
  union = SpecNamespace::TestUnion.new(:enum_field, 3)
130
- union.get_set_field.should == :enum_field
131
- 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!")
132
143
 
133
144
  other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
134
- 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
135
146
  end
136
147
 
137
148
  it "should properly serialize and match structs with a union" do
@@ -146,37 +157,37 @@ describe 'Union' do
146
157
  other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
147
158
  swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
148
159
 
149
- swu2.should_not == swu
160
+ expect(swu2).not_to eq(swu)
150
161
 
151
162
  swu2.read(proto)
152
- swu2.should == swu
163
+ expect(swu2).to eq(swu)
153
164
  end
154
165
 
155
166
  it "should support old style constructor" do
156
167
  union = SpecNamespace::My_union.new(:integer32 => 26)
157
- union.get_set_field.should == :integer32
158
- union.get_value.should == 26
168
+ expect(union.get_set_field).to eq(:integer32)
169
+ expect(union.get_value).to eq(26)
159
170
  end
160
171
 
161
172
  it "should not throw an error when inspected and unset" do
162
- lambda{SpecNamespace::TestUnion.new().inspect}.should_not raise_error
173
+ expect{SpecNamespace::TestUnion.new().inspect}.not_to raise_error
163
174
  end
164
175
 
165
176
  it "should print enum value name when inspected" do
166
- 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)>")
167
178
 
168
- 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)]}>")
169
180
  end
170
181
 
171
182
  it "should offer field? methods" do
172
- SpecNamespace::My_union.new.some_enum?.should be_false
173
- SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?.should be_true
174
- SpecNamespace::My_union.new(:im_true => false).im_true?.should be_true
175
- 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
176
187
  end
177
188
 
178
189
  it "should pretty print binary fields" do
179
- 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>")
180
191
  end
181
192
 
182
193
  it "should be comparable" do
@@ -195,7 +206,7 @@ describe 'Union' do
195
206
  for y in 0..3
196
207
  for x in 0..3
197
208
  # puts "#{objs[y].inspect} <=> #{objs[x].inspect} should == #{relationships[y][x]}"
198
- (objs[y] <=> objs[x]).should == relationships[y][x]
209
+ expect(objs[y] <=> objs[x]).to eq(relationships[y][x])
199
210
  end
200
211
  end
201
212
  end
@@ -26,21 +26,26 @@ describe 'UNIXSocket' do
26
26
  before(:each) do
27
27
  @path = '/tmp/thrift_spec_socket'
28
28
  @socket = Thrift::UNIXSocket.new(@path)
29
- @handle = mock("Handle", :closed? => false)
30
- @handle.stub!(:close)
31
- ::UNIXSocket.stub!(:new).and_return(@handle)
29
+ @handle = double("Handle", :closed? => false)
30
+ allow(@handle).to receive(:close)
31
+ allow(::UNIXSocket).to receive(:new).and_return(@handle)
32
32
  end
33
33
 
34
34
  it_should_behave_like "a socket"
35
35
 
36
36
  it "should raise a TransportException when it cannot open a socket" do
37
- ::UNIXSocket.should_receive(:new).and_raise(StandardError)
38
- lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
37
+ expect(::UNIXSocket).to receive(:new).and_raise(StandardError)
38
+ expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
39
39
  end
40
40
 
41
41
  it "should accept an optional timeout" do
42
- ::UNIXSocket.stub!(:new)
43
- Thrift::UNIXSocket.new(@path, 5).timeout.should == 5
42
+ allow(::UNIXSocket).to receive(:new)
43
+ expect(Thrift::UNIXSocket.new(@path, 5).timeout).to eq(5)
44
+ end
45
+
46
+ it "should provide a reasonable to_s" do
47
+ allow(::UNIXSocket).to receive(:new)
48
+ expect(Thrift::UNIXSocket.new(@path).to_s).to eq("domain(#{@path})")
44
49
  end
45
50
  end
46
51
 
@@ -51,57 +56,61 @@ describe 'UNIXSocket' do
51
56
  end
52
57
 
53
58
  it "should create a handle when calling listen" do
54
- UNIXServer.should_receive(:new).with(@path)
59
+ expect(UNIXServer).to receive(:new).with(@path)
55
60
  @socket.listen
56
61
  end
57
62
 
58
63
  it "should create a Thrift::UNIXSocket to wrap accepted sockets" do
59
- handle = mock("UNIXServer")
60
- UNIXServer.should_receive(:new).with(@path).and_return(handle)
64
+ handle = double("UNIXServer")
65
+ expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
61
66
  @socket.listen
62
- sock = mock("sock")
63
- handle.should_receive(:accept).and_return(sock)
64
- trans = mock("UNIXSocket")
65
- Thrift::UNIXSocket.should_receive(:new).and_return(trans)
66
- trans.should_receive(:handle=).with(sock)
67
- @socket.accept.should == trans
67
+ sock = double("sock")
68
+ expect(handle).to receive(:accept).and_return(sock)
69
+ trans = double("UNIXSocket")
70
+ expect(Thrift::UNIXSocket).to receive(:new).and_return(trans)
71
+ expect(trans).to receive(:handle=).with(sock)
72
+ expect(@socket.accept).to eq(trans)
68
73
  end
69
74
 
70
75
  it "should close the handle when closed" do
71
- handle = mock("UNIXServer", :closed? => false)
72
- UNIXServer.should_receive(:new).with(@path).and_return(handle)
76
+ handle = double("UNIXServer", :closed? => false)
77
+ expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
73
78
  @socket.listen
74
- handle.should_receive(:close)
75
- File.stub!(:delete)
79
+ expect(handle).to receive(:close)
80
+ allow(File).to receive(:delete)
76
81
  @socket.close
77
82
  end
78
83
 
79
84
  it "should delete the socket when closed" do
80
- handle = mock("UNIXServer", :closed? => false)
81
- UNIXServer.should_receive(:new).with(@path).and_return(handle)
85
+ handle = double("UNIXServer", :closed? => false)
86
+ expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
82
87
  @socket.listen
83
- handle.stub!(:close)
84
- File.should_receive(:delete).with(@path)
88
+ allow(handle).to receive(:close)
89
+ expect(File).to receive(:delete).with(@path)
85
90
  @socket.close
86
91
  end
87
92
 
88
93
  it "should return nil when accepting if there is no handle" do
89
- @socket.accept.should be_nil
94
+ expect(@socket.accept).to be_nil
90
95
  end
91
96
 
92
97
  it "should return true for closed? when appropriate" do
93
- handle = mock("UNIXServer", :closed? => false)
94
- UNIXServer.stub!(:new).and_return(handle)
95
- File.stub!(:delete)
98
+ handle = double("UNIXServer", :closed? => false)
99
+ allow(UNIXServer).to receive(:new).and_return(handle)
100
+ allow(File).to receive(:delete)
96
101
  @socket.listen
97
- @socket.should_not be_closed
98
- handle.stub!(:close)
102
+ expect(@socket).not_to be_closed
103
+ allow(handle).to receive(:close)
99
104
  @socket.close
100
- @socket.should be_closed
105
+ expect(@socket).to be_closed
101
106
  @socket.listen
102
- @socket.should_not be_closed
103
- handle.stub!(:closed?).and_return(true)
104
- @socket.should be_closed
107
+ expect(@socket).not_to be_closed
108
+ allow(handle).to receive(:closed?).and_return(true)
109
+ expect(@socket).to be_closed
110
+ end
111
+
112
+ it "should provide a reasonable to_s" do
113
+ expect(@socket.to_s).to eq("domain(#{@path})")
105
114
  end
106
115
  end
107
116
  end