summaryrefslogtreecommitdiff
path: root/lib/rb
diff options
context:
space:
mode:
authorJames E. King III <jking@apache.org>2018-03-22 20:50:23 -0400
committerJames E. King III <jking@apache.org>2018-03-23 15:16:47 -0400
commit272470790ad6db791bd6f9db399b2cd2d5879f74 (patch)
treedbe3b8e96a336e05b65887962219d30e6ac48a02 /lib/rb
parentdab4529f730c033e1ac037e820176667f5c422fd (diff)
downloadthrift-272470790ad6db791bd6f9db399b2cd2d5879f74.tar.gz
THRIFT-4342: update ruby tests to use rspec 3, updated all dependencies for ruby
Client: rb
Diffstat (limited to 'lib/rb')
-rw-r--r--lib/rb/spec/base_protocol_spec.rb146
-rw-r--r--lib/rb/spec/base_transport_spec.rb262
-rw-r--r--lib/rb/spec/binary_protocol_accelerated_spec.rb4
-rw-r--r--lib/rb/spec/binary_protocol_spec.rb20
-rw-r--r--lib/rb/spec/binary_protocol_spec_shared.rb143
-rw-r--r--lib/rb/spec/bytes_spec.rb76
-rw-r--r--lib/rb/spec/client_spec.rb83
-rw-r--r--lib/rb/spec/compact_protocol_spec.rb22
-rw-r--r--lib/rb/spec/exception_spec.rb108
-rw-r--r--lib/rb/spec/flat_spec.rb10
-rw-r--r--lib/rb/spec/http_client_spec.rb76
-rw-r--r--lib/rb/spec/json_protocol_spec.rb280
-rw-r--r--lib/rb/spec/namespaced_spec.rb10
-rw-r--r--lib/rb/spec/nonblocking_server_spec.rb32
-rw-r--r--lib/rb/spec/processor_spec.rb52
-rw-r--r--lib/rb/spec/serializer_spec.rb40
-rw-r--r--lib/rb/spec/server_socket_spec.rb46
-rw-r--r--lib/rb/spec/server_spec.rb140
-rw-r--r--lib/rb/spec/socket_spec.rb34
-rw-r--r--lib/rb/spec/socket_spec_shared.rb62
-rw-r--r--lib/rb/spec/ssl_server_socket_spec.rb2
-rw-r--r--lib/rb/spec/ssl_socket_spec.rb46
-rw-r--r--lib/rb/spec/struct_nested_containers_spec.rb48
-rw-r--r--lib/rb/spec/struct_spec.rb240
-rw-r--r--lib/rb/spec/thin_http_server_spec.rb36
-rw-r--r--lib/rb/spec/types_spec.rb105
-rw-r--r--lib/rb/spec/union_spec.rb84
-rw-r--r--lib/rb/spec/unix_socket_spec.rb74
-rw-r--r--lib/rb/thrift.gemspec15
29 files changed, 1152 insertions, 1144 deletions
diff --git a/lib/rb/spec/base_protocol_spec.rb b/lib/rb/spec/base_protocol_spec.rb
index d31e81193..eca936b23 100644
--- a/lib/rb/spec/base_protocol_spec.rb
+++ b/lib/rb/spec/base_protocol_spec.rb
@@ -22,7 +22,7 @@ require 'spec_helper'
describe 'BaseProtocol' do
before(:each) do
- @trans = mock("MockTransport")
+ @trans = double("MockTransport")
@prot = Thrift::BaseProtocol.new(@trans)
end
@@ -30,38 +30,38 @@ describe 'BaseProtocol' do
# most of the methods are stubs, so we can ignore them
it "should provide a reasonable to_s" do
- @trans.should_receive(:to_s).once.and_return("trans")
- @prot.to_s.should == "trans"
+ expect(@trans).to receive(:to_s).once.and_return("trans")
+ expect(@prot.to_s).to eq("trans")
end
it "should make trans accessible" do
- @prot.trans.should eql(@trans)
+ expect(@prot.trans).to eql(@trans)
end
it 'should write out a field nicely (deprecated write_field signature)' do
- @prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
- @prot.should_receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
- @prot.should_receive(:write_field_end).ordered
+ expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
+ expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
+ expect(@prot).to receive(:write_field_end).ordered
@prot.write_field('field', 'type', 'fid', 'value')
end
it 'should write out a field nicely' do
- @prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
- @prot.should_receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
- @prot.should_receive(:write_field_end).ordered
+ expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
+ expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
+ expect(@prot).to receive(:write_field_end).ordered
@prot.write_field({:name => 'field', :type => 'type', :binary => false}, 'fid', 'value')
end
it 'should write out the different types (deprecated write_type signature)' do
- @prot.should_receive(:write_bool).with('bool').ordered
- @prot.should_receive(:write_byte).with('byte').ordered
- @prot.should_receive(:write_double).with('double').ordered
- @prot.should_receive(:write_i16).with('i16').ordered
- @prot.should_receive(:write_i32).with('i32').ordered
- @prot.should_receive(:write_i64).with('i64').ordered
- @prot.should_receive(:write_string).with('string').ordered
- struct = mock('Struct')
- struct.should_receive(:write).with(@prot).ordered
+ expect(@prot).to receive(:write_bool).with('bool').ordered
+ expect(@prot).to receive(:write_byte).with('byte').ordered
+ expect(@prot).to receive(:write_double).with('double').ordered
+ expect(@prot).to receive(:write_i16).with('i16').ordered
+ expect(@prot).to receive(:write_i32).with('i32').ordered
+ expect(@prot).to receive(:write_i64).with('i64').ordered
+ expect(@prot).to receive(:write_string).with('string').ordered
+ struct = double('Struct')
+ expect(struct).to receive(:write).with(@prot).ordered
@prot.write_type(Thrift::Types::BOOL, 'bool')
@prot.write_type(Thrift::Types::BYTE, 'byte')
@prot.write_type(Thrift::Types::DOUBLE, 'double')
@@ -77,16 +77,16 @@ describe 'BaseProtocol' do
end
it 'should write out the different types' do
- @prot.should_receive(:write_bool).with('bool').ordered
- @prot.should_receive(:write_byte).with('byte').ordered
- @prot.should_receive(:write_double).with('double').ordered
- @prot.should_receive(:write_i16).with('i16').ordered
- @prot.should_receive(:write_i32).with('i32').ordered
- @prot.should_receive(:write_i64).with('i64').ordered
- @prot.should_receive(:write_string).with('string').ordered
- @prot.should_receive(:write_binary).with('binary').ordered
- struct = mock('Struct')
- struct.should_receive(:write).with(@prot).ordered
+ expect(@prot).to receive(:write_bool).with('bool').ordered
+ expect(@prot).to receive(:write_byte).with('byte').ordered
+ expect(@prot).to receive(:write_double).with('double').ordered
+ expect(@prot).to receive(:write_i16).with('i16').ordered
+ expect(@prot).to receive(:write_i32).with('i32').ordered
+ expect(@prot).to receive(:write_i64).with('i64').ordered
+ expect(@prot).to receive(:write_string).with('string').ordered
+ expect(@prot).to receive(:write_binary).with('binary').ordered
+ struct = double('Struct')
+ expect(struct).to receive(:write).with(@prot).ordered
@prot.write_type({:type => Thrift::Types::BOOL}, 'bool')
@prot.write_type({:type => Thrift::Types::BYTE}, 'byte')
@prot.write_type({:type => Thrift::Types::DOUBLE}, 'double')
@@ -103,13 +103,13 @@ describe 'BaseProtocol' do
end
it 'should read the different types (deprecated read_type signature)' do
- @prot.should_receive(:read_bool).ordered
- @prot.should_receive(:read_byte).ordered
- @prot.should_receive(:read_i16).ordered
- @prot.should_receive(:read_i32).ordered
- @prot.should_receive(:read_i64).ordered
- @prot.should_receive(:read_double).ordered
- @prot.should_receive(:read_string).ordered
+ expect(@prot).to receive(:read_bool).ordered
+ expect(@prot).to receive(:read_byte).ordered
+ expect(@prot).to receive(:read_i16).ordered
+ expect(@prot).to receive(:read_i32).ordered
+ expect(@prot).to receive(:read_i64).ordered
+ expect(@prot).to receive(:read_double).ordered
+ expect(@prot).to receive(:read_string).ordered
@prot.read_type(Thrift::Types::BOOL)
@prot.read_type(Thrift::Types::BYTE)
@prot.read_type(Thrift::Types::I16)
@@ -125,14 +125,14 @@ describe 'BaseProtocol' do
end
it 'should read the different types' do
- @prot.should_receive(:read_bool).ordered
- @prot.should_receive(:read_byte).ordered
- @prot.should_receive(:read_i16).ordered
- @prot.should_receive(:read_i32).ordered
- @prot.should_receive(:read_i64).ordered
- @prot.should_receive(:read_double).ordered
- @prot.should_receive(:read_string).ordered
- @prot.should_receive(:read_binary).ordered
+ expect(@prot).to receive(:read_bool).ordered
+ expect(@prot).to receive(:read_byte).ordered
+ expect(@prot).to receive(:read_i16).ordered
+ expect(@prot).to receive(:read_i32).ordered
+ expect(@prot).to receive(:read_i64).ordered
+ expect(@prot).to receive(:read_double).ordered
+ expect(@prot).to receive(:read_string).ordered
+ expect(@prot).to receive(:read_binary).ordered
@prot.read_type({:type => Thrift::Types::BOOL})
@prot.read_type({:type => Thrift::Types::BYTE})
@prot.read_type({:type => Thrift::Types::I16})
@@ -149,13 +149,13 @@ describe 'BaseProtocol' do
end
it "should skip the basic types" do
- @prot.should_receive(:read_bool).ordered
- @prot.should_receive(:read_byte).ordered
- @prot.should_receive(:read_i16).ordered
- @prot.should_receive(:read_i32).ordered
- @prot.should_receive(:read_i64).ordered
- @prot.should_receive(:read_double).ordered
- @prot.should_receive(:read_string).ordered
+ expect(@prot).to receive(:read_bool).ordered
+ expect(@prot).to receive(:read_byte).ordered
+ expect(@prot).to receive(:read_i16).ordered
+ expect(@prot).to receive(:read_i32).ordered
+ expect(@prot).to receive(:read_i64).ordered
+ expect(@prot).to receive(:read_double).ordered
+ expect(@prot).to receive(:read_string).ordered
@prot.skip(Thrift::Types::BOOL)
@prot.skip(Thrift::Types::BYTE)
@prot.skip(Thrift::Types::I16)
@@ -168,47 +168,47 @@ describe 'BaseProtocol' do
it "should skip structs" do
real_skip = @prot.method(:skip)
- @prot.should_receive(:read_struct_begin).ordered
- @prot.should_receive(:read_field_begin).exactly(4).times.and_return(
+ expect(@prot).to receive(:read_struct_begin).ordered
+ expect(@prot).to receive(:read_field_begin).exactly(4).times.and_return(
['field 1', Thrift::Types::STRING, 1],
['field 2', Thrift::Types::I32, 2],
['field 3', Thrift::Types::MAP, 3],
[nil, Thrift::Types::STOP, 0]
)
- @prot.should_receive(:read_field_end).exactly(3).times
- @prot.should_receive(:read_string).exactly(3).times
- @prot.should_receive(:read_i32).ordered
- @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
+ expect(@prot).to receive(:read_field_end).exactly(3).times
+ expect(@prot).to receive(:read_string).exactly(3).times
+ expect(@prot).to receive(:read_i32).ordered
+ expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
# @prot.should_receive(:read_string).exactly(2).times
- @prot.should_receive(:read_map_end).ordered
- @prot.should_receive(:read_struct_end).ordered
+ expect(@prot).to receive(:read_map_end).ordered
+ expect(@prot).to receive(:read_struct_end).ordered
real_skip.call(Thrift::Types::STRUCT)
end
it "should skip maps" do
real_skip = @prot.method(:skip)
- @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
- @prot.should_receive(:read_string).ordered
- @prot.should_receive(:read_struct_begin).ordered.and_return(["some_struct"])
- @prot.should_receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
- @prot.should_receive(:read_struct_end).ordered
- @prot.should_receive(:read_map_end).ordered
+ expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
+ expect(@prot).to receive(:read_string).ordered
+ expect(@prot).to receive(:read_struct_begin).ordered.and_return(["some_struct"])
+ expect(@prot).to receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
+ expect(@prot).to receive(:read_struct_end).ordered
+ expect(@prot).to receive(:read_map_end).ordered
real_skip.call(Thrift::Types::MAP)
end
it "should skip sets" do
real_skip = @prot.method(:skip)
- @prot.should_receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
- @prot.should_receive(:read_i64).ordered.exactly(9).times
- @prot.should_receive(:read_set_end)
+ expect(@prot).to receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
+ expect(@prot).to receive(:read_i64).ordered.exactly(9).times
+ expect(@prot).to receive(:read_set_end)
real_skip.call(Thrift::Types::SET)
end
it "should skip lists" do
real_skip = @prot.method(:skip)
- @prot.should_receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
- @prot.should_receive(:read_double).ordered.exactly(11).times
- @prot.should_receive(:read_list_end)
+ expect(@prot).to receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
+ expect(@prot).to receive(:read_double).ordered.exactly(11).times
+ expect(@prot).to receive(:read_list_end)
real_skip.call(Thrift::Types::LIST)
end
end
@@ -216,11 +216,11 @@ describe 'BaseProtocol' do
describe Thrift::BaseProtocolFactory do
it "should raise NotImplementedError" do
# returning nil since Protocol is just an abstract class
- lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
+ expect {Thrift::BaseProtocolFactory.new.get_protocol(double("MockTransport"))}.to raise_error(NotImplementedError)
end
it "should provide a reasonable to_s" do
- Thrift::BaseProtocolFactory.new.to_s.should == "base"
+ expect(Thrift::BaseProtocolFactory.new.to_s).to eq("base")
end
end
end
diff --git a/lib/rb/spec/base_transport_spec.rb b/lib/rb/spec/base_transport_spec.rb
index 0a05df2f0..d2f60aaea 100644
--- a/lib/rb/spec/base_transport_spec.rb
+++ b/lib/rb/spec/base_transport_spec.rb
@@ -24,119 +24,119 @@ describe 'BaseTransport' do
describe Thrift::TransportException do
it "should make type accessible" do
exc = Thrift::TransportException.new(Thrift::TransportException::ALREADY_OPEN, "msg")
- exc.type.should == Thrift::TransportException::ALREADY_OPEN
- exc.message.should == "msg"
+ expect(exc.type).to eq(Thrift::TransportException::ALREADY_OPEN)
+ expect(exc.message).to eq("msg")
end
end
describe Thrift::BaseTransport do
it "should read the specified size" do
transport = Thrift::BaseTransport.new
- transport.should_receive(:read).with(40).ordered.and_return("10 letters")
- transport.should_receive(:read).with(30).ordered.and_return("fifteen letters")
- transport.should_receive(:read).with(15).ordered.and_return("more characters")
- transport.read_all(40).should == "10 lettersfifteen lettersmore characters"
+ expect(transport).to receive(:read).with(40).ordered.and_return("10 letters")
+ expect(transport).to receive(:read).with(30).ordered.and_return("fifteen letters")
+ expect(transport).to receive(:read).with(15).ordered.and_return("more characters")
+ expect(transport.read_all(40)).to eq("10 lettersfifteen lettersmore characters")
end
it "should stub out the rest of the methods" do
# can't test for stubbiness, so just make sure they're defined
[:open?, :open, :close, :read, :write, :flush].each do |sym|
- Thrift::BaseTransport.method_defined?(sym).should be_true
+ expect(Thrift::BaseTransport.method_defined?(sym)).to be_truthy
end
end
it "should alias << to write" do
- Thrift::BaseTransport.instance_method(:<<).should == Thrift::BaseTransport.instance_method(:write)
+ expect(Thrift::BaseTransport.instance_method(:<<)).to eq(Thrift::BaseTransport.instance_method(:write))
end
it "should provide a reasonable to_s" do
- Thrift::BaseTransport.new.to_s.should == "base"
+ expect(Thrift::BaseTransport.new.to_s).to eq("base")
end
end
describe Thrift::BaseServerTransport do
it "should stub out its methods" do
[:listen, :accept, :close].each do |sym|
- Thrift::BaseServerTransport.method_defined?(sym).should be_true
+ expect(Thrift::BaseServerTransport.method_defined?(sym)).to be_truthy
end
end
end
describe Thrift::BaseTransportFactory do
it "should return the transport it's given" do
- transport = mock("Transport")
- Thrift::BaseTransportFactory.new.get_transport(transport).should eql(transport)
+ transport = double("Transport")
+ expect(Thrift::BaseTransportFactory.new.get_transport(transport)).to eql(transport)
end
it "should provide a reasonable to_s" do
- Thrift::BaseTransportFactory.new.to_s.should == "base"
+ expect(Thrift::BaseTransportFactory.new.to_s).to eq("base")
end
end
describe Thrift::BufferedTransport do
it "should provide a to_s that describes the encapsulation" do
- trans = mock("Transport")
- trans.should_receive(:to_s).and_return("mock")
- Thrift::BufferedTransport.new(trans).to_s.should == "buffered(mock)"
+ trans = double("Transport")
+ expect(trans).to receive(:to_s).and_return("mock")
+ expect(Thrift::BufferedTransport.new(trans).to_s).to eq("buffered(mock)")
end
it "should pass through everything but write/flush/read" do
- trans = mock("Transport")
- trans.should_receive(:open?).ordered.and_return("+ open?")
- trans.should_receive(:open).ordered.and_return("+ open")
- trans.should_receive(:flush).ordered # from the close
- trans.should_receive(:close).ordered.and_return("+ close")
+ trans = double("Transport")
+ expect(trans).to receive(:open?).ordered.and_return("+ open?")
+ expect(trans).to receive(:open).ordered.and_return("+ open")
+ expect(trans).to receive(:flush).ordered # from the close
+ expect(trans).to receive(:close).ordered.and_return("+ close")
btrans = Thrift::BufferedTransport.new(trans)
- btrans.open?.should == "+ open?"
- btrans.open.should == "+ open"
- btrans.close.should == "+ close"
+ expect(btrans.open?).to eq("+ open?")
+ expect(btrans.open).to eq("+ open")
+ expect(btrans.close).to eq("+ close")
end
it "should buffer reads in chunks of #{Thrift::BufferedTransport::DEFAULT_BUFFER}" do
- trans = mock("Transport")
- trans.should_receive(:read).with(Thrift::BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
+ trans = double("Transport")
+ expect(trans).to receive(:read).with(Thrift::BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
btrans = Thrift::BufferedTransport.new(trans)
- btrans.read(6).should == "lorum "
- btrans.read(6).should == "ipsum "
- btrans.read(6).should == "dolor "
- btrans.read(6).should == "emet"
+ expect(btrans.read(6)).to eq("lorum ")
+ expect(btrans.read(6)).to eq("ipsum ")
+ expect(btrans.read(6)).to eq("dolor ")
+ expect(btrans.read(6)).to eq("emet")
end
it "should buffer writes and send them on flush" do
- trans = mock("Transport")
+ trans = double("Transport")
btrans = Thrift::BufferedTransport.new(trans)
btrans.write("one/")
btrans.write("two/")
btrans.write("three/")
- trans.should_receive(:write).with("one/two/three/").ordered
- trans.should_receive(:flush).ordered
+ expect(trans).to receive(:write).with("one/two/three/").ordered
+ expect(trans).to receive(:flush).ordered
btrans.flush
end
it "should only send buffered data once" do
- trans = mock("Transport")
+ trans = double("Transport")
btrans = Thrift::BufferedTransport.new(trans)
btrans.write("one/")
btrans.write("two/")
btrans.write("three/")
- trans.should_receive(:write).with("one/two/three/")
- trans.stub!(:flush)
+ expect(trans).to receive(:write).with("one/two/three/")
+ allow(trans).to receive(:flush)
btrans.flush
# Nothing to flush with no data
btrans.flush
end
it "should flush on close" do
- trans = mock("Transport")
- trans.should_receive(:close)
+ trans = double("Transport")
+ expect(trans).to receive(:close)
btrans = Thrift::BufferedTransport.new(trans)
- btrans.should_receive(:flush)
+ expect(btrans).to receive(:flush)
btrans.close
end
it "should not write to socket if there's no data" do
- trans = mock("Transport")
- trans.should_receive(:flush)
+ trans = double("Transport")
+ expect(trans).to receive(:flush)
btrans = Thrift::BufferedTransport.new(trans)
btrans.flush
end
@@ -144,90 +144,90 @@ describe 'BaseTransport' do
describe Thrift::BufferedTransportFactory do
it "should wrap the given transport in a BufferedTransport" do
- trans = mock("Transport")
- btrans = mock("BufferedTransport")
- Thrift::BufferedTransport.should_receive(:new).with(trans).and_return(btrans)
- Thrift::BufferedTransportFactory.new.get_transport(trans).should == btrans
+ trans = double("Transport")
+ btrans = double("BufferedTransport")
+ expect(Thrift::BufferedTransport).to receive(:new).with(trans).and_return(btrans)
+ expect(Thrift::BufferedTransportFactory.new.get_transport(trans)).to eq(btrans)
end
it "should provide a reasonable to_s" do
- Thrift::BufferedTransportFactory.new.to_s.should == "buffered"
+ expect(Thrift::BufferedTransportFactory.new.to_s).to eq("buffered")
end
end
describe Thrift::FramedTransport do
before(:each) do
- @trans = mock("Transport")
+ @trans = double("Transport")
end
it "should provide a to_s that describes the encapsulation" do
- trans = mock("Transport")
- trans.should_receive(:to_s).and_return("mock")
- Thrift::FramedTransport.new(trans).to_s.should == "framed(mock)"
+ trans = double("Transport")
+ expect(trans).to receive(:to_s).and_return("mock")
+ expect(Thrift::FramedTransport.new(trans).to_s).to eq("framed(mock)")
end
it "should pass through open?/open/close" do
ftrans = Thrift::FramedTransport.new(@trans)
- @trans.should_receive(:open?).ordered.and_return("+ open?")
- @trans.should_receive(:open).ordered.and_return("+ open")
- @trans.should_receive(:close).ordered.and_return("+ close")
- ftrans.open?.should == "+ open?"
- ftrans.open.should == "+ open"
- ftrans.close.should == "+ close"
+ expect(@trans).to receive(:open?).ordered.and_return("+ open?")
+ expect(@trans).to receive(:open).ordered.and_return("+ open")
+ expect(@trans).to receive(:close).ordered.and_return("+ close")
+ expect(ftrans.open?).to eq("+ open?")
+ expect(ftrans.open).to eq("+ open")
+ expect(ftrans.close).to eq("+ close")
end
it "should pass through read when read is turned off" do
ftrans = Thrift::FramedTransport.new(@trans, false, true)
- @trans.should_receive(:read).with(17).ordered.and_return("+ read")
- ftrans.read(17).should == "+ read"
+ expect(@trans).to receive(:read).with(17).ordered.and_return("+ read")
+ expect(ftrans.read(17)).to eq("+ read")
end
it "should pass through write/flush when write is turned off" do
ftrans = Thrift::FramedTransport.new(@trans, true, false)
- @trans.should_receive(:write).with("foo").ordered.and_return("+ write")
- @trans.should_receive(:flush).ordered.and_return("+ flush")
- ftrans.write("foo").should == "+ write"
- ftrans.flush.should == "+ flush"
+ expect(@trans).to receive(:write).with("foo").ordered.and_return("+ write")
+ expect(@trans).to receive(:flush).ordered.and_return("+ flush")
+ expect(ftrans.write("foo")).to eq("+ write")
+ expect(ftrans.flush).to eq("+ flush")
end
it "should return a full frame if asked for >= the frame's length" do
frame = "this is a frame"
- @trans.should_receive(:read_all).with(4).and_return("\000\000\000\017")
- @trans.should_receive(:read_all).with(frame.length).and_return(frame)
- Thrift::FramedTransport.new(@trans).read(frame.length + 10).should == frame
+ expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017")
+ expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
+ expect(Thrift::FramedTransport.new(@trans).read(frame.length + 10)).to eq(frame)
end
it "should return slices of the frame when asked for < the frame's length" do
frame = "this is a frame"
- @trans.should_receive(:read_all).with(4).and_return("\000\000\000\017")
- @trans.should_receive(:read_all).with(frame.length).and_return(frame)
+ expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017")
+ expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
ftrans = Thrift::FramedTransport.new(@trans)
- ftrans.read(4).should == "this"
- ftrans.read(4).should == " is "
- ftrans.read(16).should == "a frame"
+ expect(ftrans.read(4)).to eq("this")
+ expect(ftrans.read(4)).to eq(" is ")
+ expect(ftrans.read(16)).to eq("a frame")
end
it "should return nothing if asked for <= 0" do
- Thrift::FramedTransport.new(@trans).read(-2).should == ""
+ expect(Thrift::FramedTransport.new(@trans).read(-2)).to eq("")
end
it "should pull a new frame when the first is exhausted" do
frame = "this is a frame"
frame2 = "yet another frame"
- @trans.should_receive(:read_all).with(4).and_return("\000\000\000\017", "\000\000\000\021")
- @trans.should_receive(:read_all).with(frame.length).and_return(frame)
- @trans.should_receive(:read_all).with(frame2.length).and_return(frame2)
+ expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017", "\000\000\000\021")
+ expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
+ expect(@trans).to receive(:read_all).with(frame2.length).and_return(frame2)
ftrans = Thrift::FramedTransport.new(@trans)
- ftrans.read(4).should == "this"
- ftrans.read(8).should == " is a fr"
- ftrans.read(6).should == "ame"
- ftrans.read(4).should == "yet "
- ftrans.read(16).should == "another frame"
+ expect(ftrans.read(4)).to eq("this")
+ expect(ftrans.read(8)).to eq(" is a fr")
+ expect(ftrans.read(6)).to eq("ame")
+ expect(ftrans.read(4)).to eq("yet ")
+ expect(ftrans.read(16)).to eq("another frame")
end
it "should buffer writes" do
ftrans = Thrift::FramedTransport.new(@trans)
- @trans.should_not_receive(:write)
+ expect(@trans).not_to receive(:write)
ftrans.write("foo")
ftrans.write("bar")
ftrans.write("this is a frame")
@@ -237,15 +237,15 @@ describe 'BaseTransport' do
ftrans = Thrift::FramedTransport.new(@trans)
ftrans.write("foobar", 3)
ftrans.write("barfoo", 1)
- @trans.stub!(:flush)
- @trans.should_receive(:write).with("\000\000\000\004foob")
+ allow(@trans).to receive(:flush)
+ expect(@trans).to receive(:write).with("\000\000\000\004foob")
ftrans.flush
end
it "should flush frames with a 4-byte header" do
ftrans = Thrift::FramedTransport.new(@trans)
- @trans.should_receive(:write).with("\000\000\000\035one/two/three/this is a frame").ordered
- @trans.should_receive(:flush).ordered
+ expect(@trans).to receive(:write).with("\000\000\000\035one/two/three/this is a frame").ordered
+ expect(@trans).to receive(:flush).ordered
ftrans.write("one/")
ftrans.write("two/")
ftrans.write("three/")
@@ -255,25 +255,25 @@ describe 'BaseTransport' do
it "should not flush the same buffered data twice" do
ftrans = Thrift::FramedTransport.new(@trans)
- @trans.should_receive(:write).with("\000\000\000\007foo/bar")
- @trans.stub!(:flush)
+ expect(@trans).to receive(:write).with("\000\000\000\007foo/bar")
+ allow(@trans).to receive(:flush)
ftrans.write("foo")
ftrans.write("/bar")
ftrans.flush
- @trans.should_receive(:write).with("\000\000\000\000")
+ expect(@trans).to receive(:write).with("\000\000\000\000")
ftrans.flush
end
end
describe Thrift::FramedTransportFactory do
it "should wrap the given transport in a FramedTransport" do
- trans = mock("Transport")
- Thrift::FramedTransport.should_receive(:new).with(trans)
+ trans = double("Transport")
+ expect(Thrift::FramedTransport).to receive(:new).with(trans)
Thrift::FramedTransportFactory.new.get_transport(trans)
end
it "should provide a reasonable to_s" do
- Thrift::FramedTransportFactory.new.to_s.should == "framed"
+ expect(Thrift::FramedTransportFactory.new.to_s).to eq("framed")
end
end
@@ -283,105 +283,105 @@ describe 'BaseTransport' do
end
it "should provide a reasonable to_s" do
- @buffer.to_s.should == "memory"
+ expect(@buffer.to_s).to eq("memory")
end
it "should accept a buffer on input and use it directly" do
s = "this is a test"
@buffer = Thrift::MemoryBufferTransport.new(s)
- @buffer.read(4).should == "this"
+ expect(@buffer.read(4)).to eq("this")
s.slice!(-4..-1)
- @buffer.read(@buffer.available).should == " is a "
+ expect(@buffer.read(@buffer.available)).to eq(" is a ")
end
it "should always remain open" do
- @buffer.should be_open
+ expect(@buffer).to be_open
@buffer.close
- @buffer.should be_open
+ expect(@buffer).to be_open
end
it "should respond to peek and available" do
@buffer.write "some data"
- @buffer.peek.should be_true
- @buffer.available.should == 9
+ expect(@buffer.peek).to be_truthy
+ expect(@buffer.available).to eq(9)
@buffer.read(4)
- @buffer.peek.should be_true
- @buffer.available.should == 5
+ expect(@buffer.peek).to be_truthy
+ expect(@buffer.available).to eq(5)
@buffer.read(5)
- @buffer.peek.should be_false
- @buffer.available.should == 0
+ expect(@buffer.peek).to be_falsey
+ expect(@buffer.available).to eq(0)
end
it "should be able to reset the buffer" do
@buffer.write "test data"
@buffer.reset_buffer("foobar")
- @buffer.available.should == 6
- @buffer.read(@buffer.available).should == "foobar"
+ expect(@buffer.available).to eq(6)
+ expect(@buffer.read(@buffer.available)).to eq("foobar")
@buffer.reset_buffer
- @buffer.available.should == 0
+ expect(@buffer.available).to eq(0)
end
it "should copy the given string when resetting the buffer" do
s = "this is a test"
@buffer.reset_buffer(s)
- @buffer.available.should == 14
+ expect(@buffer.available).to eq(14)
@buffer.read(10)
- @buffer.available.should == 4
- s.should == "this is a test"
+ expect(@buffer.available).to eq(4)
+ expect(s).to eq("this is a test")
end
it "should return from read what was given in write" do
@buffer.write "test data"
- @buffer.read(4).should == "test"
- @buffer.read(@buffer.available).should == " data"
+ expect(@buffer.read(4)).to eq("test")
+ expect(@buffer.read(@buffer.available)).to eq(" data")
@buffer.write "foo"
@buffer.write " bar"
- @buffer.read(@buffer.available).should == "foo bar"
+ expect(@buffer.read(@buffer.available)).to eq("foo bar")
end
it "should throw an EOFError when there isn't enough data in the buffer" do
@buffer.reset_buffer("")
- lambda{@buffer.read(1)}.should raise_error(EOFError)
+ expect{@buffer.read(1)}.to raise_error(EOFError)
@buffer.reset_buffer("1234")
- lambda{@buffer.read(5)}.should raise_error(EOFError)
+ expect{@buffer.read(5)}.to raise_error(EOFError)
end
end
describe Thrift::IOStreamTransport do
before(:each) do
- @input = mock("Input", :closed? => false)
- @output = mock("Output", :closed? => false)
+ @input = double("Input", :closed? => false)
+ @output = double("Output", :closed? => false)
@trans = Thrift::IOStreamTransport.new(@input, @output)
end
it "should provide a reasonable to_s" do
- @input.should_receive(:to_s).and_return("mock_input")
- @output.should_receive(:to_s).and_return("mock_output")
- @trans.to_s.should == "iostream(input=mock_input,output=mock_output)"
+ expect(@input).to receive(:to_s).and_return("mock_input")
+ expect(@output).to receive(:to_s).and_return("mock_output")
+ expect(@trans.to_s).to eq("iostream(input=mock_input,output=mock_output)")
end
it "should be open as long as both input or output are open" do
- @trans.should be_open
- @input.stub!(:closed?).and_return(true)
- @trans.should be_open
- @input.stub!(:closed?).and_return(false)
- @output.stub!(:closed?).and_return(true)
- @trans.should be_open
- @input.stub!(:closed?).and_return(true)
- @trans.should_not be_open
+ expect(@trans).to be_open
+ allow(@input).to receive(:closed?).and_return(true)
+ expect(@trans).to be_open
+ allow(@input).to receive(:closed?).and_return(false)
+ allow(@output).to receive(:closed?).and_return(true)
+ expect(@trans).to be_open
+ allow(@input).to receive(:closed?).and_return(true)
+ expect(@trans).not_to be_open
end
it "should pass through read/write to input/output" do
- @input.should_receive(:read).with(17).and_return("+ read")
- @output.should_receive(:write).with("foobar").and_return("+ write")
- @trans.read(17).should == "+ read"
- @trans.write("foobar").should == "+ write"
+ expect(@input).to receive(:read).with(17).and_return("+ read")
+ expect(@output).to receive(:write).with("foobar").and_return("+ write")
+ expect(@trans.read(17)).to eq("+ read")
+ expect(@trans.write("foobar")).to eq("+ write")
end
it "should close both input and output when closed" do
- @input.should_receive(:close)
- @output.should_receive(:close)
+ expect(@input).to receive(:close)
+ expect(@output).to receive(:close)
@trans.close
end
end
diff --git a/lib/rb/spec/binary_protocol_accelerated_spec.rb b/lib/rb/spec/binary_protocol_accelerated_spec.rb
index d49404a2d..b2cd04bec 100644
--- a/lib/rb/spec/binary_protocol_accelerated_spec.rb
+++ b/lib/rb/spec/binary_protocol_accelerated_spec.rb
@@ -33,11 +33,11 @@ if defined? Thrift::BinaryProtocolAccelerated
describe Thrift::BinaryProtocolAcceleratedFactory do
it "should create a BinaryProtocolAccelerated" do
- Thrift::BinaryProtocolAcceleratedFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::BinaryProtocolAccelerated)
+ expect(Thrift::BinaryProtocolAcceleratedFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::BinaryProtocolAccelerated)
end
it "should provide a reasonable to_s" do
- Thrift::BinaryProtocolAcceleratedFactory.new.to_s.should == "binary-accel"
+ expect(Thrift::BinaryProtocolAcceleratedFactory.new.to_s).to eq("binary-accel")
end
end
end
diff --git a/lib/rb/spec/binary_protocol_spec.rb b/lib/rb/spec/binary_protocol_spec.rb
index cccfc48d4..065f5ce29 100644
--- a/lib/rb/spec/binary_protocol_spec.rb
+++ b/lib/rb/spec/binary_protocol_spec.rb
@@ -38,37 +38,37 @@ describe 'BinaryProtocol' do
it "should read a message header" do
@trans.write([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY].pack('N'))
@trans.write([42].pack('N'))
- @prot.should_receive(:read_string).and_return('testMessage')
- @prot.read_message_begin.should == ['testMessage', Thrift::MessageTypes::REPLY, 42]
+ expect(@prot).to receive(:read_string).and_return('testMessage')
+ expect(@prot.read_message_begin).to eq(['testMessage', Thrift::MessageTypes::REPLY, 42])
end
it "should raise an exception if the message header has the wrong version" do
- @prot.should_receive(:read_i32).and_return(-1)
- lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
+ expect(@prot).to receive(:read_i32).and_return(-1)
+ expect { @prot.read_message_begin }.to raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
e.type == Thrift::ProtocolException::BAD_VERSION
end
end
it "should raise an exception if the message header does not exist and strict_read is enabled" do
- @prot.should_receive(:read_i32).and_return(42)
- @prot.should_receive(:strict_read).and_return(true)
- lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'No version identifier, old protocol client?') do |e|
+ expect(@prot).to receive(:read_i32).and_return(42)
+ expect(@prot).to receive(:strict_read).and_return(true)
+ expect { @prot.read_message_begin }.to raise_error(Thrift::ProtocolException, 'No version identifier, old protocol client?') do |e|
e.type == Thrift::ProtocolException::BAD_VERSION
end
end
it "should provide a reasonable to_s" do
- @prot.to_s.should == "binary(memory)"
+ expect(@prot.to_s).to eq("binary(memory)")
end
end
describe Thrift::BinaryProtocolFactory do
it "should create a BinaryProtocol" do
- Thrift::BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::BinaryProtocol)
+ expect(Thrift::BinaryProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::BinaryProtocol)
end
it "should provide a reasonable to_s" do
- Thrift::BinaryProtocolFactory.new.to_s.should == "binary"
+ expect(Thrift::BinaryProtocolFactory.new.to_s).to eq("binary")
end
end
end
diff --git a/lib/rb/spec/binary_protocol_spec_shared.rb b/lib/rb/spec/binary_protocol_spec_shared.rb
index 7a9d02872..58d65f040 100644
--- a/lib/rb/spec/binary_protocol_spec_shared.rb
+++ b/lib/rb/spec/binary_protocol_spec_shared.rb
@@ -27,34 +27,34 @@ shared_examples_for 'a binary protocol' do
end
it "should define the proper VERSION_1, VERSION_MASK AND TYPE_MASK" do
- protocol_class.const_get(:VERSION_MASK).should == 0xffff0000
- protocol_class.const_get(:VERSION_1).should == 0x80010000
- protocol_class.const_get(:TYPE_MASK).should == 0x000000ff
+ expect(protocol_class.const_get(:VERSION_MASK)).to eq(0xffff0000)
+ expect(protocol_class.const_get(:VERSION_1)).to eq(0x80010000)
+ expect(protocol_class.const_get(:TYPE_MASK)).to eq(0x000000ff)
end
it "should make strict_read readable" do
- @prot.strict_read.should eql(true)
+ expect(@prot.strict_read).to eql(true)
end
it "should make strict_write readable" do
- @prot.strict_write.should eql(true)
+ expect(@prot.strict_write).to eql(true)
end
it "should write the message header" do
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
- @trans.read(@trans.available).should == [protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N")
+ expect(@trans.read(@trans.available)).to eq([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N"))
end
it "should write the message header without version when writes are not strict" do
@prot = protocol_class.new(@trans, true, false) # no strict write
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
- @trans.read(@trans.available).should == "\000\000\000\vtestMessage\001\000\000\000\021"
+ expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
end
it "should write the message header with a version when writes are strict" do
@prot = protocol_class.new(@trans) # strict write
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
- @trans.read(@trans.available).should == "\200\001\000\001\000\000\000\vtestMessage\000\000\000\021"
+ expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
end
@@ -62,64 +62,67 @@ shared_examples_for 'a binary protocol' do
it "should write the field header" do
@prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
- @trans.read(@trans.available).should == [Thrift::Types::DOUBLE, 3].pack("cn")
+ expect(@trans.read(@trans.available)).to eq([Thrift::Types::DOUBLE, 3].pack("cn"))
end
# field footer is a noop
it "should write the STOP field" do
@prot.write_field_stop
- @trans.read(1).should == "\000"
+ expect(@trans.read(1)).to eq("\000")
end
it "should write the map header" do
@prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
- @trans.read(@trans.available).should == [Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN");
+ expect(@trans.read(@trans.available)).to eq([Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN"));
end
# map footer is a noop
it "should write the list header" do
@prot.write_list_begin(Thrift::Types::I16, 42)
- @trans.read(@trans.available).should == [Thrift::Types::I16, 42].pack("cN")
+ expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
end
# list footer is a noop
it "should write the set header" do
@prot.write_set_begin(Thrift::Types::I16, 42)
- @trans.read(@trans.available).should == [Thrift::Types::I16, 42].pack("cN")
+ expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
end
it "should write a bool" do
@prot.write_bool(true)
@prot.write_bool(false)
- @trans.read(@trans.available).should == "\001\000"
+ expect(@trans.read(@trans.available)).to eq("\001\000")
end
it "should treat a nil bool as false" do
@prot.write_bool(nil)
- @trans.read(1).should == "\000"
+ expect(@trans.read(1)).to eq("\000")
end
it "should write a byte" do
# byte is small enough, let's check -128..127
(-128..127).each do |i|
@prot.write_byte(i)
- @trans.read(1).should == [i].pack('c')
+ expect(@trans.read(1)).to eq([i].pack('c'))
end
- # handing it numbers out of signed range should clip
- @trans.rspec_verify
+ end
+
+ it "should clip numbers out of signed range" do
(128..255).each do |i|
@prot.write_byte(i)
- @trans.read(1).should == [i].pack('c')
+ expect(@trans.read(1)).to eq([i].pack('c'))
end
- # and lastly, a Bignum is going to error out
- lambda { @prot.write_byte(2**65) }.should raise_error(RangeError)
+ end
+
+ it "errors out with a Bignum" do
+ expect { @prot.write_byte(2**65) }.to raise_error(RangeError)
end
it "should error gracefully when trying to write a nil byte" do
- lambda { @prot.write_byte(nil) }.should raise_error
+ expect { @prot.write_byte(nil) }.to raise_error
end
it "should write an i16" do
@@ -131,14 +134,14 @@ shared_examples_for 'a binary protocol' do
# and try something out of signed range, it should clip
@prot.write_i16(2**15 + 5)
- @trans.read(@trans.available).should == "\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005"
+ expect(@trans.read(@trans.available)).to eq("\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005")
# a Bignum should error
# lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
end
it "should error gracefully when trying to write a nil i16" do
- lambda { @prot.write_i16(nil) }.should raise_error
+ expect { @prot.write_i16(nil) }.to raise_error
end
it "should write an i32" do
@@ -148,14 +151,14 @@ shared_examples_for 'a binary protocol' do
@prot.write_i32(i)
end
# try something out of signed range, it should clip
- @trans.read(@trans.available).should == "\200\000\000\000" + "\377\376\037\r" + "\377\377\366\034" + "\377\377\377\375" + "\000\000\000\000" + "\000#\340\203" + "\000\0000+" + "\177\377\377\377"
+ expect(@trans.read(@trans.available)).to eq("\200\000\000\000" + "\377\376\037\r" + "\377\377\366\034" + "\377\377\377\375" + "\000\000\000\000" + "\000#\340\203" + "\000\0000+" + "\177\377\377\377")
[2 ** 31 + 5, 2 ** 65 + 5].each do |i|
- lambda { @prot.write_i32(i) }.should raise_error(RangeError)
+ expect { @prot.write_i32(i) }.to raise_error(RangeError)
end
end
it "should error gracefully when trying to write a nil i32" do
- lambda { @prot.write_i32(nil) }.should raise_error
+ expect { @prot.write_i32(nil) }.to raise_error
end
it "should write an i64" do
@@ -165,7 +168,7 @@ shared_examples_for 'a binary protocol' do
@prot.write_i64(i)
end
# try something out of signed range, it should clip
- @trans.read(@trans.available).should == ["\200\000\000\000\000\000\000\000",
+ expect(@trans.read(@trans.available)).to eq(["\200\000\000\000\000\000\000\000",
"\377\377\364\303\035\244+]",
"\377\377\377\377\376\231:\341",
"\377\377\377\377\377\377\377\026",
@@ -173,12 +176,12 @@ shared_examples_for 'a binary protocol' do
"\000\000\000\000\000\000\004\317",
"\000\000\000\000\000#\340\204",
"\000\000\000\002\340\311~\365",
- "\177\377\377\377\377\377\377\377"].join("")
- lambda { @prot.write_i64(2 ** 65 + 5) }.should raise_error(RangeError)
+ "\177\377\377\377\377\377\377\377"].join(""))
+ expect { @prot.write_i64(2 ** 65 + 5) }.to raise_error(RangeError)
end
it "should error gracefully when trying to write a nil i64" do
- lambda { @prot.write_i64(nil) }.should raise_error
+ expect { @prot.write_i64(nil) }.to raise_error
end
it "should write a double" do
@@ -186,12 +189,12 @@ shared_examples_for 'a binary protocol' do
values = [Float::MIN,-1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
values.each do |f|
@prot.write_double(f)
- @trans.read(@trans.available).should == [f].pack("G")
+ expect(@trans.read(@trans.available)).to eq([f].pack("G"))
end
end
it "should error gracefully when trying to write a nil double" do
- lambda { @prot.write_double(nil) }.should raise_error
+ expect { @prot.write_double(nil) }.to raise_error
end
if RUBY_VERSION >= '1.9'
@@ -199,111 +202,111 @@ shared_examples_for 'a binary protocol' do
str = 'abc'
@prot.write_string(str)
a = @trans.read(@trans.available)
- a.encoding.should == Encoding::BINARY
- a.unpack('C*').should == [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63]
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
end
it 'should write a string with unicode characters' do
str = "abc \u20AC \u20AD".encode('UTF-8')
@prot.write_string(str)
a = @trans.read(@trans.available)
- a.encoding.should == Encoding::BINARY
- a.unpack('C*').should == [0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
- 0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD]
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
+ 0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD])
end
it 'should write should write a string with unicode characters and transcoding' do
str = "abc \u20AC".encode('ISO-8859-15')
@prot.write_string(str)
a = @trans.read(@trans.available)
- a.encoding.should == Encoding::BINARY
- a.unpack('C*').should == [0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC]
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC])
end
it 'should write a binary string' do
buffer = [0, 1, 2, 3].pack('C*')
@prot.write_binary(buffer)
a = @trans.read(@trans.available)
- a.encoding.should == Encoding::BINARY
- a.unpack('C*').should == [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03]
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
end
else
it 'should write a string' do
str = 'abc'
@prot.write_string(str)
a = @trans.read(@trans.available)
- a.unpack('C*').should == [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63]
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
end
it 'should write a binary string' do
buffer = [0, 1, 2, 3].pack('C*')
@prot.write_binary(buffer)
a = @trans.read(@trans.available)
- a.unpack('C*').should == [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03]
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
end
end
it "should error gracefully when trying to write a nil string" do
- lambda { @prot.write_string(nil) }.should raise_error
+ expect { @prot.write_string(nil) }.to raise_error
end
it "should write the message header without version when writes are not strict" do
@prot = protocol_class.new(@trans, true, false) # no strict write
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
- @trans.read(@trans.available).should == "\000\000\000\vtestMessage\001\000\000\000\021"
+ expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
end
it "should write the message header with a version when writes are strict" do
@prot = protocol_class.new(@trans) # strict write
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
- @trans.read(@trans.available).should == "\200\001\000\001\000\000\000\vtestMessage\000\000\000\021"
+ expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
end
# message footer is a noop
it "should read a field header" do
@trans.write([Thrift::Types::STRING, 3].pack("cn"))
- @prot.read_field_begin.should == [nil, Thrift::Types::STRING, 3]
+ expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STRING, 3])
end
# field footer is a noop
it "should read a stop field" do
@trans.write([Thrift::Types::STOP].pack("c"));
- @prot.read_field_begin.should == [nil, Thrift::Types::STOP, 0]
+ expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STOP, 0])
end
it "should read a map header" do
@trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
- @prot.read_map_begin.should == [Thrift::Types::DOUBLE, Thrift::Types::I64, 42]
+ expect(@prot.read_map_begin).to eq([Thrift::Types::DOUBLE, Thrift::Types::I64, 42])
end
# map footer is a noop
it "should read a list header" do
@trans.write([Thrift::Types::STRING, 17].pack("cN"))
- @prot.read_list_begin.should == [Thrift::Types::STRING, 17]
+ expect(@prot.read_list_begin).to eq([Thrift::Types::STRING, 17])
end
# list footer is a noop
it "should read a set header" do
@trans.write([Thrift::Types::STRING, 17].pack("cN"))
- @prot.read_set_begin.should == [Thrift::Types::STRING, 17]
+ expect(@prot.read_set_begin).to eq([Thrift::Types::STRING, 17])
end
# set footer is a noop
it "should read a bool" do
@trans.write("\001\000");
- @prot.read_bool.should == true
- @prot.read_bool.should == false
+ expect(@prot.read_bool).to eq(true)
+ expect(@prot.read_bool).to eq(false)
end
it "should read a byte" do
[-128, -57, -3, 0, 17, 24, 127].each do |i|
@trans.write([i].pack("c"))
- @prot.read_byte.should == i
+ expect(@prot.read_byte).to eq(i)
end
end
@@ -311,7 +314,7 @@ shared_examples_for 'a binary protocol' do
# try a scattering of values, including min/max
[-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
@trans.write([i].pack("n"));
- @prot.read_i16.should == i
+ expect(@prot.read_i16).to eq(i)
end
end
@@ -319,7 +322,7 @@ shared_examples_for 'a binary protocol' do
# try a scattering of values, including min/max
[-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
@trans.write([i].pack("N"))
- @prot.read_i32.should == i
+ expect(@prot.read_i32).to eq(i)
end
end
@@ -327,7 +330,7 @@ shared_examples_for 'a binary protocol' do
# try a scattering of values, including min/max
[-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
@trans.write([i >> 32, i & 0xFFFFFFFF].pack("NN"))
- @prot.read_i64.should == i
+ expect(@prot.read_i64).to eq(i)
end
end
@@ -335,7 +338,7 @@ shared_examples_for 'a binary protocol' do
# try a random scattering of values, including min/max
[Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
@trans.write([f].pack("G"));
- @prot.read_double.should == f
+ expect(@prot.read_double).to eq(f)
end
end
@@ -345,8 +348,8 @@ shared_examples_for 'a binary protocol' do
buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
@trans.write(buffer)
a = @prot.read_string
- a.should == 'abc'.encode('UTF-8')
- a.encoding.should == Encoding::UTF_8
+ expect(a).to eq('abc'.encode('UTF-8'))
+ expect(a.encoding).to eq(Encoding::UTF_8)
end
it 'should read a string containing unicode characters from UTF-8 encoded buffer' do
@@ -354,44 +357,44 @@ shared_examples_for 'a binary protocol' do
buffer = [0x00, 0x00, 0x00, 0x03, 0xE2, 0x82, 0xAC].pack('C*')
@trans.write(buffer)
a = @prot.read_string
- a.should == "\u20AC".encode('UTF-8')
- a.encoding.should == Encoding::UTF_8
+ expect(a).to eq("\u20AC".encode('UTF-8'))
+ expect(a.encoding).to eq(Encoding::UTF_8)
end
it 'should read a binary string' do
buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
@trans.write(buffer)
a = @prot.read_binary
- a.should == [0x00, 0x01, 0x02, 0x03].pack('C*')
- a.encoding.should == Encoding::BINARY
+ expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
+ expect(a.encoding).to eq(Encoding::BINARY)
end
else
it 'should read a string' do
# i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
@trans.write(buffer)
- @prot.read_string.should == 'abc'
+ expect(@prot.read_string).to eq('abc')
end
it 'should read a binary string' do
buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
@trans.write(buffer)
a = @prot.read_binary
- a.should == [0x00, 0x01, 0x02, 0x03].pack('C*')
+ expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
end
end
it "should perform a complete rpc with no args or return" do
srv_test(
proc {|client| client.send_voidMethod()},
- proc {|client| client.recv_voidMethod.should == nil}
+ proc {|client| expect(client.recv_voidMethod).to eq(nil)}
)
end
it "should perform a complete rpc with a primitive return type" do
srv_test(
proc {|client| client.send_primitiveMethod()},
- proc {|client| client.recv_primitiveMethod.should == 1}
+ proc {|client| expect(client.recv_primitiveMethod).to eq(1)}
)
end
@@ -402,7 +405,7 @@ shared_examples_for 'a binary protocol' do
result = client.recv_structMethod
result.set_byte_map = nil
result.map_byte_map = nil
- result.should == Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
+ expect(result).to eq(Fixtures::COMPACT_PROTOCOL_TEST_STRUCT)
}
)
end
diff --git a/lib/rb/spec/bytes_spec.rb b/lib/rb/spec/bytes_spec.rb
index b82e304b7..2e8653cfc 100644
--- a/lib/rb/spec/bytes_spec.rb
+++ b/lib/rb/spec/bytes_spec.rb
@@ -25,33 +25,33 @@ describe Thrift::Bytes do
describe '.empty_byte_buffer' do
it 'should create an empty buffer' do
b = Thrift::Bytes.empty_byte_buffer
- b.length.should == 0
- b.encoding.should == Encoding::BINARY
+ expect(b.length).to eq(0)
+ expect(b.encoding).to eq(Encoding::BINARY)
end
it 'should create an empty buffer of given size' do
b = Thrift::Bytes.empty_byte_buffer 2
- b.length.should == 2
- b.getbyte(0).should == 0
- b.getbyte(1).should == 0
- b.encoding.should == Encoding::BINARY
+ expect(b.length).to eq(2)
+ expect(b.getbyte(0)).to eq(0)
+ expect(b.getbyte(1)).to eq(0)
+ expect(b.encoding).to eq(Encoding::BINARY)
end
end
describe '.force_binary_encoding' do
it 'should change encoding' do
e = 'STRING'.encode('UTF-8')
- e.encoding.should_not == Encoding::BINARY
+ expect(e.encoding).not_to eq(Encoding::BINARY)
a = Thrift::Bytes.force_binary_encoding e
- a.encoding.should == Encoding::BINARY
+ expect(a.encoding).to eq(Encoding::BINARY)
end
end
describe '.get_string_byte' do
it 'should get the byte at index' do
s = "\x41\x42"
- Thrift::Bytes.get_string_byte(s, 0).should == 0x41
- Thrift::Bytes.get_string_byte(s, 1).should == 0x42
+ expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
+ expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
end
end
@@ -59,42 +59,42 @@ describe Thrift::Bytes do
it 'should set byte value at index' do
s = "\x41\x42"
Thrift::Bytes.set_string_byte(s, 0, 0x43)
- s.getbyte(0).should == 0x43
- s.should == 'CB'
+ expect(s.getbyte(0)).to eq(0x43)
+ expect(s).to eq('CB')
end
end
describe '.convert_to_utf8_byte_buffer' do
it 'should convert UTF-8 String to byte buffer' do
e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
- e.length.should == 1
+ expect(e.length).to eq(1)
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
- a.encoding.should == Encoding::BINARY
- a.length.should == 3
- a.unpack('C*').should == [0xE2, 0x82, 0xAC]
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.length).to eq(3)
+ expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
end
it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
# Assumptions
e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
- e.length.should == 1
- e.unpack('C*').should == [0xA4] # euro sign is a different code point in ISO-8859-15
+ expect(e.length).to eq(1)
+ expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
- a.encoding.should == Encoding::BINARY
- a.length.should == 3
- a.unpack('C*').should == [0xE2, 0x82, 0xAC]
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.length).to eq(3)
+ expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
end
end
describe '.convert_to_string' do
it 'should convert UTF-8 byte buffer to a UTF-8 String' do
e = [0xE2, 0x82, 0xAC].pack("C*")
- e.encoding.should == Encoding::BINARY
+ expect(e.encoding).to eq(Encoding::BINARY)
a = Thrift::Bytes.convert_to_string e
- a.encoding.should == Encoding::UTF_8
- a.should == "\u20AC"
+ expect(a.encoding).to eq(Encoding::UTF_8)
+ expect(a).to eq("\u20AC")
end
end
@@ -102,14 +102,14 @@ describe Thrift::Bytes do
describe '.empty_byte_buffer' do
it 'should create an empty buffer' do
b = Thrift::Bytes.empty_byte_buffer
- b.length.should == 0
+ expect(b.length).to eq(0)
end
it 'should create an empty buffer of given size' do
b = Thrift::Bytes.empty_byte_buffer 2
- b.length.should == 2
- b[0].should == 0
- b[1].should == 0
+ expect(b.length).to eq(2)
+ expect(b[0]).to eq(0)
+ expect(b[1]).to eq(0)
end
end
@@ -117,16 +117,16 @@ describe Thrift::Bytes do
it 'should be a no-op' do
e = 'STRING'
a = Thrift::Bytes.force_binary_encoding e
- a.should == e
- a.should be(e)
+ expect(a).to eq(e)
+ expect(a).to be(e)
end
end
describe '.get_string_byte' do
it 'should get the byte at index' do
s = "\x41\x42"
- Thrift::Bytes.get_string_byte(s, 0).should == 0x41
- Thrift::Bytes.get_string_byte(s, 1).should == 0x42
+ expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
+ expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
end
end
@@ -134,8 +134,8 @@ describe Thrift::Bytes do
it 'should set byte value at index' do
s = "\x41\x42"
Thrift::Bytes.set_string_byte(s, 0, 0x43)
- s[0].should == 0x43
- s.should == 'CB'
+ expect(s[0]).to eq(0x43)
+ expect(s).to eq('CB')
end
end
@@ -143,8 +143,8 @@ describe Thrift::Bytes do
it 'should be a no-op' do
e = 'STRING'
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
- a.should == e
- a.should be(e)
+ expect(a).to eq(e)
+ expect(a).to be(e)
end
end
@@ -152,8 +152,8 @@ describe Thrift::Bytes do
it 'should be a no-op' do
e = 'STRING'
a = Thrift::Bytes.convert_to_string e
- a.should == e
- a.should be(e)
+ expect(a).to eq(e)
+ expect(a).to be(e)
end
end
end
diff --git a/lib/rb/spec/client_spec.rb b/lib/rb/spec/client_spec.rb
index f8ffe8a8d..d5d4ceedb 100644
--- a/lib/rb/spec/client_spec.rb
+++ b/lib/rb/spec/client_spec.rb
@@ -26,74 +26,73 @@ describe 'Client' do
end
before(:each) do
- @prot = mock("MockProtocol")
+ @prot = double("MockProtocol")
@client = ClientSpec.new(@prot)
end
describe Thrift::Client do
it "should re-use iprot for oprot if not otherwise specified" do
- @client.instance_variable_get(:'@iprot').should eql(@prot)
- @client.instance_variable_get(:'@oprot').should eql(@prot)
+ expect(@client.instance_variable_get(:'@iprot')).to eql(@prot)
+ expect(@client.instance_variable_get(:'@oprot')).to eql(@prot)
end
it "should send a test message" do
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
- mock_args = mock('#<TestMessage_args:mock>')
- mock_args.should_receive(:foo=).with('foo')
- mock_args.should_receive(:bar=).with(42)
- mock_args.should_receive(:write).with(@prot)
- @prot.should_receive(:write_message_end)
- @prot.should_receive(:trans) do
- mock('trans').tap do |trans|
- trans.should_receive(:flush)
+ expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
+ mock_args = double('#<TestMessage_args:mock>')
+ expect(mock_args).to receive(:foo=).with('foo')
+ expect(mock_args).to receive(:bar=).with(42)
+ expect(mock_args).to receive(:write).with(@prot)
+ expect(@prot).to receive(:write_message_end)
+ expect(@prot).to receive(:trans) do
+ double('trans').tap do |trans|
+ expect(trans).to receive(:flush)
end
end
- klass = stub("TestMessage_args", :new => mock_args)
+ klass = double("TestMessage_args", :new => mock_args)
@client.send_message('testMessage', klass, :foo => 'foo', :bar => 42)
end
it "should increment the sequence id when sending messages" do
- pending "it seems sequence ids are completely ignored right now" do
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
- @prot.should_receive(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
- @prot.should_receive(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
- @prot.stub!(:write_message_end)
- @prot.stub!(:trans).and_return mock("trans").as_null_object
- @client.send_message('testMessage', mock("args class").as_null_object)
- @client.send_message('testMessage2', mock("args class").as_null_object)
- @client.send_message('testMessage3', mock("args class").as_null_object)
- end
+ pending "it seems sequence ids are completely ignored right now"
+ @prot.expect(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
+ @prot.expect(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
+ @prot.expect(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
+ @prot.stub!(:write_message_end)
+ @prot.stub!(:trans).and_return double("trans").as_null_object
+ @client.send_message('testMessage', double("args class").as_null_object)
+ @client.send_message('testMessage2', double("args class").as_null_object)
+ @client.send_message('testMessage3', double("args class").as_null_object)
end
it "should receive a test message" do
- @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
- @prot.should_receive(:read_message_end)
- mock_klass = mock("#<MockClass:mock>")
- mock_klass.should_receive(:read).with(@prot)
- @client.receive_message(stub("MockClass", :new => mock_klass))
+ expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
+ expect(@prot).to receive(:read_message_end)
+ mock_klass = double("#<MockClass:mock>")
+ expect(mock_klass).to receive(:read).with(@prot)
+ @client.receive_message(double("MockClass", :new => mock_klass))
end
it "should handle received exceptions" do
- @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
- @prot.should_receive(:read_message_end)
- Thrift::ApplicationException.should_receive(:new).and_return do
+ expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
+ expect(@prot).to receive(:read_message_end)
+ expect(Thrift::ApplicationException).to receive(:new) do
StandardError.new.tap do |mock_exc|
- mock_exc.should_receive(:read).with(@prot)
+ expect(mock_exc).to receive(:read).with(@prot)
end
end
- lambda { @client.receive_message(nil) }.should raise_error(StandardError)
+ expect { @client.receive_message(nil) }.to raise_error(StandardError)
end
it "should close the transport if an error occurs while sending a message" do
- @prot.stub!(:write_message_begin)
- @prot.should_not_receive(:write_message_end)
- mock_args = mock("#<TestMessage_args:mock>")
- mock_args.should_receive(:write).with(@prot).and_raise(StandardError)
- trans = mock("MockTransport")
- @prot.stub!(:trans).and_return(trans)
- trans.should_receive(:close)
- klass = mock("TestMessage_args", :new => mock_args)
- lambda { @client.send_message("testMessage", klass) }.should raise_error(StandardError)
+ allow(@prot).to receive(:write_message_begin)
+ expect(@prot).not_to receive(:write_message_end)
+ mock_args = double("#<TestMessage_args:mock>")
+ expect(mock_args).to receive(:write).with(@prot).and_raise(StandardError)
+ trans = double("MockTransport")
+ allow(@prot).to receive(:trans).and_return(trans)
+ expect(trans).to receive(:close)
+ klass = double("TestMessage_args", :new => mock_args)
+ expect { @client.send_message("testMessage", klass) }.to raise_error(StandardError)
end
end
end
diff --git a/lib/rb/spec/compact_protocol_spec.rb b/lib/rb/spec/compact_protocol_spec.rb
index 71ddc0ea3..513dd69cf 100644
--- a/lib/rb/spec/compact_protocol_spec.rb
+++ b/lib/rb/spec/compact_protocol_spec.rb
@@ -42,7 +42,7 @@ describe Thrift::CompactProtocol do
proto.send(writer(primitive_type), value)
# puts "buf: #{trans.inspect_buffer}" if primitive_type == :i64
read_back = proto.send(reader(primitive_type))
- read_back.should == value
+ expect(read_back).to eq(value)
end
end
end
@@ -62,10 +62,10 @@ describe Thrift::CompactProtocol do
proto = Thrift::CompactProtocol.new(trans)
name, type, id = proto.read_field_begin
- type.should == thrift_type
- id.should == 15
+ expect(type).to eq(thrift_type)
+ expect(id).to eq(15)
read_back = proto.send(reader(primitive_type))
- read_back.should == value
+ expect(read_back).to eq(value)
proto.read_field_end
end
end
@@ -81,7 +81,7 @@ describe Thrift::CompactProtocol do
struct2 = Thrift::Test::CompactProtoTestStruct.new
struct2.read(proto)
- struct2.should == struct
+ expect(struct2).to eq(struct)
end
it "should make method calls correctly" do
@@ -97,7 +97,7 @@ describe Thrift::CompactProtocol do
client.send_Janky(1)
# puts client_out_trans.inspect_buffer
processor.process(client_out_proto, client_in_proto)
- client.recv_Janky.should == 2
+ expect(client.recv_Janky).to eq(2)
end
it "should deal with fields following fields that have non-delta ids" do
@@ -113,7 +113,7 @@ describe Thrift::CompactProtocol do
deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
brcp2 = Thrift::Test::BreaksRubyCompactProtocol.new
deser.deserialize(brcp2, bytes)
- brcp2.should == brcp
+ expect(brcp2).to eq(brcp)
end
it "should deserialize an empty map to an empty hash" do
@@ -124,12 +124,12 @@ describe Thrift::CompactProtocol do
deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
struct2 = Thrift::Test::SingleMapTestStruct.new
deser.deserialize(struct2, bytes)
- struct.should == struct2
+ expect(struct).to eq(struct2)
end
it "should provide a reasonable to_s" do
trans = Thrift::MemoryBufferTransport.new
- Thrift::CompactProtocol.new(trans).to_s.should == "compact(memory)"
+ expect(Thrift::CompactProtocol.new(trans).to_s).to eq("compact(memory)")
end
class JankyHandler
@@ -149,10 +149,10 @@ end
describe Thrift::CompactProtocolFactory do
it "should create a CompactProtocol" do
- Thrift::CompactProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::CompactProtocol)
+ expect(Thrift::CompactProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::CompactProtocol)
end
it "should provide a reasonable to_s" do
- Thrift::CompactProtocolFactory.new.to_s.should == "compact"
+ expect(Thrift::CompactProtocolFactory.new.to_s).to eq("compact")
end
end
diff --git a/lib/rb/spec/exception_spec.rb b/lib/rb/spec/exception_spec.rb
index d1da6217e..379ae6980 100644
--- a/lib/rb/spec/exception_spec.rb
+++ b/lib/rb/spec/exception_spec.rb
@@ -24,107 +24,107 @@ describe 'Exception' do
describe Thrift::Exception do
it "should have an accessible message" do
e = Thrift::Exception.new("test message")
- e.message.should == "test message"
+ expect(e.message).to eq("test message")
end
end
describe Thrift::ApplicationException do
it "should inherit from Thrift::Exception" do
- Thrift::ApplicationException.superclass.should == Thrift::Exception
+ expect(Thrift::ApplicationException.superclass).to eq(Thrift::Exception)
end
it "should have an accessible type and message" do
e = Thrift::ApplicationException.new
- e.type.should == Thrift::ApplicationException::UNKNOWN
- e.message.should be_nil
+ expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN)
+ expect(e.message).to be_nil
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
- e.type.should == Thrift::ApplicationException::UNKNOWN_METHOD
- e.message.should == "test message"
+ expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN_METHOD)
+ expect(e.message).to eq("test message")
end
it "should read a struct off of a protocol" do
- prot = mock("MockProtocol")
- prot.should_receive(:read_struct_begin).ordered
- prot.should_receive(:read_field_begin).exactly(3).times.and_return(
+ prot = double("MockProtocol")
+ expect(prot).to receive(:read_struct_begin).ordered
+ expect(prot).to receive(:read_field_begin).exactly(3).times.and_return(
["message", Thrift::Types::STRING, 1],
["type", Thrift::Types::I32, 2],
[nil, Thrift::Types::STOP, 0]
)
- prot.should_receive(:read_string).ordered.and_return "test message"
- prot.should_receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
- prot.should_receive(:read_field_end).exactly(2).times
- prot.should_receive(:read_struct_end).ordered
+ expect(prot).to receive(:read_string).ordered.and_return "test message"
+ expect(prot).to receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
+ expect(prot).to receive(:read_field_end).exactly(2).times
+ expect(prot).to receive(:read_struct_end).ordered
e = Thrift::ApplicationException.new
e.read(prot)
- e.message.should == "test message"
- e.type.should == Thrift::ApplicationException::BAD_SEQUENCE_ID
+ expect(e.message).to eq("test message")
+ expect(e.type).to eq(Thrift::ApplicationException::BAD_SEQUENCE_ID)
end
it "should skip bad fields when reading a struct" do
- prot = mock("MockProtocol")
- prot.should_receive(:read_struct_begin).ordered
- prot.should_receive(:read_field_begin).exactly(5).times.and_return(
+ prot = double("MockProtocol")
+ expect(prot).to receive(:read_struct_begin).ordered
+ expect(prot).to receive(:read_field_begin).exactly(5).times.and_return(
["type", Thrift::Types::I32, 2],
["type", Thrift::Types::STRING, 2],
["message", Thrift::Types::MAP, 1],
["message", Thrift::Types::STRING, 3],
[nil, Thrift::Types::STOP, 0]
)
- prot.should_receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
- prot.should_receive(:skip).with(Thrift::Types::STRING).twice
- prot.should_receive(:skip).with(Thrift::Types::MAP)
- prot.should_receive(:read_field_end).exactly(4).times
- prot.should_receive(:read_struct_end).ordered
+ expect(prot).to receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
+ expect(prot).to receive(:skip).with(Thrift::Types::STRING).twice
+ expect(prot).to receive(:skip).with(Thrift::Types::MAP)
+ expect(prot).to receive(:read_field_end).exactly(4).times
+ expect(prot).to receive(:read_struct_end).ordered
e = Thrift::ApplicationException.new
e.read(prot)
- e.message.should be_nil
- e.type.should == Thrift::ApplicationException::INVALID_MESSAGE_TYPE
+ expect(e.message).to be_nil
+ expect(e.type).to eq(Thrift::ApplicationException::INVALID_MESSAGE_TYPE)
end
it "should write a Thrift::ApplicationException struct to the oprot" do
- prot = mock("MockProtocol")
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
- prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
- prot.should_receive(:write_string).with("test message").ordered
- prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
- prot.should_receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
- prot.should_receive(:write_field_end).twice
- prot.should_receive(:write_field_stop).ordered
- prot.should_receive(:write_struct_end).ordered
+ prot = double("MockProtocol")
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
+ expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
+ expect(prot).to receive(:write_string).with("test message").ordered
+ expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
+ expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
+ expect(prot).to receive(:write_field_end).twice
+ expect(prot).to receive(:write_field_stop).ordered
+ expect(prot).to receive(:write_struct_end).ordered
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
e.write(prot)
end
it "should skip nil fields when writing to the oprot" do
- prot = mock("MockProtocol")
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
- prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
- prot.should_receive(:write_string).with("test message").ordered
- prot.should_receive(:write_field_end).ordered
- prot.should_receive(:write_field_stop).ordered
- prot.should_receive(:write_struct_end).ordered
+ prot = double("MockProtocol")
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
+ expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
+ expect(prot).to receive(:write_string).with("test message").ordered
+ expect(prot).to receive(:write_field_end).ordered
+ expect(prot).to receive(:write_field_stop).ordered
+ expect(prot).to receive(:write_struct_end).ordered
e = Thrift::ApplicationException.new(nil, "test message")
e.write(prot)
- prot = mock("MockProtocol")
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
- prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
- prot.should_receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
- prot.should_receive(:write_field_end).ordered
- prot.should_receive(:write_field_stop).ordered
- prot.should_receive(:write_struct_end).ordered
+ prot = double("MockProtocol")
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
+ expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
+ expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
+ expect(prot).to receive(:write_field_end).ordered
+ expect(prot).to receive(:write_field_stop).ordered
+ expect(prot).to receive(:write_struct_end).ordered
e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
e.write(prot)
- prot = mock("MockProtocol")
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
- prot.should_receive(:write_field_stop).ordered
- prot.should_receive(:write_struct_end).ordered
+ prot = double("MockProtocol")
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
+ expect(prot).to receive(:write_field_stop).ordered
+ expect(prot).to receive(:write_struct_end).ordered
e = Thrift::ApplicationException.new(nil)
e.write(prot)
@@ -134,8 +134,8 @@ describe 'Exception' do
describe Thrift::ProtocolException do
it "should have an accessible type" do
prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
- prot.type.should == Thrift::ProtocolException::SIZE_LIMIT
- prot.message.should == "message"
+ expect(prot.type).to eq(Thrift::ProtocolException::SIZE_LIMIT)
+ expect(prot.message).to eq("message")
end
end
end
diff --git a/lib/rb/spec/flat_spec.rb b/lib/rb/spec/flat_spec.rb
index f37878231..893056c10 100644
--- a/lib/rb/spec/flat_spec.rb
+++ b/lib/rb/spec/flat_spec.rb
@@ -32,7 +32,7 @@ describe 'generation' do
"other_namespace/referenced_constants.rb",
"other_namespace/referenced_types.rb"
].each do |name|
- File.exist?(File.join(prefix, name)).should_not be_true
+ expect(File.exist?(File.join(prefix, name))).not_to be_truthy
end
end
@@ -44,19 +44,19 @@ describe 'generation' do
"referenced_constants.rb",
"referenced_types.rb"
].each do |name|
- File.exist?(File.join(prefix, name)).should be_true
+ expect(File.exist?(File.join(prefix, name))).to be_truthy
end
end
it "has a service class in the right place" do
- defined?(NamespacedSpecNamespace::NamespacedNonblockingService).should be_true
+ expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
end
it "has a struct in the right place" do
- defined?(NamespacedSpecNamespace::Hello).should be_true
+ expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
end
it "required an included file" do
- defined?(OtherNamespace::SomeEnum).should be_true
+ expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
end
end
diff --git a/lib/rb/spec/http_client_spec.rb b/lib/rb/spec/http_client_spec.rb
index 70747ed3f..df472ab33 100644
--- a/lib/rb/spec/http_client_spec.rb
+++ b/lib/rb/spec/http_client_spec.rb
@@ -31,26 +31,26 @@ describe 'Thrift::HTTPClientTransport' do
end
it "should always be open" do
- @client.should be_open
+ expect(@client).to be_open
@client.close
- @client.should be_open
+ expect(@client).to be_open
end
it "should post via HTTP and return the results" do
@client.write "a test"
@client.write " frame"
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
- mock("Net::HTTP").tap do |http|
- http.should_receive(:use_ssl=).with(false)
- http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
- mock("Net::HTTPOK").tap do |response|
- response.should_receive(:body).and_return "data"
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
+ double("Net::HTTP").tap do |http|
+ expect(http).to receive(:use_ssl=).with(false)
+ expect(http).to receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}) do
+ double("Net::HTTPOK").tap do |response|
+ expect(response).to receive(:body).and_return "data"
end
end
end
end
@client.flush
- @client.read(10).should == "data"
+ expect(@client.read(10)).to eq("data")
end
it "should send custom headers if defined" do
@@ -59,12 +59,12 @@ describe 'Thrift::HTTPClientTransport' do
headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
@client.add_headers(custom_headers)
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
- mock("Net::HTTP").tap do |http|
- http.should_receive(:use_ssl=).with(false)
- http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
- mock("Net::HTTPOK").tap do |response|
- response.should_receive(:body).and_return "data"
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
+ double("Net::HTTP").tap do |http|
+ expect(http).to receive(:use_ssl=).with(false)
+ expect(http).to receive(:post).with("/path/to/service?param=value", "test", headers) do
+ double("Net::HTTPOK").tap do |response|
+ expect(response).to receive(:body).and_return "data"
end
end
end
@@ -75,15 +75,15 @@ describe 'Thrift::HTTPClientTransport' do
it 'should reset the outbuf on HTTP failures' do
@client.write "test"
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
- mock("Net::HTTP").tap do |http|
- http.should_receive(:use_ssl=).with(false)
- http.should_receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
+ double("Net::HTTP").tap do |http|
+ expect(http).to receive(:use_ssl=).with(false)
+ expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
end
end
@client.flush rescue
- @client.instance_variable_get(:@outbuf).should eq(Thrift::Bytes.empty_byte_buffer)
+ expect(@client.instance_variable_get(:@outbuf)).to eq(Thrift::Bytes.empty_byte_buffer)
end
end
@@ -99,20 +99,20 @@ describe 'Thrift::HTTPClientTransport' do
client.write "test"
- Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
- mock("Net::HTTP").tap do |http|
- http.should_receive(:use_ssl=).with(true)
- http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
- http.should_receive(:post).with(@service_path, "test",
- "Content-Type" => "application/x-thrift").and_return do
- mock("Net::HTTPOK").tap do |response|
- response.should_receive(:body).and_return "data"
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
+ double("Net::HTTP").tap do |http|
+ expect(http).to receive(:use_ssl=).with(true)
+ expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
+ expect(http).to receive(:post).with(@service_path, "test",
+ "Content-Type" => "application/x-thrift") do
+ double("Net::HTTPOK").tap do |response|
+ expect(response).to receive(:body).and_return "data"
end
end
end
end
client.flush
- client.read(4).should == "data"
+ expect(client.read(4)).to eq("data")
end
it "should set SSL verify mode when specified" do
@@ -120,20 +120,20 @@ describe 'Thrift::HTTPClientTransport' do
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
client.write "test"
- Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
- mock("Net::HTTP").tap do |http|
- http.should_receive(:use_ssl=).with(true)
- http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
- http.should_receive(:post).with(@service_path, "test",
- "Content-Type" => "application/x-thrift").and_return do
- mock("Net::HTTPOK").tap do |response|
- response.should_receive(:body).and_return "data"
+ expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
+ double("Net::HTTP").tap do |http|
+ expect(http).to receive(:use_ssl=).with(true)
+ expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
+ expect(http).to receive(:post).with(@service_path, "test",
+ "Content-Type" => "application/x-thrift") do
+ double("Net::HTTPOK").tap do |response|
+ expect(response).to receive(:body).and_return "data"
end
end
end
end
client.flush
- client.read(4).should == "data"
+ expect(client.read(4)).to eq("data")
end
end
end
diff --git a/lib/rb/spec/json_protocol_spec.rb b/lib/rb/spec/json_protocol_spec.rb
index 57e94016e..fe1af7bb2 100644
--- a/lib/rb/spec/json_protocol_spec.rb
+++ b/lib/rb/spec/json_protocol_spec.rb
@@ -30,257 +30,257 @@ describe 'JsonProtocol' do
it "should write json escaped char" do
@prot.write_json_escape_char("\n")
- @trans.read(@trans.available).should == '\u000a'
+ expect(@trans.read(@trans.available)).to eq('\u000a')
@prot.write_json_escape_char(" ")
- @trans.read(@trans.available).should == '\u0020'
+ expect(@trans.read(@trans.available)).to eq('\u0020')
end
it "should write json char" do
@prot.write_json_char("\n")
- @trans.read(@trans.available).should == '\\n'
+ expect(@trans.read(@trans.available)).to eq('\\n')
@prot.write_json_char(" ")
- @trans.read(@trans.available).should == ' '
+ expect(@trans.read(@trans.available)).to eq(' ')
@prot.write_json_char("\\")
- @trans.read(@trans.available).should == "\\\\"
+ expect(@trans.read(@trans.available)).to eq("\\\\")
@prot.write_json_char("@")
- @trans.read(@trans.available).should == '@'
+ expect(@trans.read(@trans.available)).to eq('@')
end
it "should write json string" do
@prot.write_json_string("this is a \\ json\nstring")
- @trans.read(@trans.available).should == "\"this is a \\\\ json\\nstring\""
+ expect(@trans.read(@trans.available)).to eq("\"this is a \\\\ json\\nstring\"")
end
it "should write json base64" do
@prot.write_json_base64("this is a base64 string")
- @trans.read(@trans.available).should == "\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\""
+ expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
end
it "should write json integer" do
@prot.write_json_integer(45)
- @trans.read(@trans.available).should == "45"
+ expect(@trans.read(@trans.available)).to eq("45")
@prot.write_json_integer(33000)
- @trans.read(@trans.available).should == "33000"
+ expect(@trans.read(@trans.available)).to eq("33000")
@prot.write_json_integer(3000000000)
- @trans.read(@trans.available).should == "3000000000"
+ expect(@trans.read(@trans.available)).to eq("3000000000")
@prot.write_json_integer(6000000000)
- @trans.read(@trans.available).should == "6000000000"
+ expect(@trans.read(@trans.available)).to eq("6000000000")
end
it "should write json double" do
@prot.write_json_double(12.3)
- @trans.read(@trans.available).should == "12.3"
+ expect(@trans.read(@trans.available)).to eq("12.3")
@prot.write_json_double(-3.21)
- @trans.read(@trans.available).should == "-3.21"
+ expect(@trans.read(@trans.available)).to eq("-3.21")
@prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
- @trans.read(@trans.available).should == "\"NaN\""
+ expect(@trans.read(@trans.available)).to eq("\"NaN\"")
@prot.write_json_double((+1.0/0.0))
- @trans.read(@trans.available).should == "\"Infinity\""
+ expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
@prot.write_json_double((-1.0/0.0))
- @trans.read(@trans.available).should == "\"-Infinity\""
+ expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
end
it "should write json object start" do
@prot.write_json_object_start
- @trans.read(@trans.available).should == "{"
+ expect(@trans.read(@trans.available)).to eq("{")
end
it "should write json object end" do
@prot.write_json_object_end
- @trans.read(@trans.available).should == "}"
+ expect(@trans.read(@trans.available)).to eq("}")
end
it "should write json array start" do
@prot.write_json_array_start
- @trans.read(@trans.available).should == "["
+ expect(@trans.read(@trans.available)).to eq("[")
end
it "should write json array end" do
@prot.write_json_array_end
- @trans.read(@trans.available).should == "]"
+ expect(@trans.read(@trans.available)).to eq("]")
end
it "should write message begin" do
@prot.write_message_begin("name", 12, 32)
- @trans.read(@trans.available).should == "[1,\"name\",12,32"
+ expect(@trans.read(@trans.available)).to eq("[1,\"name\",12,32")
end
it "should write message end" do
@prot.write_message_end
- @trans.read(@trans.available).should == "]"
+ expect(@trans.read(@trans.available)).to eq("]")
end
it "should write struct begin" do
@prot.write_struct_begin("name")
- @trans.read(@trans.available).should == "{"
+ expect(@trans.read(@trans.available)).to eq("{")
end
it "should write struct end" do
@prot.write_struct_end
- @trans.read(@trans.available).should == "}"
+ expect(@trans.read(@trans.available)).to eq("}")
end
it "should write field begin" do
@prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
- @trans.read(@trans.available).should == "32{\"rec\""
+ expect(@trans.read(@trans.available)).to eq("32{\"rec\"")
end
it "should write field end" do
@prot.write_field_end
- @trans.read(@trans.available).should == "}"
+ expect(@trans.read(@trans.available)).to eq("}")
end
it "should write field stop" do
@prot.write_field_stop
- @trans.read(@trans.available).should == ""
+ expect(@trans.read(@trans.available)).to eq("")
end
it "should write map begin" do
@prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
- @trans.read(@trans.available).should == "[\"rec\",\"lst\",32,{"
+ expect(@trans.read(@trans.available)).to eq("[\"rec\",\"lst\",32,{")
end
it "should write map end" do
@prot.write_map_end
- @trans.read(@trans.available).should == "}]"
+ expect(@trans.read(@trans.available)).to eq("}]")
end
it "should write list begin" do
@prot.write_list_begin(Thrift::Types::STRUCT, 32)
- @trans.read(@trans.available).should == "[\"rec\",32"
+ expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
end
it "should write list end" do
@prot.write_list_end
- @trans.read(@trans.available).should == "]"
+ expect(@trans.read(@trans.available)).to eq("]")
end
it "should write set begin" do
@prot.write_set_begin(Thrift::Types::STRUCT, 32)
- @trans.read(@trans.available).should == "[\"rec\",32"
+ expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
end
it "should write set end" do
@prot.write_set_end
- @trans.read(@trans.available).should == "]"
+ expect(@trans.read(@trans.available)).to eq("]")
end
it "should write bool" do
@prot.write_bool(true)
- @trans.read(@trans.available).should == "1"
+ expect(@trans.read(@trans.available)).to eq("1")
@prot.write_bool(false)
- @trans.read(@trans.available).should == "0"
+ expect(@trans.read(@trans.available)).to eq("0")
end
it "should write byte" do
@prot.write_byte(100)
- @trans.read(@trans.available).should == "100"
+ expect(@trans.read(@trans.available)).to eq("100")
end
it "should write i16" do
@prot.write_i16(1000)
- @trans.read(@trans.available).should == "1000"
+ expect(@trans.read(@trans.available)).to eq("1000")
end
it "should write i32" do
@prot.write_i32(3000000000)
- @trans.read(@trans.available).should == "3000000000"
+ expect(@trans.read(@trans.available)).to eq("3000000000")
end
it "should write i64" do
@prot.write_i64(6000000000)
- @trans.read(@trans.available).should == "6000000000"
+ expect(@trans.read(@trans.available)).to eq("6000000000")
end
it "should write double" do
@prot.write_double(1.23)
- @trans.read(@trans.available).should == "1.23"
+ expect(@trans.read(@trans.available)).to eq("1.23")
@prot.write_double(-32.1)
- @trans.read(@trans.available).should == "-32.1"
+ expect(@trans.read(@trans.available)).to eq("-32.1")
@prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
- @trans.read(@trans.available).should == "\"NaN\""
+ expect(@trans.read(@trans.available)).to eq("\"NaN\"")
@prot.write_double((+1.0/0.0))
- @trans.read(@trans.available).should == "\"Infinity\""
+ expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
@prot.write_double((-1.0/0.0))
- @trans.read(@trans.available).should == "\"-Infinity\""
+ expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
end
if RUBY_VERSION >= '1.9'
it 'should write string' do
@prot.write_string('this is a test string')
a = @trans.read(@trans.available)
- a.should == '"this is a test string"'.force_encoding(Encoding::BINARY)
- a.encoding.should == Encoding::BINARY
+ expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY))
+ expect(a.encoding).to eq(Encoding::BINARY)
end
it 'should write string with unicode characters' do
@prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
a = @trans.read(@trans.available)
- a.should == "\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY)
- a.encoding.should == Encoding::BINARY
+ expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY))
+ expect(a.encoding).to eq(Encoding::BINARY)
end
else
it 'should write string' do
@prot.write_string('this is a test string')
- @trans.read(@trans.available).should == '"this is a test string"'
+ expect(@trans.read(@trans.available)).to eq('"this is a test string"')
end
end
it "should write binary" do
@prot.write_binary("this is a base64 string")
- @trans.read(@trans.available).should == "\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\""
+ expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
end
it "should write long binary" do
@prot.write_binary((0...256).to_a.pack('C*'))
- @trans.read(@trans.available).should == "\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\""
+ expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
end
it "should get type name for type id" do
expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError)
- @prot.get_type_name_for_type_id(Thrift::Types::BOOL).should == "tf"
- @prot.get_type_name_for_type_id(Thrift::Types::BYTE).should == "i8"
- @prot.get_type_name_for_type_id(Thrift::Types::DOUBLE).should == "dbl"
- @prot.get_type_name_for_type_id(Thrift::Types::I16).should == "i16"
- @prot.get_type_name_for_type_id(Thrift::Types::I32).should == "i32"
- @prot.get_type_name_for_type_id(Thrift::Types::I64).should == "i64"
- @prot.get_type_name_for_type_id(Thrift::Types::STRING).should == "str"
- @prot.get_type_name_for_type_id(Thrift::Types::STRUCT).should == "rec"
- @prot.get_type_name_for_type_id(Thrift::Types::MAP).should == "map"
- @prot.get_type_name_for_type_id(Thrift::Types::SET).should == "set"
- @prot.get_type_name_for_type_id(Thrift::Types::LIST).should == "lst"
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::BOOL)).to eq("tf")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::BYTE)).to eq("i8")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE)).to eq("dbl")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::I16)).to eq("i16")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::I32)).to eq("i32")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::I64)).to eq("i64")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::STRING)).to eq("str")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::STRUCT)).to eq("rec")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::MAP)).to eq("map")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::SET)).to eq("set")
+ expect(@prot.get_type_name_for_type_id(Thrift::Types::LIST)).to eq("lst")
end
it "should get type id for type name" do
expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError)
- @prot.get_type_id_for_type_name("tf").should == Thrift::Types::BOOL
- @prot.get_type_id_for_type_name("i8").should == Thrift::Types::BYTE
- @prot.get_type_id_for_type_name("dbl").should == Thrift::Types::DOUBLE
- @prot.get_type_id_for_type_name("i16").should == Thrift::Types::I16
- @prot.get_type_id_for_type_name("i32").should == Thrift::Types::I32
- @prot.get_type_id_for_type_name("i64").should == Thrift::Types::I64
- @prot.get_type_id_for_type_name("str").should == Thrift::Types::STRING
- @prot.get_type_id_for_type_name("rec").should == Thrift::Types::STRUCT
- @prot.get_type_id_for_type_name("map").should == Thrift::Types::MAP
- @prot.get_type_id_for_type_name("set").should == Thrift::Types::SET
- @prot.get_type_id_for_type_name("lst").should == Thrift::Types::LIST
+ expect(@prot.get_type_id_for_type_name("tf")).to eq(Thrift::Types::BOOL)
+ expect(@prot.get_type_id_for_type_name("i8")).to eq(Thrift::Types::BYTE)
+ expect(@prot.get_type_id_for_type_name("dbl")).to eq(Thrift::Types::DOUBLE)
+ expect(@prot.get_type_id_for_type_name("i16")).to eq(Thrift::Types::I16)
+ expect(@prot.get_type_id_for_type_name("i32")).to eq(Thrift::Types::I32)
+ expect(@prot.get_type_id_for_type_name("i64")).to eq(Thrift::Types::I64)
+ expect(@prot.get_type_id_for_type_name("str")).to eq(Thrift::Types::STRING)
+ expect(@prot.get_type_id_for_type_name("rec")).to eq(Thrift::Types::STRUCT)
+ expect(@prot.get_type_id_for_type_name("map")).to eq(Thrift::Types::MAP)
+ expect(@prot.get_type_id_for_type_name("set")).to eq(Thrift::Types::SET)
+ expect(@prot.get_type_id_for_type_name("lst")).to eq(Thrift::Types::LIST)
end
it "should read json syntax char" do
@@ -292,31 +292,31 @@ describe 'JsonProtocol' do
it "should read json escape char" do
@trans.write('0054')
- @prot.read_json_escape_char.should == 'T'
+ expect(@prot.read_json_escape_char).to eq('T')
@trans.write("\"\\\"\"")
- @prot.read_json_string(false).should == "\""
+ expect(@prot.read_json_string(false)).to eq("\"")
@trans.write("\"\\\\\"")
- @prot.read_json_string(false).should == "\\"
+ expect(@prot.read_json_string(false)).to eq("\\")
@trans.write("\"\\/\"")
- @prot.read_json_string(false).should == "\/"
+ expect(@prot.read_json_string(false)).to eq("\/")
@trans.write("\"\\b\"")
- @prot.read_json_string(false).should == "\b"
+ expect(@prot.read_json_string(false)).to eq("\b")
@trans.write("\"\\f\"")
- @prot.read_json_string(false).should == "\f"
+ expect(@prot.read_json_string(false)).to eq("\f")
@trans.write("\"\\n\"")
- @prot.read_json_string(false).should == "\n"
+ expect(@prot.read_json_string(false)).to eq("\n")
@trans.write("\"\\r\"")
- @prot.read_json_string(false).should == "\r"
+ expect(@prot.read_json_string(false)).to eq("\r")
@trans.write("\"\\t\"")
- @prot.read_json_string(false).should == "\t"
+ expect(@prot.read_json_string(false)).to eq("\t")
end
it "should read json string" do
@@ -324,36 +324,36 @@ describe 'JsonProtocol' do
expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
@trans.write("\"this is a test string\"")
- @prot.read_json_string.should == "this is a test string"
+ expect(@prot.read_json_string).to eq("this is a test string")
end
it "should read json base64" do
@trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
- @prot.read_json_base64.should == "this is a test string"
+ expect(@prot.read_json_base64).to eq("this is a test string")
end
it "should is json numeric" do
- @prot.is_json_numeric("A").should == false
- @prot.is_json_numeric("+").should == true
- @prot.is_json_numeric("-").should == true
- @prot.is_json_numeric(".").should == true
- @prot.is_json_numeric("0").should == true
- @prot.is_json_numeric("1").should == true
- @prot.is_json_numeric("2").should == true
- @prot.is_json_numeric("3").should == true
- @prot.is_json_numeric("4").should == true
- @prot.is_json_numeric("5").should == true
- @prot.is_json_numeric("6").should == true
- @prot.is_json_numeric("7").should == true
- @prot.is_json_numeric("8").should == true
- @prot.is_json_numeric("9").should == true
- @prot.is_json_numeric("E").should == true
- @prot.is_json_numeric("e").should == true
+ expect(@prot.is_json_numeric("A")).to eq(false)
+ expect(@prot.is_json_numeric("+")).to eq(true)
+ expect(@prot.is_json_numeric("-")).to eq(true)
+ expect(@prot.is_json_numeric(".")).to eq(true)
+ expect(@prot.is_json_numeric("0")).to eq(true)
+ expect(@prot.is_json_numeric("1")).to eq(true)
+ expect(@prot.is_json_numeric("2")).to eq(true)
+ expect(@prot.is_json_numeric("3")).to eq(true)
+ expect(@prot.is_json_numeric("4")).to eq(true)
+ expect(@prot.is_json_numeric("5")).to eq(true)
+ expect(@prot.is_json_numeric("6")).to eq(true)
+ expect(@prot.is_json_numeric("7")).to eq(true)
+ expect(@prot.is_json_numeric("8")).to eq(true)
+ expect(@prot.is_json_numeric("9")).to eq(true)
+ expect(@prot.is_json_numeric("E")).to eq(true)
+ expect(@prot.is_json_numeric("e")).to eq(true)
end
it "should read json numeric chars" do
@trans.write("1.453E45T")
- @prot.read_json_numeric_chars.should == "1.453E45"
+ expect(@prot.read_json_numeric_chars).to eq("1.453E45")
end
it "should read json integer" do
@@ -362,7 +362,7 @@ describe 'JsonProtocol' do
@prot.read_string
@trans.write("1453T")
- @prot.read_json_integer.should == 1453
+ expect(@prot.read_json_integer).to eq(1453)
end
it "should read json double" do
@@ -374,37 +374,37 @@ describe 'JsonProtocol' do
expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
@trans.write("1.453e01\"\"")
- @prot.read_json_double.should == 14.53
+ expect(@prot.read_json_double).to eq(14.53)
@prot.read_string
@trans.write("\"NaN\"")
- @prot.read_json_double.nan?.should == true
+ expect(@prot.read_json_double.nan?).to eq(true)
@trans.write("\"Infinity\"")
- @prot.read_json_double.should == +1.0/0.0
+ expect(@prot.read_json_double).to eq(+1.0/0.0)
@trans.write("\"-Infinity\"")
- @prot.read_json_double.should == -1.0/0.0
+ expect(@prot.read_json_double).to eq(-1.0/0.0)
end
it "should read json object start" do
@trans.write("{")
- @prot.read_json_object_start.should == nil
+ expect(@prot.read_json_object_start).to eq(nil)
end
it "should read json object end" do
@trans.write("}")
- @prot.read_json_object_end.should == nil
+ expect(@prot.read_json_object_end).to eq(nil)
end
it "should read json array start" do
@trans.write("[")
- @prot.read_json_array_start.should == nil
+ expect(@prot.read_json_array_start).to eq(nil)
end
it "should read json array end" do
@trans.write("]")
- @prot.read_json_array_end.should == nil
+ expect(@prot.read_json_array_end).to eq(nil)
end
it "should read_message_begin" do
@@ -412,141 +412,141 @@ describe 'JsonProtocol' do
expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
@trans.write("[1,\"name\",12,32\"\"")
- @prot.read_message_begin.should == ["name", 12, 32]
+ expect(@prot.read_message_begin).to eq(["name", 12, 32])
end
it "should read message end" do
@trans.write("]")
- @prot.read_message_end.should == nil
+ expect(@prot.read_message_end).to eq(nil)
end
it "should read struct begin" do
@trans.write("{")
- @prot.read_struct_begin.should == nil
+ expect(@prot.read_struct_begin).to eq(nil)
end
it "should read struct end" do
@trans.write("}")
- @prot.read_struct_end.should == nil
+ expect(@prot.read_struct_end).to eq(nil)
end
it "should read field begin" do
@trans.write("1{\"rec\"")
- @prot.read_field_begin.should == [nil, 12, 1]
+ expect(@prot.read_field_begin).to eq([nil, 12, 1])
end
it "should read field end" do
@trans.write("}")
- @prot.read_field_end.should == nil
+ expect(@prot.read_field_end).to eq(nil)
end
it "should read map begin" do
@trans.write("[\"rec\",\"lst\",2,{")
- @prot.read_map_begin.should == [12, 15, 2]
+ expect(@prot.read_map_begin).to eq([12, 15, 2])
end
it "should read map end" do
@trans.write("}]")
- @prot.read_map_end.should == nil
+ expect(@prot.read_map_end).to eq(nil)
end
it "should read list begin" do
@trans.write("[\"rec\",2\"\"")
- @prot.read_list_begin.should == [12, 2]
+ expect(@prot.read_list_begin).to eq([12, 2])
end
it "should read list end" do
@trans.write("]")
- @prot.read_list_end.should == nil
+ expect(@prot.read_list_end).to eq(nil)
end
it "should read set begin" do
@trans.write("[\"rec\",2\"\"")
- @prot.read_set_begin.should == [12, 2]
+ expect(@prot.read_set_begin).to eq([12, 2])
end
it "should read set end" do
@trans.write("]")
- @prot.read_set_end.should == nil
+ expect(@prot.read_set_end).to eq(nil)
end
it "should read bool" do
@trans.write("0\"\"")
- @prot.read_bool.should == false
+ expect(@prot.read_bool).to eq(false)
@prot.read_string
@trans.write("1\"\"")
- @prot.read_bool.should == true
+ expect(@prot.read_bool).to eq(true)
end
it "should read byte" do
@trans.write("60\"\"")
- @prot.read_byte.should == 60
+ expect(@prot.read_byte).to eq(60)
end
it "should read i16" do
@trans.write("1000\"\"")
- @prot.read_i16.should == 1000
+ expect(@prot.read_i16).to eq(1000)
end
it "should read i32" do
@trans.write("3000000000\"\"")
- @prot.read_i32.should == 3000000000
+ expect(@prot.read_i32).to eq(3000000000)
end
it "should read i64" do
@trans.write("6000000000\"\"")
- @prot.read_i64.should == 6000000000
+ expect(@prot.read_i64).to eq(6000000000)
end
it "should read double" do
@trans.write("12.23\"\"")
- @prot.read_double.should == 12.23
+ expect(@prot.read_double).to eq(12.23)
end
if RUBY_VERSION >= '1.9'
it 'should read string' do
@trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
a = @prot.read_string
- a.should == 'this is a test string'
- a.encoding.should == Encoding::UTF_8
+ expect(a).to eq('this is a test string')
+ expect(a.encoding).to eq(Encoding::UTF_8)
end
it 'should read string with unicode characters' do
@trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
a = @prot.read_string
- a.should == "this is a test string with unicode characters: \u20AC \u20AD"
- a.encoding.should == Encoding::UTF_8
+ expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
+ expect(a.encoding).to eq(Encoding::UTF_8)
end
else
it 'should read string' do
@trans.write('"this is a test string"')
- @prot.read_string.should == 'this is a test string'
+ expect(@prot.read_string).to eq('this is a test string')
end
end
it "should read binary" do
@trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
- @prot.read_binary.should == "this is a test string"
+ expect(@prot.read_binary).to eq("this is a test string")
end
it "should read long binary" do
@trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
- @prot.read_binary.bytes.to_a.should == (0...256).to_a
+ expect(@prot.read_binary.bytes.to_a).to eq((0...256).to_a)
end
it "should provide a reasonable to_s" do
- @prot.to_s.should == "json(memory)"
+ expect(@prot.to_s).to eq("json(memory)")
end
end
describe Thrift::JsonProtocolFactory do
it "should create a JsonProtocol" do
- Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol)
+ expect(Thrift::JsonProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::JsonProtocol)
end
it "should provide a reasonable to_s" do
- Thrift::JsonProtocolFactory.new.to_s.should == "json"
+ expect(Thrift::JsonProtocolFactory.new.to_s).to eq("json")
end
end
end
diff --git a/lib/rb/spec/namespaced_spec.rb b/lib/rb/spec/namespaced_spec.rb
index 31379d964..4d6d369e5 100644
--- a/lib/rb/spec/namespaced_spec.rb
+++ b/lib/rb/spec/namespaced_spec.rb
@@ -32,7 +32,7 @@ describe 'namespaced generation' do
"other_namespace/referenced_constants.rb",
"other_namespace/referenced_types.rb"
].each do |name|
- File.exist?(File.join(prefix, name)).should be_true
+ expect(File.exist?(File.join(prefix, name))).to be_truthy
end
end
@@ -44,20 +44,20 @@ describe 'namespaced generation' do
"referenced_constants.rb",
"referenced_types.rb"
].each do |name|
- File.exist?(File.join(prefix, name)).should_not be_true
+ expect(File.exist?(File.join(prefix, name))).not_to be_truthy
end
end
it "has a service class in the right place" do
- defined?(NamespacedSpecNamespace::NamespacedNonblockingService).should be_true
+ expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
end
it "has a struct in the right place" do
- defined?(NamespacedSpecNamespace::Hello).should be_true
+ expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
end
it "required an included file" do
- defined?(OtherNamespace::SomeEnum).should be_true
+ expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
end
it "extended a service" do
diff --git a/lib/rb/spec/nonblocking_server_spec.rb b/lib/rb/spec/nonblocking_server_spec.rb
index 712cf45c2..613d88390 100644
--- a/lib/rb/spec/nonblocking_server_spec.rb
+++ b/lib/rb/spec/nonblocking_server_spec.rb
@@ -176,8 +176,8 @@ describe 'NonblockingServer' do
it "should handle basic message passing" do
client = setup_client
- client.greeting(true).should == SpecNamespace::Hello.new
- client.greeting(false).should == SpecNamespace::Hello.new(:greeting => 'Aloha!')
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
+ expect(client.greeting(false)).to eq(SpecNamespace::Hello.new(:greeting => 'Aloha!'))
@server.shutdown
end
@@ -195,7 +195,7 @@ describe 'NonblockingServer' do
end
4.times { trans_queue.pop }
setup_client.unblock(4)
- 4.times { queue.pop.should be_true }
+ 4.times { expect(queue.pop).to be_truthy }
@server.shutdown
end
@@ -212,15 +212,15 @@ describe 'NonblockingServer' do
queues[4] << :hello
queues[5] << :hello
queues[6] << :hello
- 3.times { result.pop.should == SpecNamespace::Hello.new }
- client.greeting(true).should == SpecNamespace::Hello.new
+ 3.times { expect(result.pop).to eq(SpecNamespace::Hello.new) }
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
queues[5] << [:unblock, 4]
- 4.times { result.pop.should be_true }
+ 4.times { expect(result.pop).to be_truthy }
queues[2] << :hello
- result.pop.should == SpecNamespace::Hello.new
- client.greeting(false).should == SpecNamespace::Hello.new(:greeting => 'Aloha!')
+ expect(result.pop).to eq(SpecNamespace::Hello.new)
+ expect(client.greeting(false)).to eq(SpecNamespace::Hello.new(:greeting => 'Aloha!'))
7.times { queues.shift << :exit }
- client.greeting(true).should == SpecNamespace::Hello.new
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
@server.shutdown
end
@@ -229,7 +229,7 @@ describe 'NonblockingServer' do
client = setup_client
client.greeting(false) # force a message pass
@server.shutdown
- @server_thread.join(2).should be_an_instance_of(Thread)
+ expect(@server_thread.join(2)).to be_an_instance_of(Thread)
end
it "should continue processing active messages when shutting down" do
@@ -238,8 +238,8 @@ describe 'NonblockingServer' do
client << :sleep
sleep 0.1 # give the server time to start processing the client's message
@server.shutdown
- @server_thread.join(2).should be_an_instance_of(Thread)
- result.pop.should == :slept
+ expect(@server_thread.join(2)).to be_an_instance_of(Thread)
+ expect(result.pop).to eq(:slept)
end
it "should kill active messages when they don't expire while shutting down" do
@@ -249,15 +249,15 @@ describe 'NonblockingServer' do
sleep 0.1 # start processing the client's message
@server.shutdown(1)
@catch_exceptions = true
- @server_thread.join(3).should_not be_nil
- result.should be_empty
+ expect(@server_thread.join(3)).not_to be_nil
+ expect(result).to be_empty
end
it "should allow shutting down in response to a message" do
client = setup_client
- client.greeting(true).should == SpecNamespace::Hello.new
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
client.shutdown
- @server_thread.join(2).should_not be_nil
+ expect(@server_thread.join(2)).not_to be_nil
end
end
end
diff --git a/lib/rb/spec/processor_spec.rb b/lib/rb/spec/processor_spec.rb
index 989f5cca1..d30553f55 100644
--- a/lib/rb/spec/processor_spec.rb
+++ b/lib/rb/spec/processor_spec.rb
@@ -27,52 +27,52 @@ describe 'Processor' do
describe Thrift::Processor do
before(:each) do
- @processor = ProcessorSpec.new(mock("MockHandler"))
- @prot = mock("MockProtocol")
+ @processor = ProcessorSpec.new(double("MockHandler"))
+ @prot = double("MockProtocol")
end
def mock_trans(obj)
- obj.should_receive(:trans).ordered.and_return do
- mock("trans").tap do |trans|
- trans.should_receive(:flush).ordered
+ expect(obj).to receive(:trans).ordered do
+ double("trans").tap do |trans|
+ expect(trans).to receive(:flush).ordered
end
end
end
it "should call process_<message> when it receives that message" do
- @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 17]
- @processor.should_receive(:process_testMessage).with(17, @prot, @prot).ordered
- @processor.process(@prot, @prot).should == true
+ expect(@prot).to receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 17]
+ expect(@processor).to receive(:process_testMessage).with(17, @prot, @prot).ordered
+ expect(@processor.process(@prot, @prot)).to eq(true)
end
it "should raise an ApplicationException when the received message cannot be processed" do
- @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
- @prot.should_receive(:skip).with(Thrift::Types::STRUCT).ordered
- @prot.should_receive(:read_message_end).ordered
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::EXCEPTION, 4).ordered
- e = mock(Thrift::ApplicationException)
- e.should_receive(:write).with(@prot).ordered
- Thrift::ApplicationException.should_receive(:new).with(Thrift::ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return(e)
- @prot.should_receive(:write_message_end).ordered
+ expect(@prot).to receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
+ expect(@prot).to receive(:skip).with(Thrift::Types::STRUCT).ordered
+ expect(@prot).to receive(:read_message_end).ordered
+ expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::EXCEPTION, 4).ordered
+ e = double(Thrift::ApplicationException)
+ expect(e).to receive(:write).with(@prot).ordered
+ expect(Thrift::ApplicationException).to receive(:new).with(Thrift::ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return(e)
+ expect(@prot).to receive(:write_message_end).ordered
mock_trans(@prot)
@processor.process(@prot, @prot)
end
it "should pass args off to the args class" do
- args_class = mock("MockArgsClass")
- args = mock("#<MockArgsClass:mock>").tap do |args|
- args.should_receive(:read).with(@prot).ordered
+ args_class = double("MockArgsClass")
+ args = double("#<MockArgsClass:mock>").tap do |args|
+ expect(args).to receive(:read).with(@prot).ordered
end
- args_class.should_receive(:new).and_return args
- @prot.should_receive(:read_message_end).ordered
- @processor.read_args(@prot, args_class).should eql(args)
+ expect(args_class).to receive(:new).and_return args
+ expect(@prot).to receive(:read_message_end).ordered
+ expect(@processor.read_args(@prot, args_class)).to eql(args)
end
it "should write out a reply when asked" do
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::REPLY, 23).ordered
- result = mock("MockResult")
- result.should_receive(:write).with(@prot).ordered
- @prot.should_receive(:write_message_end).ordered
+ expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::REPLY, 23).ordered
+ result = double("MockResult")
+ expect(result).to receive(:write).with(@prot).ordered
+ expect(@prot).to receive(:write_message_end).ordered
mock_trans(@prot)
@processor.write_result(result, @prot, 'testMessage', 23)
end
diff --git a/lib/rb/spec/serializer_spec.rb b/lib/rb/spec/serializer_spec.rb
index 599b454bb..2a7dc6db9 100644
--- a/lib/rb/spec/serializer_spec.rb
+++ b/lib/rb/spec/serializer_spec.rb
@@ -25,19 +25,19 @@ describe 'Serializer' do
it "should serialize structs to binary by default" do
serializer = Thrift::Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
data = serializer.serialize(SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!"))
- data.should == "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
+ expect(data).to eq("\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00")
end
it "should serialize structs to the given protocol" do
- protocol = Thrift::BaseProtocol.new(mock("transport"))
- protocol.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
- protocol.should_receive(:write_field_begin).with("greeting", Thrift::Types::STRING, 1)
- protocol.should_receive(:write_string).with("Good day")
- protocol.should_receive(:write_field_end)
- protocol.should_receive(:write_field_stop)
- protocol.should_receive(:write_struct_end)
- protocol_factory = mock("ProtocolFactory")
- protocol_factory.stub!(:get_protocol).and_return(protocol)
+ protocol = Thrift::BaseProtocol.new(double("transport"))
+ expect(protocol).to receive(:write_struct_begin).with("SpecNamespace::Hello")
+ expect(protocol).to receive(:write_field_begin).with("greeting", Thrift::Types::STRING, 1)
+ expect(protocol).to receive(:write_string).with("Good day")
+ expect(protocol).to receive(:write_field_end)
+ expect(protocol).to receive(:write_field_stop)
+ expect(protocol).to receive(:write_struct_end)
+ protocol_factory = double("ProtocolFactory")
+ allow(protocol_factory).to receive(:get_protocol).and_return(protocol)
serializer = Thrift::Serializer.new(protocol_factory)
serializer.serialize(SpecNamespace::Hello.new(:greeting => "Good day"))
end
@@ -47,21 +47,21 @@ describe 'Serializer' do
it "should deserialize structs from binary by default" do
deserializer = Thrift::Deserializer.new
data = "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
- deserializer.deserialize(SpecNamespace::Hello.new, data).should == SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!")
+ expect(deserializer.deserialize(SpecNamespace::Hello.new, data)).to eq(SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!"))
end
it "should deserialize structs from the given protocol" do
- protocol = Thrift::BaseProtocol.new(mock("transport"))
- protocol.should_receive(:read_struct_begin).and_return("SpecNamespace::Hello")
- protocol.should_receive(:read_field_begin).and_return(["greeting", Thrift::Types::STRING, 1],
+ protocol = Thrift::BaseProtocol.new(double("transport"))
+ expect(protocol).to receive(:read_struct_begin).and_return("SpecNamespace::Hello")
+ expect(protocol).to receive(:read_field_begin).and_return(["greeting", Thrift::Types::STRING, 1],
[nil, Thrift::Types::STOP, 0])
- protocol.should_receive(:read_string).and_return("Good day")
- protocol.should_receive(:read_field_end)
- protocol.should_receive(:read_struct_end)
- protocol_factory = mock("ProtocolFactory")
- protocol_factory.stub!(:get_protocol).and_return(protocol)
+ expect(protocol).to receive(:read_string).and_return("Good day")
+ expect(protocol).to receive(:read_field_end)
+ expect(protocol).to receive(:read_struct_end)
+ protocol_factory = double("ProtocolFactory")
+ allow(protocol_factory).to receive(:get_protocol).and_return(protocol)
deserializer = Thrift::Deserializer.new(protocol_factory)
- deserializer.deserialize(SpecNamespace::Hello.new, "").should == SpecNamespace::Hello.new(:greeting => "Good day")
+ expect(deserializer.deserialize(SpecNamespace::Hello.new, "")).to eq(SpecNamespace::Hello.new(:greeting => "Good day"))
end
end
end
diff --git a/lib/rb/spec/server_socket_spec.rb b/lib/rb/spec/server_socket_spec.rb
index 126948fa8..ec9e55005 100644
--- a/lib/rb/spec/server_socket_spec.rb
+++ b/lib/rb/spec/server_socket_spec.rb
@@ -28,57 +28,57 @@ describe 'Thrift::ServerSocket' do
end
it "should create a handle when calling listen" do
- TCPServer.should_receive(:new).with(nil, 1234)
+ expect(TCPServer).to receive(:new).with(nil, 1234)
@socket.listen
end
it "should accept an optional host argument" do
@socket = Thrift::ServerSocket.new('localhost', 1234)
- TCPServer.should_receive(:new).with('localhost', 1234)
+ expect(TCPServer).to receive(:new).with('localhost', 1234)
@socket.to_s == "server(localhost:1234)"
@socket.listen
end
it "should create a Thrift::Socket to wrap accepted sockets" do
- handle = mock("TCPServer")
- TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
+ handle = double("TCPServer")
+ expect(TCPServer).to receive(:new).with(nil, 1234).and_return(handle)
@socket.listen
- sock = mock("sock")
- handle.should_receive(:accept).and_return(sock)
- trans = mock("Socket")
- Thrift::Socket.should_receive(:new).and_return(trans)
- trans.should_receive(:handle=).with(sock)
- @socket.accept.should == trans
+ sock = double("sock")
+ expect(handle).to receive(:accept).and_return(sock)
+ trans = double("Socket")
+ expect(Thrift::Socket).to receive(:new).and_return(trans)
+ expect(trans).to receive(:handle=).with(sock)
+ expect(@socket.accept).to eq(trans)
end
it "should close the handle when closed" do
- handle = mock("TCPServer", :closed? => false)
- TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
+ handle = double("TCPServer", :closed? => false)
+ expect(TCPServer).to receive(:new).with(nil, 1234).and_return(handle)
@socket.listen
- handle.should_receive(:close)
+ expect(handle).to receive(:close)
@socket.close
end
it "should return nil when accepting if there is no handle" do
- @socket.accept.should be_nil
+ expect(@socket.accept).to be_nil
end
it "should return true for closed? when appropriate" do
- handle = mock("TCPServer", :closed? => false)
- TCPServer.stub!(:new).and_return(handle)
+ handle = double("TCPServer", :closed? => false)
+ allow(TCPServer).to receive(:new).and_return(handle)
@socket.listen
- @socket.should_not be_closed
- handle.stub!(:close)
+ expect(@socket).not_to be_closed
+ allow(handle).to receive(:close)
@socket.close
- @socket.should be_closed
+ expect(@socket).to be_closed
@socket.listen
- @socket.should_not be_closed
- handle.stub!(:closed?).and_return(true)
- @socket.should be_closed
+ expect(@socket).not_to be_closed
+ allow(handle).to receive(:closed?).and_return(true)
+ expect(@socket).to be_closed
end
it "should provide a reasonable to_s" do
- @socket.to_s.should == "socket(:1234)"
+ expect(@socket.to_s).to eq("socket(:1234)")
end
end
end
diff --git a/lib/rb/spec/server_spec.rb b/lib/rb/spec/server_spec.rb
index bc4d598bb..ee58c7cb4 100644
--- a/lib/rb/spec/server_spec.rb
+++ b/lib/rb/spec/server_spec.rb
@@ -22,17 +22,17 @@ describe 'Server' do
describe Thrift::BaseServer do
before(:each) do
- @processor = mock("Processor")
- @serverTrans = mock("ServerTransport")
- @trans = mock("BaseTransport")
- @prot = mock("BaseProtocol")
+ @processor = double("Processor")
+ @serverTrans = double("ServerTransport")
+ @trans = double("BaseTransport")
+ @prot = double("BaseProtocol")
@server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
- @server = Thrift::BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
- @server.instance_variable_get(:'@transport_factory').should be_an_instance_of(Thrift::BaseTransportFactory)
- @server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(Thrift::BinaryProtocolFactory)
+ @server = Thrift::BaseServer.new(double("Processor"), double("BaseServerTransport"))
+ expect(@server.instance_variable_get(:'@transport_factory')).to be_an_instance_of(Thrift::BaseTransportFactory)
+ expect(@server.instance_variable_get(:'@protocol_factory')).to be_an_instance_of(Thrift::BinaryProtocolFactory)
end
it "should not serve" do
@@ -40,107 +40,107 @@ describe 'Server' do
end
it "should provide a reasonable to_s" do
- @serverTrans.should_receive(:to_s).once.and_return("serverTrans")
- @trans.should_receive(:to_s).once.and_return("trans")
- @prot.should_receive(:to_s).once.and_return("prot")
- @server.to_s.should == "server(prot(trans(serverTrans)))"
+ expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
+ expect(@trans).to receive(:to_s).once.and_return("trans")
+ expect(@prot).to receive(:to_s).once.and_return("prot")
+ expect(@server.to_s).to eq("server(prot(trans(serverTrans)))")
end
end
describe Thrift::SimpleServer do
before(:each) do
- @processor = mock("Processor")
- @serverTrans = mock("ServerTransport")
- @trans = mock("BaseTransport")
- @prot = mock("BaseProtocol")
- @client = mock("Client")
+ @processor = double("Processor")
+ @serverTrans = double("ServerTransport")
+ @trans = double("BaseTransport")
+ @prot = double("BaseProtocol")
+ @client = double("Client")
@server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should provide a reasonable to_s" do
- @serverTrans.should_receive(:to_s).once.and_return("serverTrans")
- @trans.should_receive(:to_s).once.and_return("trans")
- @prot.should_receive(:to_s).once.and_return("prot")
- @server.to_s.should == "simple(server(prot(trans(serverTrans))))"
+ expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
+ expect(@trans).to receive(:to_s).once.and_return("trans")
+ expect(@prot).to receive(:to_s).once.and_return("prot")
+ expect(@server.to_s).to eq("simple(server(prot(trans(serverTrans))))")
end
it "should serve in the main thread" do
- @serverTrans.should_receive(:listen).ordered
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
- @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
- @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
+ expect(@serverTrans).to receive(:listen).ordered
+ expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
+ expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
+ expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
x = 0
- @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
+ expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
case (x += 1)
when 1 then raise Thrift::TransportException
when 2 then raise Thrift::ProtocolException
when 3 then throw :stop
end
end
- @trans.should_receive(:close).exactly(3).times
- @serverTrans.should_receive(:close).ordered
- lambda { @server.serve }.should throw_symbol(:stop)
+ expect(@trans).to receive(:close).exactly(3).times
+ expect(@serverTrans).to receive(:close).ordered
+ expect { @server.serve }.to throw_symbol(:stop)
end
end
describe Thrift::ThreadedServer do
before(:each) do
- @processor = mock("Processor")
- @serverTrans = mock("ServerTransport")
- @trans = mock("BaseTransport")
- @prot = mock("BaseProtocol")
- @client = mock("Client")
+ @processor = double("Processor")
+ @serverTrans = double("ServerTransport")
+ @trans = double("BaseTransport")
+ @prot = double("BaseProtocol")
+ @client = double("Client")
@server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should provide a reasonable to_s" do
- @serverTrans.should_receive(:to_s).once.and_return("serverTrans")
- @trans.should_receive(:to_s).once.and_return("trans")
- @prot.should_receive(:to_s).once.and_return("prot")
- @server.to_s.should == "threaded(server(prot(trans(serverTrans))))"
+ expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
+ expect(@trans).to receive(:to_s).once.and_return("trans")
+ expect(@prot).to receive(:to_s).once.and_return("prot")
+ expect(@server.to_s).to eq("threaded(server(prot(trans(serverTrans))))")
end
it "should serve using threads" do
- @serverTrans.should_receive(:listen).ordered
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
- @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
- @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
- Thread.should_receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
+ expect(@serverTrans).to receive(:listen).ordered
+ expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
+ expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
+ expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
+ expect(Thread).to receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
x = 0
- @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
+ expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
case (x += 1)
when 1 then raise Thrift::TransportException
when 2 then raise Thrift::ProtocolException
when 3 then throw :stop
end
end
- @trans.should_receive(:close).exactly(3).times
- @serverTrans.should_receive(:close).ordered
- lambda { @server.serve }.should throw_symbol(:stop)
+ expect(@trans).to receive(:close).exactly(3).times
+ expect(@serverTrans).to receive(:close).ordered
+ expect { @server.serve }.to throw_symbol(:stop)
end
end
describe Thrift::ThreadPoolServer do
before(:each) do
- @processor = mock("Processor")
- @server_trans = mock("ServerTransport")
- @trans = mock("BaseTransport")
- @prot = mock("BaseProtocol")
- @client = mock("Client")
+ @processor = double("Processor")
+ @server_trans = double("ServerTransport")
+ @trans = double("BaseTransport")
+ @prot = double("BaseProtocol")
+ @client = double("Client")
@server = described_class.new(@processor, @server_trans, @trans, @prot)
sleep(0.15)
end
it "should provide a reasonable to_s" do
- @server_trans.should_receive(:to_s).once.and_return("server_trans")
- @trans.should_receive(:to_s).once.and_return("trans")
- @prot.should_receive(:to_s).once.and_return("prot")
- @server.to_s.should == "threadpool(server(prot(trans(server_trans))))"
+ expect(@server_trans).to receive(:to_s).once.and_return("server_trans")
+ expect(@trans).to receive(:to_s).once.and_return("trans")
+ expect(@prot).to receive(:to_s).once.and_return("prot")
+ expect(@server.to_s).to eq("threadpool(server(prot(trans(server_trans))))")
end
it "should serve inside a thread" do
exception_q = @server.instance_variable_get(:@exception_q)
- described_class.any_instance.should_receive(:serve) do
+ expect_any_instance_of(described_class).to receive(:serve) do
exception_q.push(StandardError.new('ERROR'))
end
expect { @server.rescuable_serve }.to(raise_error('ERROR'))
@@ -148,7 +148,7 @@ describe 'Server' do
it "should avoid running the server twice when retrying rescuable_serve" do
exception_q = @server.instance_variable_get(:@exception_q)
- described_class.any_instance.should_receive(:serve) do
+ expect_any_instance_of(described_class).to receive(:serve) do
exception_q.push(StandardError.new('ERROR1'))
exception_q.push(StandardError.new('ERROR2'))
end
@@ -157,29 +157,29 @@ describe 'Server' do
end
it "should serve using a thread pool" do
- thread_q = mock("SizedQueue")
- exception_q = mock("Queue")
+ thread_q = double("SizedQueue")
+ exception_q = double("Queue")
@server.instance_variable_set(:@thread_q, thread_q)
@server.instance_variable_set(:@exception_q, exception_q)
- @server_trans.should_receive(:listen).ordered
- thread_q.should_receive(:push).with(:token)
- thread_q.should_receive(:pop)
- Thread.should_receive(:new).and_yield
- @server_trans.should_receive(:accept).exactly(3).times.and_return(@client)
- @trans.should_receive(:get_transport).exactly(3).times.and_return(@trans)
- @prot.should_receive(:get_protocol).exactly(3).times.and_return(@prot)
+ expect(@server_trans).to receive(:listen).ordered
+ expect(thread_q).to receive(:push).with(:token)
+ expect(thread_q).to receive(:pop)
+ expect(Thread).to receive(:new).and_yield
+ expect(@server_trans).to receive(:accept).exactly(3).times.and_return(@client)
+ expect(@trans).to receive(:get_transport).exactly(3).times.and_return(@trans)
+ expect(@prot).to receive(:get_protocol).exactly(3).times.and_return(@prot)
x = 0
error = RuntimeError.new("Stopped")
- @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
+ expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
case (x += 1)
when 1 then raise Thrift::TransportException
when 2 then raise Thrift::ProtocolException
when 3 then raise error
end
end
- @trans.should_receive(:close).exactly(3).times
- exception_q.should_receive(:push).with(error).and_throw(:stop)
- @server_trans.should_receive(:close)
+ expect(@trans).to receive(:close).exactly(3).times
+ expect(exception_q).to receive(:push).with(error).and_throw(:stop)
+ expect(@server_trans).to receive(:close)
expect { @server.serve }.to(throw_symbol(:stop))
end
end
diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb
index df56ba5b0..202c745ea 100644
--- a/lib/rb/spec/socket_spec.rb
+++ b/lib/rb/spec/socket_spec.rb
@@ -25,44 +25,44 @@ describe 'Socket' do
describe Thrift::Socket do
before(:each) do
@socket = Thrift::Socket.new
- @handle = mock("Handle", :closed? => false)
- @handle.stub!(:close)
- @handle.stub!(:connect_nonblock)
- @handle.stub!(:setsockopt)
- ::Socket.stub!(:new).and_return(@handle)
+ @handle = double("Handle", :closed? => false)
+ allow(@handle).to receive(:close)
+ allow(@handle).to receive(:connect_nonblock)
+ allow(@handle).to receive(:setsockopt)
+ allow(::Socket).to receive(:new).and_return(@handle)
end
it_should_behave_like "a socket"
it "should raise a TransportException when it cannot open a socket" do
- ::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
- lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
+ expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
+ expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
end
it "should open a ::Socket with default args" do
- ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true, :setsockopt => nil))
- ::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
- ::Socket.should_receive(:sockaddr_in)
+ expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
+ expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
+ expect(::Socket).to receive(:sockaddr_in)
@socket.to_s == "socket(localhost:9090)"
@socket.open
end
it "should accept host/port options" do
- ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true, :setsockopt => nil))
- ::Socket.should_receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
- ::Socket.should_receive(:sockaddr_in)
+ expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
+ expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
+ expect(::Socket).to receive(:sockaddr_in)
@socket = Thrift::Socket.new('my.domain', 1234).open
@socket.to_s == "socket(my.domain:1234)"
end
it "should accept an optional timeout" do
- ::Socket.stub!(:new)
- Thrift::Socket.new('localhost', 8080, 5).timeout.should == 5
+ allow(::Socket).to receive(:new)
+ expect(Thrift::Socket.new('localhost', 8080, 5).timeout).to eq(5)
end
it "should provide a reasonable to_s" do
- ::Socket.stub!(:new)
- Thrift::Socket.new('myhost', 8090).to_s.should == "socket(myhost:8090)"
+ allow(::Socket).to receive(:new)
+ expect(Thrift::Socket.new('myhost', 8090).to_s).to eq("socket(myhost:8090)")
end
end
end
diff --git a/lib/rb/spec/socket_spec_shared.rb b/lib/rb/spec/socket_spec_shared.rb
index 5fddc16a7..32bdb71f0 100644
--- a/lib/rb/spec/socket_spec_shared.rb
+++ b/lib/rb/spec/socket_spec_shared.rb
@@ -21,84 +21,84 @@ require 'spec_helper'
shared_examples_for "a socket" do
it "should open a socket" do
- @socket.open.should == @handle
+ expect(@socket.open).to eq(@handle)
end
it "should be open whenever it has a handle" do
- @socket.should_not be_open
+ expect(@socket).not_to be_open
@socket.open
- @socket.should be_open
+ expect(@socket).to be_open
@socket.handle = nil
- @socket.should_not be_open
+ expect(@socket).not_to be_open
@socket.handle = @handle
@socket.close
- @socket.should_not be_open
+ expect(@socket).not_to be_open
end
it "should write data to the handle" do
@socket.open
- @handle.should_receive(:write).with("foobar")
+ expect(@handle).to receive(:write).with("foobar")
@socket.write("foobar")
- @handle.should_receive(:write).with("fail").and_raise(StandardError)
- lambda { @socket.write("fail") }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
+ expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
+ expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
end
it "should raise an error when it cannot read from the handle" do
@socket.open
- @handle.should_receive(:readpartial).with(17).and_raise(StandardError)
- lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
+ expect(@handle).to receive(:readpartial).with(17).and_raise(StandardError)
+ expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
end
it "should return the data read when reading from the handle works" do
@socket.open
- @handle.should_receive(:readpartial).with(17).and_return("test data")
- @socket.read(17).should == "test data"
+ expect(@handle).to receive(:readpartial).with(17).and_return("test data")
+ expect(@socket.read(17)).to eq("test data")
end
it "should declare itself as closed when it has an error" do
@socket.open
- @handle.should_receive(:write).with("fail").and_raise(StandardError)
- @socket.should be_open
- lambda { @socket.write("fail") }.should raise_error
- @socket.should_not be_open
+ expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
+ expect(@socket).to be_open
+ expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
+ expect(@socket).not_to be_open
end
it "should raise an error when the stream is closed" do
@socket.open
- @handle.stub!(:closed?).and_return(true)
- @socket.should_not be_open
- lambda { @socket.write("fail") }.should raise_error(IOError, "closed stream")
- lambda { @socket.read(10) }.should raise_error(IOError, "closed stream")
+ allow(@handle).to receive(:closed?).and_return(true)
+ expect(@socket).not_to be_open
+ expect { @socket.write("fail") }.to raise_error(IOError, "closed stream")
+ expect { @socket.read(10) }.to raise_error(IOError, "closed stream")
end
it "should support the timeout accessor for read" do
@socket.timeout = 3
@socket.open
- IO.should_receive(:select).with([@handle], nil, nil, 3).and_return([[@handle], [], []])
- @handle.should_receive(:readpartial).with(17).and_return("test data")
- @socket.read(17).should == "test data"
+ expect(IO).to receive(:select).with([@handle], nil, nil, 3).and_return([[@handle], [], []])
+ expect(@handle).to receive(:readpartial).with(17).and_return("test data")
+ expect(@socket.read(17)).to eq("test data")
end
it "should support the timeout accessor for write" do
@socket.timeout = 3
@socket.open
- IO.should_receive(:select).with(nil, [@handle], nil, 3).twice.and_return([[], [@handle], []])
- @handle.should_receive(:write_nonblock).with("test data").and_return(4)
- @handle.should_receive(:write_nonblock).with(" data").and_return(5)
- @socket.write("test data").should == 9
+ expect(IO).to receive(:select).with(nil, [@handle], nil, 3).twice.and_return([[], [@handle], []])
+ expect(@handle).to receive(:write_nonblock).with("test data").and_return(4)
+ expect(@handle).to receive(:write_nonblock).with(" data").and_return(5)
+ expect(@socket.write("test data")).to eq(9)
end
it "should raise an error when read times out" do
@socket.timeout = 0.5
@socket.open
- IO.should_receive(:select).once {sleep(0.5); nil}
- lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
+ expect(IO).to receive(:select).once {sleep(0.5); nil}
+ expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
end
it "should raise an error when write times out" do
@socket.timeout = 0.5
@socket.open
- IO.should_receive(:select).with(nil, [@handle], nil, 0.5).any_number_of_times.and_return(nil)
- lambda { @socket.write("test data") }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
+ allow(IO).to receive(:select).with(nil, [@handle], nil, 0.5).and_return(nil)
+ expect { @socket.write("test data") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
end
end
diff --git a/lib/rb/spec/ssl_server_socket_spec.rb b/lib/rb/spec/ssl_server_socket_spec.rb
index 55f3fe277..82e651843 100644
--- a/lib/rb/spec/ssl_server_socket_spec.rb
+++ b/lib/rb/spec/ssl_server_socket_spec.rb
@@ -28,7 +28,7 @@ describe 'SSLServerSocket' do
end
it "should provide a reasonable to_s" do
- @socket.to_s.should == "ssl(socket(:1234))"
+ expect(@socket.to_s).to eq("ssl(socket(:1234))")
end
end
end
diff --git a/lib/rb/spec/ssl_socket_spec.rb b/lib/rb/spec/ssl_socket_spec.rb
index 9ee946bcb..808d8d512 100644
--- a/lib/rb/spec/ssl_socket_spec.rb
+++ b/lib/rb/spec/ssl_socket_spec.rb
@@ -26,53 +26,53 @@ describe 'SSLSocket' do
before(:each) do
@context = OpenSSL::SSL::SSLContext.new
@socket = Thrift::SSLSocket.new
- @simple_socket_handle = mock("Handle", :closed? => false)
- @simple_socket_handle.stub!(:close)
- @simple_socket_handle.stub!(:connect_nonblock)
- @simple_socket_handle.stub!(:setsockopt)
+ @simple_socket_handle = double("Handle", :closed? => false)
+ allow(@simple_socket_handle).to receive(:close)
+ allow(@simple_socket_handle).to receive(:connect_nonblock)
+ allow(@simple_socket_handle).to receive(:setsockopt)
- @handle = mock(mock("SSLHandle", :connect_nonblock => true, :post_connection_check => true), :closed? => false)
- @handle.stub!(:connect_nonblock)
- @handle.stub!(:close)
- @handle.stub!(:post_connection_check)
+ @handle = double(double("SSLHandle", :connect_nonblock => true, :post_connection_check => true), :closed? => false)
+ allow(@handle).to receive(:connect_nonblock)
+ allow(@handle).to receive(:close)
+ allow(@handle).to receive(:post_connection_check)
- ::Socket.stub!(:new).and_return(@simple_socket_handle)
- OpenSSL::SSL::SSLSocket.stub!(:new).and_return(@handle)
+ allow(::Socket).to receive(:new).and_return(@simple_socket_handle)
+ allow(OpenSSL::SSL::SSLSocket).to receive(:new).and_return(@handle)
end
it_should_behave_like "a socket"
it "should raise a TransportException when it cannot open a ssl socket" do
- ::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
- lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
+ expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
+ expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
end
it "should open a ::Socket with default args" do
- OpenSSL::SSL::SSLSocket.should_receive(:new).with(@simple_socket_handle, nil).and_return(@handle)
- @handle.should_receive(:post_connection_check).with('localhost')
+ expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(@simple_socket_handle, nil).and_return(@handle)
+ expect(@handle).to receive(:post_connection_check).with('localhost')
@socket.open
end
it "should accept host/port options" do
- handle = mock("Handle", :connect_nonblock => true, :setsockopt => nil)
- ::Socket.stub!(:new).and_return(handle)
- ::Socket.should_receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
- ::Socket.should_receive(:sockaddr_in)
- OpenSSL::SSL::SSLSocket.should_receive(:new).with(handle, nil).and_return(@handle)
- @handle.should_receive(:post_connection_check).with('my.domain')
+ handle = double("Handle", :connect_nonblock => true, :setsockopt => nil)
+ allow(::Socket).to receive(:new).and_return(handle)
+ expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
+ expect(::Socket).to receive(:sockaddr_in)
+ expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(handle, nil).and_return(@handle)
+ expect(@handle).to receive(:post_connection_check).with('my.domain')
Thrift::SSLSocket.new('my.domain', 1234, 6000, nil).open
end
it "should accept an optional timeout" do
- Thrift::SSLSocket.new('localhost', 8080, 5).timeout.should == 5
+ expect(Thrift::SSLSocket.new('localhost', 8080, 5).timeout).to eq(5)
end
it "should accept an optional context" do
- Thrift::SSLSocket.new('localhost', 8080, 5, @context).ssl_context.should == @context
+ expect(Thrift::SSLSocket.new('localhost', 8080, 5, @context).ssl_context).to eq(@context)
end
it "should provide a reasonable to_s" do
- Thrift::SSLSocket.new('myhost', 8090).to_s.should == "ssl(socket(myhost:8090))"
+ expect(Thrift::SSLSocket.new('myhost', 8090).to_s).to eq("ssl(socket(myhost:8090))")
end
end
end
diff --git a/lib/rb/spec/struct_nested_containers_spec.rb b/lib/rb/spec/struct_nested_containers_spec.rb
index dc8ce5f58..d063569b5 100644
--- a/lib/rb/spec/struct_nested_containers_spec.rb
+++ b/lib/rb/spec/struct_nested_containers_spec.rb
@@ -39,9 +39,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ]
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value.push [3, 4, 5]
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -52,9 +52,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ].to_set
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value.add [3, 4, 5]
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -65,9 +65,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = { [1, 2, 3] => 1, [2, 3, 4] => 2 }
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value[[3, 4, 5]] = 3
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -78,9 +78,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = { 1 => [1, 2, 3], 2 => [2, 3, 4] }
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value[3] = [3, 4, 5]
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -91,9 +91,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ]
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value.push([3, 4, 5].to_set)
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -104,9 +104,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ].to_set
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value.add([3, 4, 5].to_set)
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -117,9 +117,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = { [1, 2, 3].to_set => 1, [2, 3, 4].to_set => 2 }
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value[[3, 4, 5].to_set] = 3
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -130,9 +130,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = { 1 => [1, 2, 3].to_set, 2 => [2, 3, 4].to_set }
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value[3] = [3, 4, 5].to_set
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -143,9 +143,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ]
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value.push({ 3 => 4, 5 => 6 })
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -156,9 +156,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ].to_set
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value.add({ 3 => 4, 5 => 6 })
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -169,9 +169,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = { { 1 => 2, 3 => 4} => 1, {2 => 3, 4 => 5} => 2 }
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value[{3 => 4, 5 => 6}] = 3
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
@@ -182,9 +182,9 @@ describe 'StructNestedContainers' do
thrift_struct.value = { 1 => { 1 => 2, 3 => 4}, 2 => {2 => 3, 4 => 5} }
thrift_struct.validate
end
- a.should == b
+ expect(a).to eq(b)
b.value[3] = { 3 => 4, 5 => 6 }
- a.should_not == b
+ expect(a).not_to eq(b)
end
end
end
diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb
index 6534d616a..b09c7f626 100644
--- a/lib/rb/spec/struct_spec.rb
+++ b/lib/rb/spec/struct_spec.rb
@@ -25,7 +25,7 @@ describe 'Struct' do
it "should iterate over all fields properly" do
fields = {}
SpecNamespace::Foo.new.each_field { |fid,field_info| fields[fid] = field_info }
- fields.should == SpecNamespace::Foo::FIELDS
+ expect(fields).to eq(SpecNamespace::Foo::FIELDS)
end
it "should initialize all fields to defaults" do
@@ -39,19 +39,19 @@ describe 'Struct' do
end
def validate_default_arguments(object)
- object.simple.should == 53
- object.words.should == "words"
- object.hello.should == SpecNamespace::Hello.new(:greeting => 'hello, world!')
- object.ints.should == [1, 2, 2, 3]
- object.complex.should be_nil
- object.shorts.should == Set.new([5, 17, 239])
+ expect(object.simple).to eq(53)
+ expect(object.words).to eq("words")
+ expect(object.hello).to eq(SpecNamespace::Hello.new(:greeting => 'hello, world!'))
+ expect(object.ints).to eq([1, 2, 2, 3])
+ expect(object.complex).to be_nil
+ expect(object.shorts).to eq(Set.new([5, 17, 239]))
end
it "should not share default values between instances" do
begin
struct = SpecNamespace::Foo.new
struct.ints << 17
- SpecNamespace::Foo.new.ints.should == [1,2,2,3]
+ expect(SpecNamespace::Foo.new.ints).to eq([1,2,2,3])
ensure
# ensure no leakage to other tests
SpecNamespace::Foo::FIELDS[4][:default] = [1,2,2,3]
@@ -60,48 +60,48 @@ describe 'Struct' do
it "should properly initialize boolean values" do
struct = SpecNamespace::BoolStruct.new(:yesno => false)
- struct.yesno.should be_false
+ expect(struct.yesno).to be_falsey
end
it "should have proper == semantics" do
- SpecNamespace::Foo.new.should_not == SpecNamespace::Hello.new
- SpecNamespace::Foo.new.should == SpecNamespace::Foo.new
- SpecNamespace::Foo.new(:simple => 52).should_not == SpecNamespace::Foo.new
+ expect(SpecNamespace::Foo.new).not_to eq(SpecNamespace::Hello.new)
+ expect(SpecNamespace::Foo.new).to eq(SpecNamespace::Foo.new)
+ expect(SpecNamespace::Foo.new(:simple => 52)).not_to eq(SpecNamespace::Foo.new)
end
it "should print enum value names in inspect" do
- SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::StructWithSomeEnum some_enum:ONE (0)>"
+ expect(SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect).to eq("<SpecNamespace::StructWithSomeEnum some_enum:ONE (0)>")
- SpecNamespace::StructWithEnumMap.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::StructWithEnumMap my_map:{ONE (0): [TWO (1)]}>"
+ expect(SpecNamespace::StructWithEnumMap.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect).to eq("<SpecNamespace::StructWithEnumMap my_map:{ONE (0): [TWO (1)]}>")
end
it "should pretty print binary fields" do
- SpecNamespace::Foo2.new(:my_binary => "\001\002\003").inspect.should == "<SpecNamespace::Foo2 my_binary:010203>"
+ expect(SpecNamespace::Foo2.new(:my_binary => "\001\002\003").inspect).to eq("<SpecNamespace::Foo2 my_binary:010203>")
end
it "should offer field? methods" do
- SpecNamespace::Foo.new.opt_string?.should be_false
- SpecNamespace::Foo.new(:simple => 52).simple?.should be_true
- SpecNamespace::Foo.new(:my_bool => false).my_bool?.should be_true
- SpecNamespace::Foo.new(:my_bool => true).my_bool?.should be_true
+ expect(SpecNamespace::Foo.new.opt_string?).to be_falsey
+ expect(SpecNamespace::Foo.new(:simple => 52).simple?).to be_truthy
+ expect(SpecNamespace::Foo.new(:my_bool => false).my_bool?).to be_truthy
+ expect(SpecNamespace::Foo.new(:my_bool => true).my_bool?).to be_truthy
end
it "should be comparable" do
s1 = SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::ONE)
s2 = SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::TWO)
- (s1 <=> s2).should == -1
- (s2 <=> s1).should == 1
- (s1 <=> s1).should == 0
- (s1 <=> SpecNamespace::StructWithSomeEnum.new()).should == -1
+ expect(s1 <=> s2).to eq(-1)
+ expect(s2 <=> s1).to eq(1)
+ expect(s1 <=> s1).to eq(0)
+ expect(s1 <=> SpecNamespace::StructWithSomeEnum.new()).to eq(-1)
end
it "should read itself off the wire" do
struct = SpecNamespace::Foo.new
- prot = Thrift::BaseProtocol.new(mock("transport"))
- prot.should_receive(:read_struct_begin).twice
- prot.should_receive(:read_struct_end).twice
- prot.should_receive(:read_field_begin).and_return(
+ prot = Thrift::BaseProtocol.new(double("transport"))
+ expect(prot).to receive(:read_struct_begin).twice
+ expect(prot).to receive(:read_struct_end).twice
+ expect(prot).to receive(:read_field_begin).and_return(
['complex', Thrift::Types::MAP, 5], # Foo
['words', Thrift::Types::STRING, 2], # Foo
['hello', Thrift::Types::STRUCT, 3], # Foo
@@ -112,49 +112,49 @@ describe 'Struct' do
['shorts', Thrift::Types::SET, 6], # Foo
[nil, Thrift::Types::STOP, 0] # Hello
)
- prot.should_receive(:read_field_end).exactly(7).times
- prot.should_receive(:read_map_begin).and_return(
+ expect(prot).to receive(:read_field_end).exactly(7).times
+ expect(prot).to receive(:read_map_begin).and_return(
[Thrift::Types::I32, Thrift::Types::MAP, 2], # complex
[Thrift::Types::STRING, Thrift::Types::DOUBLE, 2], # complex/1/value
[Thrift::Types::STRING, Thrift::Types::DOUBLE, 1] # complex/2/value
)
- prot.should_receive(:read_map_end).exactly(3).times
- prot.should_receive(:read_list_begin).and_return([Thrift::Types::I32, 4])
- prot.should_receive(:read_list_end)
- prot.should_receive(:read_set_begin).and_return([Thrift::Types::I16, 2])
- prot.should_receive(:read_set_end)
- prot.should_receive(:read_i32).and_return(
+ expect(prot).to receive(:read_map_end).exactly(3).times
+ expect(prot).to receive(:read_list_begin).and_return([Thrift::Types::I32, 4])
+ expect(prot).to receive(:read_list_end)
+ expect(prot).to receive(:read_set_begin).and_return([Thrift::Types::I16, 2])
+ expect(prot).to receive(:read_set_end)
+ expect(prot).to receive(:read_i32).and_return(
1, 14, # complex keys
42, # simple
4, 23, 4, 29 # ints
)
- prot.should_receive(:read_string).and_return("pi", "e", "feigenbaum", "apple banana", "what's up?")
- prot.should_receive(:read_double).and_return(Math::PI, Math::E, 4.669201609)
- prot.should_receive(:read_i16).and_return(2, 3)
- prot.should_not_receive(:skip)
+ expect(prot).to receive(:read_string).and_return("pi", "e", "feigenbaum", "apple banana", "what's up?")
+ expect(prot).to receive(:read_double).and_return(Math::PI, Math::E, 4.669201609)
+ expect(prot).to receive(:read_i16).and_return(2, 3)
+ expect(prot).not_to receive(:skip)
struct.read(prot)
- struct.simple.should == 42
- struct.complex.should == {1 => {"pi" => Math::PI, "e" => Math::E}, 14 => {"feigenbaum" => 4.669201609}}
- struct.hello.should == SpecNamespace::Hello.new(:greeting => "what's up?")
- struct.words.should == "apple banana"
- struct.ints.should == [4, 23, 4, 29]
- struct.shorts.should == Set.new([3, 2])
+ expect(struct.simple).to eq(42)
+ expect(struct.complex).to eq({1 => {"pi" => Math::PI, "e" => Math::E}, 14 => {"feigenbaum" => 4.669201609}})
+ expect(struct.hello).to eq(SpecNamespace::Hello.new(:greeting => "what's up?"))
+ expect(struct.words).to eq("apple banana")
+ expect(struct.ints).to eq([4, 23, 4, 29])
+ expect(struct.shorts).to eq(Set.new([3, 2]))
end
it "should serialize false boolean fields correctly" do
b = SpecNamespace::BoolStruct.new(:yesno => false)
prot = Thrift::BinaryProtocol.new(Thrift::MemoryBufferTransport.new)
- prot.should_receive(:write_bool).with(false)
+ expect(prot).to receive(:write_bool).with(false)
b.write(prot)
end
it "should skip unexpected fields in structs and use default values" do
struct = SpecNamespace::Foo.new
- prot = Thrift::BaseProtocol.new(mock("transport"))
- prot.should_receive(:read_struct_begin)
- prot.should_receive(:read_struct_end)
- prot.should_receive(:read_field_begin).and_return(
+ prot = Thrift::BaseProtocol.new(double("transport"))
+ expect(prot).to receive(:read_struct_begin)
+ expect(prot).to receive(:read_struct_end)
+ expect(prot).to receive(:read_field_begin).and_return(
['simple', Thrift::Types::I32, 1],
['complex', Thrift::Types::STRUCT, 5],
['thinz', Thrift::Types::MAP, 7],
@@ -162,55 +162,55 @@ describe 'Struct' do
['words', Thrift::Types::STRING, 2],
[nil, Thrift::Types::STOP, 0]
)
- prot.should_receive(:read_field_end).exactly(5).times
- prot.should_receive(:read_i32).and_return(42)
- prot.should_receive(:read_string).and_return("foobar")
- prot.should_receive(:skip).with(Thrift::Types::STRUCT)
- prot.should_receive(:skip).with(Thrift::Types::MAP)
+ expect(prot).to receive(:read_field_end).exactly(5).times
+ expect(prot).to receive(:read_i32).and_return(42)
+ expect(prot).to receive(:read_string).and_return("foobar")
+ expect(prot).to receive(:skip).with(Thrift::Types::STRUCT)
+ expect(prot).to receive(:skip).with(Thrift::Types::MAP)
# prot.should_receive(:read_map_begin).and_return([Thrift::Types::I32, Thrift::Types::I32, 0])
# prot.should_receive(:read_map_end)
- prot.should_receive(:skip).with(Thrift::Types::I32)
+ expect(prot).to receive(:skip).with(Thrift::Types::I32)
struct.read(prot)
- struct.simple.should == 42
- struct.complex.should be_nil
- struct.words.should == "foobar"
- struct.hello.should == SpecNamespace::Hello.new(:greeting => 'hello, world!')
- struct.ints.should == [1, 2, 2, 3]
- struct.shorts.should == Set.new([5, 17, 239])
+ expect(struct.simple).to eq(42)
+ expect(struct.complex).to be_nil
+ expect(struct.words).to eq("foobar")
+ expect(struct.hello).to eq(SpecNamespace::Hello.new(:greeting => 'hello, world!'))
+ expect(struct.ints).to eq([1, 2, 2, 3])
+ expect(struct.shorts).to eq(Set.new([5, 17, 239]))
end
it "should write itself to the wire" do
- prot = Thrift::BaseProtocol.new(mock("transport")) #mock("Protocol")
- prot.should_receive(:write_struct_begin).with("SpecNamespace::Foo")
- prot.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
- prot.should_receive(:write_struct_end).twice
- prot.should_receive(:write_field_begin).with('ints', Thrift::Types::LIST, 4)
- prot.should_receive(:write_i32).with(1)
- prot.should_receive(:write_i32).with(2).twice
- prot.should_receive(:write_i32).with(3)
- prot.should_receive(:write_field_begin).with('complex', Thrift::Types::MAP, 5)
- prot.should_receive(:write_i32).with(5)
- prot.should_receive(:write_string).with('foo')
- prot.should_receive(:write_double).with(1.23)
- prot.should_receive(:write_field_begin).with('shorts', Thrift::Types::SET, 6)
- prot.should_receive(:write_i16).with(5)
- prot.should_receive(:write_i16).with(17)
- prot.should_receive(:write_i16).with(239)
- prot.should_receive(:write_field_stop).twice
- prot.should_receive(:write_field_end).exactly(6).times
- prot.should_receive(:write_field_begin).with('simple', Thrift::Types::I32, 1)
- prot.should_receive(:write_i32).with(53)
- prot.should_receive(:write_field_begin).with('hello', Thrift::Types::STRUCT, 3)
- prot.should_receive(:write_field_begin).with('greeting', Thrift::Types::STRING, 1)
- prot.should_receive(:write_string).with('hello, world!')
- prot.should_receive(:write_map_begin).with(Thrift::Types::I32, Thrift::Types::MAP, 1)
- prot.should_receive(:write_map_begin).with(Thrift::Types::STRING, Thrift::Types::DOUBLE, 1)
- prot.should_receive(:write_map_end).twice
- prot.should_receive(:write_list_begin).with(Thrift::Types::I32, 4)
- prot.should_receive(:write_list_end)
- prot.should_receive(:write_set_begin).with(Thrift::Types::I16, 3)
- prot.should_receive(:write_set_end)
+ prot = Thrift::BaseProtocol.new(double("transport")) #mock("Protocol")
+ expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Foo")
+ expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Hello")
+ expect(prot).to receive(:write_struct_end).twice
+ expect(prot).to receive(:write_field_begin).with('ints', Thrift::Types::LIST, 4)
+ expect(prot).to receive(:write_i32).with(1)
+ expect(prot).to receive(:write_i32).with(2).twice
+ expect(prot).to receive(:write_i32).with(3)
+ expect(prot).to receive(:write_field_begin).with('complex', Thrift::Types::MAP, 5)
+ expect(prot).to receive(:write_i32).with(5)
+ expect(prot).to receive(:write_string).with('foo')
+ expect(prot).to receive(:write_double).with(1.23)
+ expect(prot).to receive(:write_field_begin).with('shorts', Thrift::Types::SET, 6)
+ expect(prot).to receive(:write_i16).with(5)
+ expect(prot).to receive(:write_i16).with(17)
+ expect(prot).to receive(:write_i16).with(239)
+ expect(prot).to receive(:write_field_stop).twice
+ expect(prot).to receive(:write_field_end).exactly(6).times
+ expect(prot).to receive(:write_field_begin).with('simple', Thrift::Types::I32, 1)
+ expect(prot).to receive(:write_i32).with(53)
+ expect(prot).to receive(:write_field_begin).with('hello', Thrift::Types::STRUCT, 3)
+ expect(prot).to receive(:write_field_begin).with('greeting', Thrift::Types::STRING, 1)
+ expect(prot).to receive(:write_string).with('hello, world!')
+ expect(prot).to receive(:write_map_begin).with(Thrift::Types::I32, Thrift::Types::MAP, 1)
+ expect(prot).to receive(:write_map_begin).with(Thrift::Types::STRING, Thrift::Types::DOUBLE, 1)
+ expect(prot).to receive(:write_map_end).twice
+ expect(prot).to receive(:write_list_begin).with(Thrift::Types::I32, 4)
+ expect(prot).to receive(:write_list_end)
+ expect(prot).to receive(:write_set_begin).with(Thrift::Types::I16, 3)
+ expect(prot).to receive(:write_set_end)
struct = SpecNamespace::Foo.new
struct.words = nil
@@ -221,50 +221,50 @@ describe 'Struct' do
it "should raise an exception if presented with an unknown container" do
# yeah this is silly, but I'm going for code coverage here
struct = SpecNamespace::Foo.new
- lambda { struct.send :write_container, nil, nil, {:type => "foo"} }.should raise_error(StandardError, "Not a container type: foo")
+ expect { struct.send :write_container, nil, nil, {:type => "foo"} }.to raise_error(StandardError, "Not a container type: foo")
end
it "should support optional type-checking in Thrift::Struct.new" do
Thrift.type_checking = true
begin
- lambda { SpecNamespace::Hello.new(:greeting => 3) }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
+ expect { SpecNamespace::Hello.new(:greeting => 3) }.to raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
ensure
Thrift.type_checking = false
end
- lambda { SpecNamespace::Hello.new(:greeting => 3) }.should_not raise_error(Thrift::TypeError)
+ expect { SpecNamespace::Hello.new(:greeting => 3) }.not_to raise_error
end
it "should support optional type-checking in field accessors" do
Thrift.type_checking = true
begin
hello = SpecNamespace::Hello.new
- lambda { hello.greeting = 3 }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
+ expect { hello.greeting = 3 }.to raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
ensure
Thrift.type_checking = false
end
- lambda { hello.greeting = 3 }.should_not raise_error(Thrift::TypeError)
+ expect { hello.greeting = 3 }.not_to raise_error
end
it "should raise an exception when unknown types are given to Thrift::Struct.new" do
- lambda { SpecNamespace::Hello.new(:fish => 'salmon') }.should raise_error(Exception, "Unknown key given to SpecNamespace::Hello.new: fish")
+ expect { SpecNamespace::Hello.new(:fish => 'salmon') }.to raise_error(Exception, "Unknown key given to SpecNamespace::Hello.new: fish")
end
it "should support `raise Xception, 'message'` for Exception structs" do
begin
raise SpecNamespace::Xception, "something happened"
rescue Thrift::Exception => e
- e.message.should == "something happened"
- e.code.should == 1
+ expect(e.message).to eq("something happened")
+ expect(e.code).to eq(1)
# ensure it gets serialized properly, this is the really important part
- prot = Thrift::BaseProtocol.new(mock("trans"))
- prot.should_receive(:write_struct_begin).with("SpecNamespace::Xception")
- prot.should_receive(:write_struct_end)
- prot.should_receive(:write_field_begin).with('message', Thrift::Types::STRING, 1)#, "something happened")
- prot.should_receive(:write_string).with("something happened")
- prot.should_receive(:write_field_begin).with('code', Thrift::Types::I32, 2)#, 1)
- prot.should_receive(:write_i32).with(1)
- prot.should_receive(:write_field_stop)
- prot.should_receive(:write_field_end).twice
+ prot = Thrift::BaseProtocol.new(double("trans"))
+ expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Xception")
+ expect(prot).to receive(:write_struct_end)
+ expect(prot).to receive(:write_field_begin).with('message', Thrift::Types::STRING, 1)#, "something happened")
+ expect(prot).to receive(:write_string).with("something happened")
+ expect(prot).to receive(:write_field_begin).with('code', Thrift::Types::I32, 2)#, 1)
+ expect(prot).to receive(:write_i32).with(1)
+ expect(prot).to receive(:write_field_stop)
+ expect(prot).to receive(:write_field_end).twice
e.write(prot)
end
@@ -274,17 +274,17 @@ describe 'Struct' do
begin
raise SpecNamespace::Xception, :message => "something happened", :code => 5
rescue Thrift::Exception => e
- e.message.should == "something happened"
- e.code.should == 5
- prot = Thrift::BaseProtocol.new(mock("trans"))
- prot.should_receive(:write_struct_begin).with("SpecNamespace::Xception")
- prot.should_receive(:write_struct_end)
- prot.should_receive(:write_field_begin).with('message', Thrift::Types::STRING, 1)
- prot.should_receive(:write_string).with("something happened")
- prot.should_receive(:write_field_begin).with('code', Thrift::Types::I32, 2)
- prot.should_receive(:write_i32).with(5)
- prot.should_receive(:write_field_stop)
- prot.should_receive(:write_field_end).twice
+ expect(e.message).to eq("something happened")
+ expect(e.code).to eq(5)
+ prot = Thrift::BaseProtocol.new(double("trans"))
+ expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Xception")
+ expect(prot).to receive(:write_struct_end)
+ expect(prot).to receive(:write_field_begin).with('message', Thrift::Types::STRING, 1)
+ expect(prot).to receive(:write_string).with("something happened")
+ expect(prot).to receive(:write_field_begin).with('code', Thrift::Types::I32, 2)
+ expect(prot).to receive(:write_i32).with(5)
+ expect(prot).to receive(:write_field_stop)
+ expect(prot).to receive(:write_field_end).twice
e.write(prot)
end
diff --git a/lib/rb/spec/thin_http_server_spec.rb b/lib/rb/spec/thin_http_server_spec.rb
index 552083921..665391b7d 100644
--- a/lib/rb/spec/thin_http_server_spec.rb
+++ b/lib/rb/spec/thin_http_server_spec.rb
@@ -23,24 +23,24 @@ require 'thrift/server/thin_http_server'
describe Thrift::ThinHTTPServer do
- let(:processor) { mock('processor') }
+ let(:processor) { double('processor') }
describe "#initialize" do
context "when using the defaults" do
it "binds to port 80, with host 0.0.0.0, a path of '/'" do
- Thin::Server.should_receive(:new).with('0.0.0.0', 80, an_instance_of(Rack::Builder))
+ expect(Thin::Server).to receive(:new).with('0.0.0.0', 80, an_instance_of(Rack::Builder))
Thrift::ThinHTTPServer.new(processor)
end
it 'creates a ThinHTTPServer::RackApplicationContext' do
- Thrift::ThinHTTPServer::RackApplication.should_receive(:for).with("/", processor, an_instance_of(Thrift::BinaryProtocolFactory)).and_return(anything)
+ expect(Thrift::ThinHTTPServer::RackApplication).to receive(:for).with("/", processor, an_instance_of(Thrift::BinaryProtocolFactory)).and_return(anything)
Thrift::ThinHTTPServer.new(processor)
end
it "uses the BinaryProtocolFactory" do
- Thrift::BinaryProtocolFactory.should_receive(:new)
+ expect(Thrift::BinaryProtocolFactory).to receive(:new)
Thrift::ThinHTTPServer.new(processor)
end
@@ -52,7 +52,7 @@ describe Thrift::ThinHTTPServer do
ip = "192.168.0.1"
port = 3000
path = "/thin"
- Thin::Server.should_receive(:new).with(ip, port, an_instance_of(Rack::Builder))
+ expect(Thin::Server).to receive(:new).with(ip, port, an_instance_of(Rack::Builder))
Thrift::ThinHTTPServer.new(processor,
:ip => ip,
:port => port,
@@ -60,7 +60,7 @@ describe Thrift::ThinHTTPServer do
end
it 'creates a ThinHTTPServer::RackApplicationContext with a different protocol factory' do
- Thrift::ThinHTTPServer::RackApplication.should_receive(:for).with("/", processor, an_instance_of(Thrift::JsonProtocolFactory)).and_return(anything)
+ expect(Thrift::ThinHTTPServer::RackApplication).to receive(:for).with("/", processor, an_instance_of(Thrift::JsonProtocolFactory)).and_return(anything)
Thrift::ThinHTTPServer.new(processor,
:protocol_factory => Thrift::JsonProtocolFactory.new)
end
@@ -72,12 +72,12 @@ describe Thrift::ThinHTTPServer do
describe "#serve" do
it 'starts the Thin server' do
- underlying_thin_server = mock('thin server', :start => true)
- Thin::Server.stub(:new).and_return(underlying_thin_server)
+ underlying_thin_server = double('thin server', :start => true)
+ allow(Thin::Server).to receive(:new).and_return(underlying_thin_server)
thin_thrift_server = Thrift::ThinHTTPServer.new(processor)
- underlying_thin_server.should_receive(:start)
+ expect(underlying_thin_server).to receive(:start)
thin_thrift_server.serve
end
end
@@ -87,8 +87,8 @@ end
describe Thrift::ThinHTTPServer::RackApplication do
include Rack::Test::Methods
- let(:processor) { mock('processor') }
- let(:protocol_factory) { mock('protocol factory') }
+ let(:processor) { double('processor') }
+ let(:protocol_factory) { double('protocol factory') }
def app
Thrift::ThinHTTPServer::RackApplication.for("/", processor, protocol_factory)
@@ -99,13 +99,13 @@ describe Thrift::ThinHTTPServer::RackApplication do
it 'receives a non-POST' do
header('Content-Type', "application/x-thrift")
get "/"
- last_response.status.should be 404
+ expect(last_response.status).to be 404
end
it 'receives a header other than application/x-thrift' do
header('Content-Type', "application/json")
post "/"
- last_response.status.should be 404
+ expect(last_response.status).to be 404
end
end
@@ -113,26 +113,26 @@ describe Thrift::ThinHTTPServer::RackApplication do
context "200 response" do
before do
- protocol_factory.stub(:get_protocol)
- processor.stub(:process)
+ allow(protocol_factory).to receive(:get_protocol)
+ allow(processor).to receive(:process)
end
it 'creates an IOStreamTransport' do
header('Content-Type', "application/x-thrift")
- Thrift::IOStreamTransport.should_receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
+ expect(Thrift::IOStreamTransport).to receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
post "/"
end
it 'fetches the right protocol based on the Transport' do
header('Content-Type', "application/x-thrift")
- protocol_factory.should_receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
+ expect(protocol_factory).to receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
post "/"
end
it 'status code 200' do
header('Content-Type', "application/x-thrift")
post "/"
- last_response.ok?.should be_true
+ expect(last_response.ok?).to be_truthy
end
end
diff --git a/lib/rb/spec/types_spec.rb b/lib/rb/spec/types_spec.rb
index b2c3a200d..364c2a7ec 100644
--- a/lib/rb/spec/types_spec.rb
+++ b/lib/rb/spec/types_spec.rb
@@ -31,85 +31,88 @@ describe Thrift::Types do
context 'type checking' do
it "should return the proper name for each type" do
- Thrift.type_name(Thrift::Types::I16).should == "Types::I16"
- Thrift.type_name(Thrift::Types::VOID).should == "Types::VOID"
- Thrift.type_name(Thrift::Types::LIST).should == "Types::LIST"
- Thrift.type_name(42).should be_nil
+ expect(Thrift.type_name(Thrift::Types::I16)).to eq("Types::I16")
+ expect(Thrift.type_name(Thrift::Types::VOID)).to eq("Types::VOID")
+ expect(Thrift.type_name(Thrift::Types::LIST)).to eq("Types::LIST")
+ expect(Thrift.type_name(42)).to be_nil
end
it "should check types properly" do
# lambda { Thrift.check_type(nil, Thrift::Types::STOP) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.not_to raise_error
+ expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError)
hello = SpecNamespace::Hello.new
- lambda { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type({:foo => 1}, {:type => Thrift::Types::MAP}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type([1], {:type => Thrift::Types::MAP}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type([1], {:type => Thrift::Types::LIST}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type({:foo => 1}, {:type => Thrift::Types::LIST}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(Set.new([1,2]), {:type => Thrift::Types::SET}, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type([1,2], {:type => Thrift::Types::SET}, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type({:foo => true}, {:type => Thrift::Types::SET}, :foo) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.not_to raise_error
+ expect { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.to raise_error(Thrift::TypeError)
+ field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
+ expect { Thrift.check_type({1 => "one"}, field, :foo) }.not_to raise_error
+ expect { Thrift.check_type([1], field, :foo) }.to raise_error(Thrift::TypeError)
+ field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
+ expect { Thrift.check_type([1], field, :foo) }.not_to raise_error
+ expect { Thrift.check_type({:foo => 1}, field, :foo) }.to raise_error(Thrift::TypeError)
+ field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
+ expect { Thrift.check_type(Set.new([1,2]), field, :foo) }.not_to raise_error
+ expect { Thrift.check_type([1,2], field, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type({:foo => true}, field, :foo) }.to raise_error(Thrift::TypeError)
end
it "should error out if nil is passed and skip_types is false" do
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.to raise_error(Thrift::TypeError)
end
it "should check element types on containers" do
field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
- lambda { Thrift.check_type([1, 2], field, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type([1, nil, 2], field, :foo) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type([1, 2], field, :foo) }.not_to raise_error
+ expect { Thrift.check_type([1, nil, 2], field, :foo) }.to raise_error(Thrift::TypeError)
field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
- lambda { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.not_to raise_error
+ expect { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.to raise_error(Thrift::TypeError)
field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
- lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(Thrift::TypeError)
- lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(Set.new([1, 2]), field, :foo) }.not_to raise_error
+ expect { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
field = {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}
- lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(Thrift::TypeError)
+ expect { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.to raise_error(Thrift::TypeError)
end
it "should give the Thrift::TypeError a readable message" do
msg = "Expected Types::STRING, received Fixnum for field foo"
- lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError, msg)
+ expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError, msg)
msg = "Expected Types::STRING, received Fixnum for field foo.element"
field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
- lambda { Thrift.check_type([3], field, :foo) }.should raise_error(Thrift::TypeError, msg)
+ expect { Thrift.check_type([3], field, :foo) }.to raise_error(Thrift::TypeError, msg)
msg = "Expected Types::I32, received NilClass for field foo.element.key"
field = {:type => Thrift::Types::LIST,
:element => {:type => Thrift::Types::MAP,
:key => {:type => Thrift::Types::I32},
:value => {:type => Thrift::Types::I32}}}
- lambda { Thrift.check_type([{nil => 3}], field, :foo) }.should raise_error(Thrift::TypeError, msg)
+ expect { Thrift.check_type([{nil => 3}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
msg = "Expected Types::I32, received NilClass for field foo.element.value"
- lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should raise_error(Thrift::TypeError, msg)
+ expect { Thrift.check_type([{1 => nil}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
end
end
end
diff --git a/lib/rb/spec/union_spec.rb b/lib/rb/spec/union_spec.rb
index 6ad31940c..0ce630629 100644
--- a/lib/rb/spec/union_spec.rb
+++ b/lib/rb/spec/union_spec.rb
@@ -24,85 +24,85 @@ describe 'Union' do
describe Thrift::Union do
it "should return nil value in unset union" do
union = SpecNamespace::My_union.new
- union.get_set_field.should == nil
- union.get_value.should == nil
+ expect(union.get_set_field).to eq(nil)
+ expect(union.get_value).to eq(nil)
end
it "should set a field and be accessible through get_value and the named field accessor" do
union = SpecNamespace::My_union.new
union.integer32 = 25
- union.get_set_field.should == :integer32
- union.get_value.should == 25
- union.integer32.should == 25
+ expect(union.get_set_field).to eq(:integer32)
+ expect(union.get_value).to eq(25)
+ expect(union.integer32).to eq(25)
end
it "should work correctly when instantiated with static field constructors" do
union = SpecNamespace::My_union.integer32(5)
- union.get_set_field.should == :integer32
- union.integer32.should == 5
+ expect(union.get_set_field).to eq(:integer32)
+ expect(union.integer32).to eq(5)
end
it "should raise for wrong set field" do
union = SpecNamespace::My_union.new
union.integer32 = 25
- lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
+ expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
end
it "should raise for wrong set field when hash initialized and type checking is off" do
Thrift.type_checking = false
union = SpecNamespace::My_union.new({incorrect_field: :incorrect})
example = lambda { Thrift::Serializer.new.serialize(union) }
- example.should raise_error(RuntimeError, "set_field is not valid for this union!")
+ expect(example).to raise_error(RuntimeError, "set_field is not valid for this union!")
end
it "should not be equal to nil" do
union = SpecNamespace::My_union.new
- union.should_not == nil
+ expect(union).not_to eq(nil)
end
it "should not be equal with an empty String" do
union = SpecNamespace::My_union.new
- union.should_not == ''
+ expect(union).not_to eq('')
end
it "should not equate two different unions, i32 vs. string" do
union = SpecNamespace::My_union.new(:integer32, 25)
other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
- union.should_not == other_union
+ expect(union).not_to eq(other_union)
end
it "should properly reset setfield and setvalue" do
union = SpecNamespace::My_union.new(:integer32, 25)
- union.get_set_field.should == :integer32
+ expect(union.get_set_field).to eq(:integer32)
union.some_characters = "blah!"
- union.get_set_field.should == :some_characters
- union.get_value.should == "blah!"
- lambda { union.integer32 }.should raise_error(RuntimeError, "integer32 is not union's set field.")
+ expect(union.get_set_field).to eq(:some_characters)
+ expect(union.get_value).to eq("blah!")
+ expect { union.integer32 }.to raise_error(RuntimeError, "integer32 is not union's set field.")
end
it "should not equate two different unions with different values" do
union = SpecNamespace::My_union.new(:integer32, 25)
other_union = SpecNamespace::My_union.new(:integer32, 400)
- union.should_not == other_union
+ expect(union).not_to eq(other_union)
end
it "should not equate two different unions with different fields" do
union = SpecNamespace::My_union.new(:integer32, 25)
other_union = SpecNamespace::My_union.new(:other_i32, 25)
- union.should_not == other_union
+ expect(union).not_to eq(other_union)
end
it "should inspect properly" do
union = SpecNamespace::My_union.new(:integer32, 25)
- union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
+ expect(union.inspect).to eq("<SpecNamespace::My_union integer32: 25>")
end
it "should not allow setting with instance_variable_set" do
union = SpecNamespace::My_union.new(:integer32, 27)
union.instance_variable_set(:@some_characters, "hallo!")
- union.get_set_field.should == :integer32
- union.get_value.should == 27
- lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
+ expect(union.get_set_field).to eq(:integer32)
+ expect(union.get_value).to eq(27)
+ expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
end
it "should serialize to binary correctly" do
@@ -114,7 +114,7 @@ describe 'Union' do
other_union = SpecNamespace::My_union.new(:integer32, 25)
other_union.read(proto)
- other_union.should == union
+ expect(other_union).to eq(union)
end
it "should serialize to json correctly" do
@@ -126,24 +126,24 @@ describe 'Union' do
other_union = SpecNamespace::My_union.new(:integer32, 25)
other_union.read(proto)
- other_union.should == union
+ expect(other_union).to eq(union)
end
it "should raise when validating unset union" do
union = SpecNamespace::My_union.new
- lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")
+ expect { union.validate }.to raise_error(StandardError, "Union fields are not set.")
other_union = SpecNamespace::My_union.new(:integer32, 1)
- lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
+ expect { other_union.validate }.not_to raise_error
end
it "should validate an enum field properly" do
union = SpecNamespace::TestUnion.new(:enum_field, 3)
- union.get_set_field.should == :enum_field
- lambda { union.validate }.should raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
+ expect(union.get_set_field).to eq(:enum_field)
+ expect { union.validate }.to raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
- lambda { other_union.validate }.should_not raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
+ expect { other_union.validate }.not_to raise_error
end
it "should properly serialize and match structs with a union" do
@@ -158,37 +158,37 @@ describe 'Union' do
other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
- swu2.should_not == swu
+ expect(swu2).not_to eq(swu)
swu2.read(proto)
- swu2.should == swu
+ expect(swu2).to eq(swu)
end
it "should support old style constructor" do
union = SpecNamespace::My_union.new(:integer32 => 26)
- union.get_set_field.should == :integer32
- union.get_value.should == 26
+ expect(union.get_set_field).to eq(:integer32)
+ expect(union.get_value).to eq(26)
end
it "should not throw an error when inspected and unset" do
- lambda{SpecNamespace::TestUnion.new().inspect}.should_not raise_error
+ expect{SpecNamespace::TestUnion.new().inspect}.not_to raise_error
end
it "should print enum value name when inspected" do
- SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
+ expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect).to eq("<SpecNamespace::My_union some_enum: ONE (0)>")
- SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
+ 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)]}>")
end
it "should offer field? methods" do
- SpecNamespace::My_union.new.some_enum?.should be_false
- SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?.should be_true
- SpecNamespace::My_union.new(:im_true => false).im_true?.should be_true
- SpecNamespace::My_union.new(:im_true => true).im_true?.should be_true
+ expect(SpecNamespace::My_union.new.some_enum?).to be_falsey
+ expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?).to be_truthy
+ expect(SpecNamespace::My_union.new(:im_true => false).im_true?).to be_truthy
+ expect(SpecNamespace::My_union.new(:im_true => true).im_true?).to be_truthy
end
it "should pretty print binary fields" do
- SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
+ expect(SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect).to eq("<SpecNamespace::TestUnion binary_field: 010203>")
end
it "should be comparable" do
@@ -207,7 +207,7 @@ describe 'Union' do
for y in 0..3
for x in 0..3
# puts "#{objs[y].inspect} <=> #{objs[x].inspect} should == #{relationships[y][x]}"
- (objs[y] <=> objs[x]).should == relationships[y][x]
+ expect(objs[y] <=> objs[x]).to eq(relationships[y][x])
end
end
end
diff --git a/lib/rb/spec/unix_socket_spec.rb b/lib/rb/spec/unix_socket_spec.rb
index 0bea82947..8623e95a0 100644
--- a/lib/rb/spec/unix_socket_spec.rb
+++ b/lib/rb/spec/unix_socket_spec.rb
@@ -26,26 +26,26 @@ describe 'UNIXSocket' do
before(:each) do
@path = '/tmp/thrift_spec_socket'
@socket = Thrift::UNIXSocket.new(@path)
- @handle = mock("Handle", :closed? => false)
- @handle.stub!(:close)
- ::UNIXSocket.stub!(:new).and_return(@handle)
+ @handle = double("Handle", :closed? => false)
+ allow(@handle).to receive(:close)
+ allow(::UNIXSocket).to receive(:new).and_return(@handle)
end
it_should_behave_like "a socket"
it "should raise a TransportException when it cannot open a socket" do
- ::UNIXSocket.should_receive(:new).and_raise(StandardError)
- lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
+ expect(::UNIXSocket).to receive(:new).and_raise(StandardError)
+ expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
end
it "should accept an optional timeout" do
- ::UNIXSocket.stub!(:new)
- Thrift::UNIXSocket.new(@path, 5).timeout.should == 5
+ allow(::UNIXSocket).to receive(:new)
+ expect(Thrift::UNIXSocket.new(@path, 5).timeout).to eq(5)
end
it "should provide a reasonable to_s" do
- ::UNIXSocket.stub!(:new)
- Thrift::UNIXSocket.new(@path).to_s.should == "domain(#{@path})"
+ allow(::UNIXSocket).to receive(:new)
+ expect(Thrift::UNIXSocket.new(@path).to_s).to eq("domain(#{@path})")
end
end
@@ -56,61 +56,61 @@ describe 'UNIXSocket' do
end
it "should create a handle when calling listen" do
- UNIXServer.should_receive(:new).with(@path)
+ expect(UNIXServer).to receive(:new).with(@path)
@socket.listen
end
it "should create a Thrift::UNIXSocket to wrap accepted sockets" do
- handle = mock("UNIXServer")
- UNIXServer.should_receive(:new).with(@path).and_return(handle)
+ handle = double("UNIXServer")
+ expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
@socket.listen
- sock = mock("sock")
- handle.should_receive(:accept).and_return(sock)
- trans = mock("UNIXSocket")
- Thrift::UNIXSocket.should_receive(:new).and_return(trans)
- trans.should_receive(:handle=).with(sock)
- @socket.accept.should == trans
+ sock = double("sock")
+ expect(handle).to receive(:accept).and_return(sock)
+ trans = double("UNIXSocket")
+ expect(Thrift::UNIXSocket).to receive(:new).and_return(trans)
+ expect(trans).to receive(:handle=).with(sock)
+ expect(@socket.accept).to eq(trans)
end
it "should close the handle when closed" do
- handle = mock("UNIXServer", :closed? => false)
- UNIXServer.should_receive(:new).with(@path).and_return(handle)
+ handle = double("UNIXServer", :closed? => false)
+ expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
@socket.listen
- handle.should_receive(:close)
- File.stub!(:delete)
+ expect(handle).to receive(:close)
+ allow(File).to receive(:delete)
@socket.close
end
it "should delete the socket when closed" do
- handle = mock("UNIXServer", :closed? => false)
- UNIXServer.should_receive(:new).with(@path).and_return(handle)
+ handle = double("UNIXServer", :closed? => false)
+ expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
@socket.listen
- handle.stub!(:close)
- File.should_receive(:delete).with(@path)
+ allow(handle).to receive(:close)
+ expect(File).to receive(:delete).with(@path)
@socket.close
end
it "should return nil when accepting if there is no handle" do
- @socket.accept.should be_nil
+ expect(@socket.accept).to be_nil
end
it "should return true for closed? when appropriate" do
- handle = mock("UNIXServer", :closed? => false)
- UNIXServer.stub!(:new).and_return(handle)
- File.stub!(:delete)
+ handle = double("UNIXServer", :closed? => false)
+ allow(UNIXServer).to receive(:new).and_return(handle)
+ allow(File).to receive(:delete)
@socket.listen
- @socket.should_not be_closed
- handle.stub!(:close)
+ expect(@socket).not_to be_closed
+ allow(handle).to receive(:close)
@socket.close
- @socket.should be_closed
+ expect(@socket).to be_closed
@socket.listen
- @socket.should_not be_closed
- handle.stub!(:closed?).and_return(true)
- @socket.should be_closed
+ expect(@socket).not_to be_closed
+ allow(handle).to receive(:closed?).and_return(true)
+ expect(@socket).to be_closed
end
it "should provide a reasonable to_s" do
- @socket.to_s.should == "domain(#{@path})"
+ expect(@socket.to_s).to eq("domain(#{@path})")
end
end
end
diff --git a/lib/rb/thrift.gemspec b/lib/rb/thrift.gemspec
index 450de5bec..fcc344f48 100644
--- a/lib/rb/thrift.gemspec
+++ b/lib/rb/thrift.gemspec
@@ -27,11 +27,14 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib ext]
- s.add_development_dependency 'rspec', ['>= 2.10.0', '< 2.14.0']
- s.add_development_dependency "rack", "~> 1.5"
- s.add_development_dependency "rack-test", "< 0.8.0" # until we no longer build on trusty, then "~> 0.8.2"
- s.add_development_dependency "thin", "~> 1.5"
- s.add_development_dependency "bundler", "~> 1"
- s.add_development_dependency 'rake', '~> 10.5'
+ s.add_development_dependency 'bundler', '~> 1.11'
+ s.add_development_dependency 'pry', '~> 0.11.3'
+ s.add_development_dependency 'pry-byebug', '~> 3.6'
+ s.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.2'
+ s.add_development_dependency 'rack', '~> 2.0'
+ s.add_development_dependency 'rack-test', '~> 0.8.3'
+ s.add_development_dependency 'rake', '~> 12.3'
+ s.add_development_dependency 'rspec', '~> 3.5'
+ s.add_development_dependency 'thin', '~> 1.7'
end