summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Farrell <jfarrell@apache.org>2012-09-28 01:59:04 +0000
committerJake Farrell <jfarrell@apache.org>2012-09-28 01:59:04 +0000
commita87810ff4b4fb75ccb83e4720169422a77939527 (patch)
tree1c52b8ba3a0b8200b5dabd2ef14730f09ad6959d
parent6af2ec09b3ce3a9b440b79fb918e0c0378a703d5 (diff)
downloadthrift-a87810ff4b4fb75ccb83e4720169422a77939527.tar.gz
Thrift-1644:Upgrade RSpec to 2.11.x and refactor specs as needed
Client: rb Patch: Nathan Beyer Upgrading to rspec2. git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1391280 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--lib/rb/Rakefile12
-rw-r--r--lib/rb/spec/base_protocol_spec.rb89
-rw-r--r--lib/rb/spec/base_transport_spec.rb99
-rw-r--r--lib/rb/spec/binary_protocol_accelerated_spec.rb22
-rw-r--r--lib/rb/spec/binary_protocol_spec.rb25
-rw-r--r--lib/rb/spec/binary_protocol_spec_shared.rb2
-rw-r--r--lib/rb/spec/client_spec.rb23
-rw-r--r--lib/rb/spec/compact_protocol_spec.rb2
-rw-r--r--lib/rb/spec/exception_spec.rb79
-rw-r--r--lib/rb/spec/http_client_spec.rb9
-rw-r--r--lib/rb/spec/json_protocol_spec.rb723
-rw-r--r--lib/rb/spec/mongrel_http_server_spec.rb33
-rw-r--r--lib/rb/spec/nonblocking_server_spec.rb38
-rw-r--r--lib/rb/spec/processor_spec.rb25
-rw-r--r--lib/rb/spec/serializer_spec.rb36
-rw-r--r--lib/rb/spec/server_socket_spec.rb13
-rw-r--r--lib/rb/spec/server_spec.rb66
-rw-r--r--lib/rb/spec/socket_spec.rb13
-rw-r--r--lib/rb/spec/socket_spec_shared.rb2
-rw-r--r--lib/rb/spec/spec_helper.rb10
-rw-r--r--lib/rb/spec/struct_nested_containers_spec.rb32
-rw-r--r--lib/rb/spec/struct_spec.rb170
-rw-r--r--lib/rb/spec/types_spec.rb131
-rw-r--r--lib/rb/spec/union_spec.rb90
-rw-r--r--lib/rb/spec/unix_socket_spec.rb17
-rw-r--r--lib/rb/thrift.gemspec6
26 files changed, 865 insertions, 902 deletions
diff --git a/lib/rb/Rakefile b/lib/rb/Rakefile
index 259073848..132c6358f 100644
--- a/lib/rb/Rakefile
+++ b/lib/rb/Rakefile
@@ -20,21 +20,19 @@
require 'rubygems'
require 'rake'
require 'rake/clean'
-require 'spec/rake/spectask'
+require 'rspec/core/rake_task'
THRIFT = '../../compiler/cpp/thrift'
task :default => [:gem]
task :spec => [:'gen-rb', :build_ext, :realspec]
-Spec::Rake::SpecTask.new(:realspec) do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.spec_opts = ['--color']
+RSpec::Core::RakeTask.new(:realspec) do |t|
+ t.rspec_opts = ['--color', '--format d']
end
-Spec::Rake::SpecTask.new(:'spec:rcov') do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.spec_opts = ['--color']
+RSpec::Core::RakeTask.new(:'spec:rcov') do |t|
+ t.rspec_opts = ['--color', '--format d']
t.rcov = true
t.rcov_opts = ['--exclude', '^spec,/gems/']
end
diff --git a/lib/rb/spec/base_protocol_spec.rb b/lib/rb/spec/base_protocol_spec.rb
index bd9b59b9b..c0f9cfcb0 100644
--- a/lib/rb/spec/base_protocol_spec.rb
+++ b/lib/rb/spec/base_protocol_spec.rb
@@ -17,17 +17,16 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftBaseProtocolSpec < Spec::ExampleGroup
- include Thrift
+describe 'BaseProtocol' do
before(:each) do
@trans = mock("MockTransport")
- @prot = BaseProtocol.new(@trans)
+ @prot = Thrift::BaseProtocol.new(@trans)
end
- describe BaseProtocol do
+ describe Thrift::BaseProtocol do
# most of the methods are stubs, so we can ignore them
it "should make trans accessible" do
@@ -51,16 +50,16 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
@prot.should_receive(:write_string).with('string').ordered
struct = mock('Struct')
struct.should_receive(:write).with(@prot).ordered
- @prot.write_type(Types::BOOL, 'bool')
- @prot.write_type(Types::BYTE, 'byte')
- @prot.write_type(Types::DOUBLE, 'double')
- @prot.write_type(Types::I16, 'i16')
- @prot.write_type(Types::I32, 'i32')
- @prot.write_type(Types::I64, 'i64')
- @prot.write_type(Types::STRING, 'string')
- @prot.write_type(Types::STRUCT, struct)
+ @prot.write_type(Thrift::Types::BOOL, 'bool')
+ @prot.write_type(Thrift::Types::BYTE, 'byte')
+ @prot.write_type(Thrift::Types::DOUBLE, 'double')
+ @prot.write_type(Thrift::Types::I16, 'i16')
+ @prot.write_type(Thrift::Types::I32, 'i32')
+ @prot.write_type(Thrift::Types::I64, 'i64')
+ @prot.write_type(Thrift::Types::STRING, 'string')
+ @prot.write_type(Thrift::Types::STRUCT, struct)
# all other types are not implemented
- [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
lambda { @prot.write_type(type, type.to_s) }.should raise_error(NotImplementedError)
end
end
@@ -73,15 +72,15 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
@prot.should_receive(:read_i64).ordered
@prot.should_receive(:read_double).ordered
@prot.should_receive(:read_string).ordered
- @prot.read_type(Types::BOOL)
- @prot.read_type(Types::BYTE)
- @prot.read_type(Types::I16)
- @prot.read_type(Types::I32)
- @prot.read_type(Types::I64)
- @prot.read_type(Types::DOUBLE)
- @prot.read_type(Types::STRING)
+ @prot.read_type(Thrift::Types::BOOL)
+ @prot.read_type(Thrift::Types::BYTE)
+ @prot.read_type(Thrift::Types::I16)
+ @prot.read_type(Thrift::Types::I32)
+ @prot.read_type(Thrift::Types::I64)
+ @prot.read_type(Thrift::Types::DOUBLE)
+ @prot.read_type(Thrift::Types::STRING)
# all other types are not implemented
- [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
lambda { @prot.read_type(type) }.should raise_error(NotImplementedError)
end
end
@@ -94,67 +93,67 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
@prot.should_receive(:read_i64).ordered
@prot.should_receive(:read_double).ordered
@prot.should_receive(:read_string).ordered
- @prot.skip(Types::BOOL)
- @prot.skip(Types::BYTE)
- @prot.skip(Types::I16)
- @prot.skip(Types::I32)
- @prot.skip(Types::I64)
- @prot.skip(Types::DOUBLE)
- @prot.skip(Types::STRING)
- @prot.skip(Types::STOP) # should do absolutely nothing
+ @prot.skip(Thrift::Types::BOOL)
+ @prot.skip(Thrift::Types::BYTE)
+ @prot.skip(Thrift::Types::I16)
+ @prot.skip(Thrift::Types::I32)
+ @prot.skip(Thrift::Types::I64)
+ @prot.skip(Thrift::Types::DOUBLE)
+ @prot.skip(Thrift::Types::STRING)
+ @prot.skip(Thrift::Types::STOP) # should do absolutely nothing
end
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(
- ['field 1', Types::STRING, 1],
- ['field 2', Types::I32, 2],
- ['field 3', Types::MAP, 3],
- [nil, Types::STOP, 0]
+ ['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([Types::STRING, Types::STRING, 1])
+ @prot.should_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
- real_skip.call(Types::STRUCT)
+ 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([Types::STRING, Types::STRUCT, 1])
+ @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, Types::STOP, nil]);
+ @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
- real_skip.call(Types::MAP)
+ 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([Types::I64, 9])
+ @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)
- real_skip.call(Types::SET)
+ 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([Types::DOUBLE, 11])
+ @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)
- real_skip.call(Types::LIST)
+ real_skip.call(Thrift::Types::LIST)
end
end
- describe BaseProtocolFactory do
+ describe Thrift::BaseProtocolFactory do
it "should raise NotImplementedError" do
# returning nil since Protocol is just an abstract class
- lambda {BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
+ lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
end
end
end
diff --git a/lib/rb/spec/base_transport_spec.rb b/lib/rb/spec/base_transport_spec.rb
index d91a1181d..4196572da 100644
--- a/lib/rb/spec/base_transport_spec.rb
+++ b/lib/rb/spec/base_transport_spec.rb
@@ -17,22 +17,21 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftBaseTransportSpec < Spec::ExampleGroup
- include Thrift
+describe 'BaseTransport' do
- describe TransportException do
+ describe Thrift::TransportException do
it "should make type accessible" do
- exc = TransportException.new(TransportException::ALREADY_OPEN, "msg")
- exc.type.should == TransportException::ALREADY_OPEN
+ exc = Thrift::TransportException.new(Thrift::TransportException::ALREADY_OPEN, "msg")
+ exc.type.should == Thrift::TransportException::ALREADY_OPEN
exc.message.should == "msg"
end
end
- describe BaseTransport do
+ describe Thrift::BaseTransport do
it "should read the specified size" do
- transport = BaseTransport.new
+ 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")
@@ -42,47 +41,47 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
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|
- BaseTransport.method_defined?(sym).should be_true
+ Thrift::BaseTransport.method_defined?(sym).should be_true
end
end
it "should alias << to write" do
- BaseTransport.instance_method(:<<).should == BaseTransport.instance_method(:write)
+ Thrift::BaseTransport.instance_method(:<<).should == Thrift::BaseTransport.instance_method(:write)
end
end
- describe BaseServerTransport do
+ describe Thrift::BaseServerTransport do
it "should stub out its methods" do
[:listen, :accept, :close].each do |sym|
- BaseServerTransport.method_defined?(sym).should be_true
+ Thrift::BaseServerTransport.method_defined?(sym).should be_true
end
end
end
- describe BaseTransportFactory do
+ describe Thrift::BaseTransportFactory do
it "should return the transport it's given" do
transport = mock("Transport")
- BaseTransportFactory.new.get_transport(transport).should eql(transport)
+ Thrift::BaseTransportFactory.new.get_transport(transport).should eql(transport)
end
end
- describe BufferedTransport do
+ describe Thrift::BufferedTransport do
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")
- btrans = BufferedTransport.new(trans)
+ btrans = Thrift::BufferedTransport.new(trans)
btrans.open?.should == "+ open?"
btrans.open.should == "+ open"
btrans.close.should == "+ close"
end
-
- it "should buffer reads in chunks of #{BufferedTransport::DEFAULT_BUFFER}" do
+
+ it "should buffer reads in chunks of #{Thrift::BufferedTransport::DEFAULT_BUFFER}" do
trans = mock("Transport")
- trans.should_receive(:read).with(BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
- btrans = BufferedTransport.new(trans)
+ trans.should_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 "
@@ -91,7 +90,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
it "should buffer writes and send them on flush" do
trans = mock("Transport")
- btrans = BufferedTransport.new(trans)
+ btrans = Thrift::BufferedTransport.new(trans)
btrans.write("one/")
btrans.write("two/")
btrans.write("three/")
@@ -102,7 +101,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
it "should only send buffered data once" do
trans = mock("Transport")
- btrans = BufferedTransport.new(trans)
+ btrans = Thrift::BufferedTransport.new(trans)
btrans.write("one/")
btrans.write("two/")
btrans.write("three/")
@@ -112,39 +111,39 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
# Nothing to flush with no data
btrans.flush
end
-
+
it "should flush on close" do
trans = mock("Transport")
trans.should_receive(:close)
- btrans = BufferedTransport.new(trans)
+ btrans = Thrift::BufferedTransport.new(trans)
btrans.should_receive(:flush)
btrans.close
end
-
+
it "should not write to socket if there's no data" do
trans = mock("Transport")
trans.should_receive(:flush)
- btrans = BufferedTransport.new(trans)
+ btrans = Thrift::BufferedTransport.new(trans)
btrans.flush
end
end
- describe BufferedTransportFactory do
+ describe Thrift::BufferedTransportFactory do
it "should wrap the given transport in a BufferedTransport" do
trans = mock("Transport")
btrans = mock("BufferedTransport")
- BufferedTransport.should_receive(:new).with(trans).and_return(btrans)
- BufferedTransportFactory.new.get_transport(trans).should == btrans
+ Thrift::BufferedTransport.should_receive(:new).with(trans).and_return(btrans)
+ Thrift::BufferedTransportFactory.new.get_transport(trans).should == btrans
end
end
- describe FramedTransport do
+ describe Thrift::FramedTransport do
before(:each) do
@trans = mock("Transport")
end
it "should pass through open?/open/close" do
- ftrans = FramedTransport.new(@trans)
+ 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")
@@ -154,13 +153,13 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
it "should pass through read when read is turned off" do
- ftrans = FramedTransport.new(@trans, false, true)
+ ftrans = Thrift::FramedTransport.new(@trans, false, true)
@trans.should_receive(:read).with(17).ordered.and_return("+ read")
ftrans.read(17).should == "+ read"
end
it "should pass through write/flush when write is turned off" do
- ftrans = FramedTransport.new(@trans, true, false)
+ 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"
@@ -171,21 +170,21 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
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)
- FramedTransport.new(@trans).read(frame.length + 10).should == frame
+ Thrift::FramedTransport.new(@trans).read(frame.length + 10).should == 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)
- ftrans = FramedTransport.new(@trans)
+ ftrans = Thrift::FramedTransport.new(@trans)
ftrans.read(4).should == "this"
ftrans.read(4).should == " is "
ftrans.read(16).should == "a frame"
end
it "should return nothing if asked for <= 0" do
- FramedTransport.new(@trans).read(-2).should == ""
+ Thrift::FramedTransport.new(@trans).read(-2).should == ""
end
it "should pull a new frame when the first is exhausted" do
@@ -194,7 +193,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
@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)
- ftrans = FramedTransport.new(@trans)
+ ftrans = Thrift::FramedTransport.new(@trans)
ftrans.read(4).should == "this"
ftrans.read(8).should == " is a fr"
ftrans.read(6).should == "ame"
@@ -203,7 +202,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
it "should buffer writes" do
- ftrans = FramedTransport.new(@trans)
+ ftrans = Thrift::FramedTransport.new(@trans)
@trans.should_not_receive(:write)
ftrans.write("foo")
ftrans.write("bar")
@@ -211,7 +210,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
it "should write slices of the buffer" do
- ftrans = FramedTransport.new(@trans)
+ ftrans = Thrift::FramedTransport.new(@trans)
ftrans.write("foobar", 3)
ftrans.write("barfoo", 1)
@trans.stub!(:flush)
@@ -220,7 +219,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
it "should flush frames with a 4-byte header" do
- ftrans = FramedTransport.new(@trans)
+ 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
ftrans.write("one/")
@@ -231,7 +230,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
it "should not flush the same buffered data twice" do
- ftrans = FramedTransport.new(@trans)
+ ftrans = Thrift::FramedTransport.new(@trans)
@trans.should_receive(:write).with("\000\000\000\007foo/bar")
@trans.stub!(:flush)
ftrans.write("foo")
@@ -242,22 +241,22 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
end
- describe FramedTransportFactory do
+ describe Thrift::FramedTransportFactory do
it "should wrap the given transport in a FramedTransport" do
trans = mock("Transport")
- FramedTransport.should_receive(:new).with(trans)
- FramedTransportFactory.new.get_transport(trans)
+ Thrift::FramedTransport.should_receive(:new).with(trans)
+ Thrift::FramedTransportFactory.new.get_transport(trans)
end
end
- describe MemoryBufferTransport do
+ describe Thrift::MemoryBufferTransport do
before(:each) do
- @buffer = MemoryBufferTransport.new
+ @buffer = Thrift::MemoryBufferTransport.new
end
it "should accept a buffer on input and use it directly" do
s = "this is a test"
- @buffer = MemoryBufferTransport.new(s)
+ @buffer = Thrift::MemoryBufferTransport.new(s)
@buffer.read(4).should == "this"
s.slice!(-4..-1)
@buffer.read(@buffer.available).should == " is a "
@@ -307,7 +306,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
@buffer.write " bar"
@buffer.read(@buffer.available).should == "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)
@@ -317,11 +316,11 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
end
end
- describe IOStreamTransport do
+ describe Thrift::IOStreamTransport do
before(:each) do
@input = mock("Input", :closed? => false)
@output = mock("Output", :closed? => false)
- @trans = IOStreamTransport.new(@input, @output)
+ @trans = Thrift::IOStreamTransport.new(@input, @output)
end
it "should be open as long as both input or output are open" do
diff --git a/lib/rb/spec/binary_protocol_accelerated_spec.rb b/lib/rb/spec/binary_protocol_accelerated_spec.rb
index 0653ba872..bac9ea7c7 100644
--- a/lib/rb/spec/binary_protocol_accelerated_spec.rb
+++ b/lib/rb/spec/binary_protocol_accelerated_spec.rb
@@ -17,27 +17,23 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
require File.expand_path("#{File.dirname(__FILE__)}/binary_protocol_spec_shared")
if defined? Thrift::BinaryProtocolAccelerated
- class ThriftBinaryProtocolAcceleratedSpec < Spec::ExampleGroup
- include Thrift
+ describe 'BinaryProtocolAccelerated' do
+ # since BinaryProtocolAccelerated should be directly equivalent to
+ # BinaryProtocol, we don't need any custom specs!
+ it_should_behave_like 'a binary protocol'
- describe Thrift::BinaryProtocolAccelerated do
- # since BinaryProtocolAccelerated should be directly equivalent to
- # BinaryProtocol, we don't need any custom specs!
- it_should_behave_like 'a binary protocol'
-
- def protocol_class
- BinaryProtocolAccelerated
- end
+ def protocol_class
+ Thrift::BinaryProtocolAccelerated
end
- describe BinaryProtocolAcceleratedFactory do
+ describe Thrift::BinaryProtocolAcceleratedFactory do
it "should create a BinaryProtocolAccelerated" do
- BinaryProtocolAcceleratedFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocolAccelerated)
+ Thrift::BinaryProtocolAcceleratedFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::BinaryProtocolAccelerated)
end
end
end
diff --git a/lib/rb/spec/binary_protocol_spec.rb b/lib/rb/spec/binary_protocol_spec.rb
index 0edd9d9dc..32772d3fc 100644
--- a/lib/rb/spec/binary_protocol_spec.rb
+++ b/lib/rb/spec/binary_protocol_spec.rb
@@ -17,17 +17,22 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
require File.expand_path("#{File.dirname(__FILE__)}/binary_protocol_spec_shared")
-class ThriftBinaryProtocolSpec < Spec::ExampleGroup
- include Thrift
+describe 'BinaryProtocol' do
- describe BinaryProtocol do
- it_should_behave_like 'a binary protocol'
+ it_should_behave_like 'a binary protocol'
- def protocol_class
- BinaryProtocol
+ def protocol_class
+ Thrift::BinaryProtocol
+ end
+
+ describe Thrift::BinaryProtocol do
+
+ before(:each) do
+ @trans = Thrift::MemoryBufferTransport.new
+ @prot = protocol_class.new(@trans)
end
it "should read a message header" do
@@ -47,15 +52,15 @@ class ThriftBinaryProtocolSpec < Spec::ExampleGroup
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|
+ lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'No version identifier, old protocol client?') do |e|
e.type == Thrift::ProtocolException::BAD_VERSION
end
end
end
- describe BinaryProtocolFactory do
+ describe Thrift::BinaryProtocolFactory do
it "should create a BinaryProtocol" do
- BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocol)
+ Thrift::BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::BinaryProtocol)
end
end
end
diff --git a/lib/rb/spec/binary_protocol_spec_shared.rb b/lib/rb/spec/binary_protocol_spec_shared.rb
index 0bc91c914..ce4931f26 100644
--- a/lib/rb/spec/binary_protocol_spec_shared.rb
+++ b/lib/rb/spec/binary_protocol_spec_shared.rb
@@ -17,7 +17,7 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
shared_examples_for 'a binary protocol' do
before(:each) do
diff --git a/lib/rb/spec/client_spec.rb b/lib/rb/spec/client_spec.rb
index 1550e14bd..7079b9486 100644
--- a/lib/rb/spec/client_spec.rb
+++ b/lib/rb/spec/client_spec.rb
@@ -17,10 +17,9 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftClientSpec < Spec::ExampleGroup
- include Thrift
+describe 'Client' do
class ClientSpec
include Thrift::Client
@@ -31,14 +30,14 @@ class ThriftClientSpec < Spec::ExampleGroup
@client = ClientSpec.new(@prot)
end
- describe Client do
+ 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)
end
it "should send a test message" do
- @prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::CALL, 0)
+ @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)
@@ -55,19 +54,19 @@ class ThriftClientSpec < Spec::ExampleGroup
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', MessageTypes::CALL, 0).ordered
- @prot.should_receive(:write_message_begin).with('testMessage2', MessageTypes::CALL, 1).ordered
- @prot.should_receive(:write_message_begin).with('testMessage3', MessageTypes::CALL, 2).ordered
+ @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)
+ @client.send_message('testMessage3', mock("args class").as_null_object)
end
end
it "should receive a test message" do
- @prot.should_receive(:read_message_begin).and_return [nil, MessageTypes::CALL, 0]
+ @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)
@@ -75,9 +74,9 @@ class ThriftClientSpec < Spec::ExampleGroup
end
it "should handle received exceptions" do
- @prot.should_receive(:read_message_begin).and_return [nil, MessageTypes::EXCEPTION, 0]
+ @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
@prot.should_receive(:read_message_end)
- ApplicationException.should_receive(:new).and_return do
+ Thrift::ApplicationException.should_receive(:new).and_return do
StandardError.new.tee do |mock_exc|
mock_exc.should_receive(:read).with(@prot)
end
diff --git a/lib/rb/spec/compact_protocol_spec.rb b/lib/rb/spec/compact_protocol_spec.rb
index 2862afd51..13c6b83d1 100644
--- a/lib/rb/spec/compact_protocol_spec.rb
+++ b/lib/rb/spec/compact_protocol_spec.rb
@@ -17,7 +17,7 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
describe Thrift::CompactProtocol do
TESTS = {
diff --git a/lib/rb/spec/exception_spec.rb b/lib/rb/spec/exception_spec.rb
index 78ddb7552..d1da6217e 100644
--- a/lib/rb/spec/exception_spec.rb
+++ b/lib/rb/spec/exception_spec.rb
@@ -17,29 +17,28 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftExceptionSpec < Spec::ExampleGroup
- include Thrift
+describe 'Exception' do
- describe Exception do
+ describe Thrift::Exception do
it "should have an accessible message" do
- e = Exception.new("test message")
+ e = Thrift::Exception.new("test message")
e.message.should == "test message"
end
end
- describe ApplicationException do
+ describe Thrift::ApplicationException do
it "should inherit from Thrift::Exception" do
- ApplicationException.superclass.should == Exception
+ Thrift::ApplicationException.superclass.should == Thrift::Exception
end
it "should have an accessible type and message" do
- e = ApplicationException.new
- e.type.should == ApplicationException::UNKNOWN
+ e = Thrift::ApplicationException.new
+ e.type.should == Thrift::ApplicationException::UNKNOWN
e.message.should be_nil
- e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
- e.type.should == ApplicationException::UNKNOWN_METHOD
+ e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
+ e.type.should == Thrift::ApplicationException::UNKNOWN_METHOD
e.message.should == "test message"
end
@@ -47,79 +46,79 @@ class ThriftExceptionSpec < Spec::ExampleGroup
prot = mock("MockProtocol")
prot.should_receive(:read_struct_begin).ordered
prot.should_receive(:read_field_begin).exactly(3).times.and_return(
- ["message", Types::STRING, 1],
- ["type", Types::I32, 2],
- [nil, Types::STOP, 0]
+ ["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 ApplicationException::BAD_SEQUENCE_ID
+ 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
- e = ApplicationException.new
+ e = Thrift::ApplicationException.new
e.read(prot)
e.message.should == "test message"
- e.type.should == ApplicationException::BAD_SEQUENCE_ID
+ e.type.should == 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(
- ["type", Types::I32, 2],
- ["type", Types::STRING, 2],
- ["message", Types::MAP, 1],
- ["message", Types::STRING, 3],
- [nil, Types::STOP, 0]
+ ["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 ApplicationException::INVALID_MESSAGE_TYPE
- prot.should_receive(:skip).with(Types::STRING).twice
- prot.should_receive(:skip).with(Types::MAP)
+ 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
- e = ApplicationException.new
+ e = Thrift::ApplicationException.new
e.read(prot)
e.message.should be_nil
- e.type.should == ApplicationException::INVALID_MESSAGE_TYPE
+ e.type.should == 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", Types::STRING, 1).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", Types::I32, 2).ordered
- prot.should_receive(:write_i32).with(ApplicationException::UNKNOWN_METHOD).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
- e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
+ 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", Types::STRING, 1).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
- e = ApplicationException.new(nil, "test message")
+ 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", Types::I32, 2).ordered
- prot.should_receive(:write_i32).with(ApplicationException::BAD_SEQUENCE_ID).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
- e = ApplicationException.new(ApplicationException::BAD_SEQUENCE_ID)
+ e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
e.write(prot)
prot = mock("MockProtocol")
@@ -127,15 +126,15 @@ class ThriftExceptionSpec < Spec::ExampleGroup
prot.should_receive(:write_field_stop).ordered
prot.should_receive(:write_struct_end).ordered
- e = ApplicationException.new(nil)
+ e = Thrift::ApplicationException.new(nil)
e.write(prot)
end
end
- describe ProtocolException do
+ describe Thrift::ProtocolException do
it "should have an accessible type" do
- prot = ProtocolException.new(ProtocolException::SIZE_LIMIT, "message")
- prot.type.should == ProtocolException::SIZE_LIMIT
+ prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
+ prot.type.should == Thrift::ProtocolException::SIZE_LIMIT
prot.message.should == "message"
end
end
diff --git a/lib/rb/spec/http_client_spec.rb b/lib/rb/spec/http_client_spec.rb
index 30561ab58..b5962793a 100644
--- a/lib/rb/spec/http_client_spec.rb
+++ b/lib/rb/spec/http_client_spec.rb
@@ -17,14 +17,13 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftHTTPClientTransportSpec < Spec::ExampleGroup
- include Thrift
+describe 'Thrift::HTTPClientTransport' do
- describe HTTPClientTransport do
+ describe Thrift::HTTPClientTransport do
before(:each) do
- @client = HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
+ @client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
end
it "should always be open" do
diff --git a/lib/rb/spec/json_protocol_spec.rb b/lib/rb/spec/json_protocol_spec.rb
index ce64aa8a8..3945925f8 100644
--- a/lib/rb/spec/json_protocol_spec.rb
+++ b/lib/rb/spec/json_protocol_spec.rb
@@ -17,463 +17,464 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftJsonProtocolSpec < Spec::ExampleGroup
- include Thrift
+describe 'JsonProtocol' do
- before(:each) do
- @trans = Thrift::MemoryBufferTransport.new
- @prot = JsonProtocol.new(@trans)
- end
+ describe Thrift::JsonProtocol do
+ before(:each) do
+ @trans = Thrift::MemoryBufferTransport.new
+ @prot = Thrift::JsonProtocol.new(@trans)
+ end
- it "should write json escaped char" do
- @prot.write_json_escape_char("\n")
- @trans.read(@trans.available).should == '\u000a'
+ it "should write json escaped char" do
+ @prot.write_json_escape_char("\n")
+ @trans.read(@trans.available).should == '\u000a'
- @prot.write_json_escape_char(" ")
- @trans.read(@trans.available).should == '\u0020'
- end
+ @prot.write_json_escape_char(" ")
+ @trans.read(@trans.available).should == '\u0020'
+ end
- it "should write json char" do
- @prot.write_json_char("\n")
- @trans.read(@trans.available).should == '\\n'
+ it "should write json char" do
+ @prot.write_json_char("\n")
+ @trans.read(@trans.available).should == '\\n'
- @prot.write_json_char(" ")
- @trans.read(@trans.available).should == ' '
+ @prot.write_json_char(" ")
+ @trans.read(@trans.available).should == ' '
- @prot.write_json_char("\\")
- @trans.read(@trans.available).should == "\\\\"
+ @prot.write_json_char("\\")
+ @trans.read(@trans.available).should == "\\\\"
- @prot.write_json_char("@")
- @trans.read(@trans.available).should == '@'
- end
+ @prot.write_json_char("@")
+ @trans.read(@trans.available).should == '@'
+ 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\""
- 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\""
+ end
- it "should write json base64" do
- @prot.write_json_base64("this is a base64 string")
- @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
- end
+ it "should write json base64" do
+ @prot.write_json_base64("this is a base64 string")
+ @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
+ end
- it "should write json integer" do
- @prot.write_json_integer(45)
- @trans.read(@trans.available).should == "45"
+ it "should write json integer" do
+ @prot.write_json_integer(45)
+ @trans.read(@trans.available).should == "45"
- @prot.write_json_integer(33000)
- @trans.read(@trans.available).should == "33000"
+ @prot.write_json_integer(33000)
+ @trans.read(@trans.available).should == "33000"
- @prot.write_json_integer(3000000000)
- @trans.read(@trans.available).should == "3000000000"
+ @prot.write_json_integer(3000000000)
+ @trans.read(@trans.available).should == "3000000000"
- @prot.write_json_integer(6000000000)
- @trans.read(@trans.available).should == "6000000000"
- end
+ @prot.write_json_integer(6000000000)
+ @trans.read(@trans.available).should == "6000000000"
+ end
- it "should write json double" do
- @prot.write_json_double(12.3)
- @trans.read(@trans.available).should == "12.3"
+ it "should write json double" do
+ @prot.write_json_double(12.3)
+ @trans.read(@trans.available).should == "12.3"
- @prot.write_json_double(-3.21)
- @trans.read(@trans.available).should == "-3.21"
+ @prot.write_json_double(-3.21)
+ @trans.read(@trans.available).should == "-3.21"
- @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
- @trans.read(@trans.available).should == "\"NaN\""
+ @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
+ @trans.read(@trans.available).should == "\"NaN\""
- @prot.write_json_double((+1.0/0.0))
- @trans.read(@trans.available).should == "\"Infinity\""
+ @prot.write_json_double((+1.0/0.0))
+ @trans.read(@trans.available).should == "\"Infinity\""
- @prot.write_json_double((-1.0/0.0))
- @trans.read(@trans.available).should == "\"-Infinity\""
- end
+ @prot.write_json_double((-1.0/0.0))
+ @trans.read(@trans.available).should == "\"-Infinity\""
+ end
- it "should write json object start" do
- @prot.write_json_object_start
- @trans.read(@trans.available).should == "{"
- end
+ it "should write json object start" do
+ @prot.write_json_object_start
+ @trans.read(@trans.available).should == "{"
+ end
- it "should write json object end" do
- @prot.write_json_object_end
- @trans.read(@trans.available).should == "}"
- end
+ it "should write json object end" do
+ @prot.write_json_object_end
+ @trans.read(@trans.available).should == "}"
+ end
- it "should write json array start" do
- @prot.write_json_array_start
- @trans.read(@trans.available).should == "["
- end
+ it "should write json array start" do
+ @prot.write_json_array_start
+ @trans.read(@trans.available).should == "["
+ end
- it "should write json array end" do
- @prot.write_json_array_end
- @trans.read(@trans.available).should == "]"
- end
+ it "should write json array end" do
+ @prot.write_json_array_end
+ @trans.read(@trans.available).should == "]"
+ end
- it "should write message begin" do
- @prot.write_message_begin("name", 12, 32)
- @trans.read(@trans.available).should == "[1,\"name\",12,32"
- end
+ it "should write message begin" do
+ @prot.write_message_begin("name", 12, 32)
+ @trans.read(@trans.available).should == "[1,\"name\",12,32"
+ end
- it "should write message end" do
- @prot.write_message_end
- @trans.read(@trans.available).should == "]"
- end
+ it "should write message end" do
+ @prot.write_message_end
+ @trans.read(@trans.available).should == "]"
+ end
- it "should write struct begin" do
- @prot.write_struct_begin("name")
- @trans.read(@trans.available).should == "{"
- end
+ it "should write struct begin" do
+ @prot.write_struct_begin("name")
+ @trans.read(@trans.available).should == "{"
+ end
- it "should write struct end" do
- @prot.write_struct_end
- @trans.read(@trans.available).should == "}"
- end
+ it "should write struct end" do
+ @prot.write_struct_end
+ @trans.read(@trans.available).should == "}"
+ end
- it "should write field begin" do
- @prot.write_field_begin("name", Types::STRUCT, 32)
- @trans.read(@trans.available).should == "32{\"rec\""
- end
+ it "should write field begin" do
+ @prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
+ @trans.read(@trans.available).should == "32{\"rec\""
+ end
- it "should write field end" do
- @prot.write_field_end
- @trans.read(@trans.available).should == "}"
- end
+ it "should write field end" do
+ @prot.write_field_end
+ @trans.read(@trans.available).should == "}"
+ end
- it "should write field stop" do
- @prot.write_field_stop
- @trans.read(@trans.available).should == ""
- end
+ it "should write field stop" do
+ @prot.write_field_stop
+ @trans.read(@trans.available).should == ""
+ end
- it "should write map begin" do
- @prot.write_map_begin(Types::STRUCT, Types::LIST, 32)
- @trans.read(@trans.available).should == "[\"rec\",\"lst\",32,{"
- 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,{"
+ end
- it "should write map end" do
- @prot.write_map_end
- @trans.read(@trans.available).should == "}]"
- end
+ it "should write map end" do
+ @prot.write_map_end
+ @trans.read(@trans.available).should == "}]"
+ end
- it "should write list begin" do
- @prot.write_list_begin(Types::STRUCT, 32)
- @trans.read(@trans.available).should == "[\"rec\",32"
- end
+ it "should write list begin" do
+ @prot.write_list_begin(Thrift::Types::STRUCT, 32)
+ @trans.read(@trans.available).should == "[\"rec\",32"
+ end
- it "should write list end" do
- @prot.write_list_end
- @trans.read(@trans.available).should == "]"
- end
+ it "should write list end" do
+ @prot.write_list_end
+ @trans.read(@trans.available).should == "]"
+ end
- it "should write set begin" do
- @prot.write_set_begin(Types::STRUCT, 32)
- @trans.read(@trans.available).should == "[\"rec\",32"
- end
+ it "should write set begin" do
+ @prot.write_set_begin(Thrift::Types::STRUCT, 32)
+ @trans.read(@trans.available).should == "[\"rec\",32"
+ end
- it "should write set end" do
- @prot.write_set_end
- @trans.read(@trans.available).should == "]"
- end
+ it "should write set end" do
+ @prot.write_set_end
+ @trans.read(@trans.available).should == "]"
+ end
- it "should write bool" do
- @prot.write_bool(true)
- @trans.read(@trans.available).should == "1"
+ it "should write bool" do
+ @prot.write_bool(true)
+ @trans.read(@trans.available).should == "1"
- @prot.write_bool(false)
- @trans.read(@trans.available).should == "0"
- end
+ @prot.write_bool(false)
+ @trans.read(@trans.available).should == "0"
+ end
- it "should write byte" do
- @prot.write_byte(100)
- @trans.read(@trans.available).should == "100"
- end
+ it "should write byte" do
+ @prot.write_byte(100)
+ @trans.read(@trans.available).should == "100"
+ end
- it "should write i16" do
- @prot.write_i16(1000)
- @trans.read(@trans.available).should == "1000"
- end
+ it "should write i16" do
+ @prot.write_i16(1000)
+ @trans.read(@trans.available).should == "1000"
+ end
- it "should write i32" do
- @prot.write_i32(3000000000)
- @trans.read(@trans.available).should == "3000000000"
- end
+ it "should write i32" do
+ @prot.write_i32(3000000000)
+ @trans.read(@trans.available).should == "3000000000"
+ end
- it "should write i64" do
- @prot.write_i64(6000000000)
- @trans.read(@trans.available).should == "6000000000"
- end
+ it "should write i64" do
+ @prot.write_i64(6000000000)
+ @trans.read(@trans.available).should == "6000000000"
+ end
- it "should write double" do
- @prot.write_double(1.23)
- @trans.read(@trans.available).should == "1.23"
+ it "should write double" do
+ @prot.write_double(1.23)
+ @trans.read(@trans.available).should == "1.23"
- @prot.write_double(-32.1)
- @trans.read(@trans.available).should == "-32.1"
+ @prot.write_double(-32.1)
+ @trans.read(@trans.available).should == "-32.1"
- @prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
- @trans.read(@trans.available).should == "\"NaN\""
+ @prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
+ @trans.read(@trans.available).should == "\"NaN\""
- @prot.write_double((+1.0/0.0))
- @trans.read(@trans.available).should == "\"Infinity\""
+ @prot.write_double((+1.0/0.0))
+ @trans.read(@trans.available).should == "\"Infinity\""
- @prot.write_double((-1.0/0.0))
- @trans.read(@trans.available).should == "\"-Infinity\""
- end
+ @prot.write_double((-1.0/0.0))
+ @trans.read(@trans.available).should == "\"-Infinity\""
+ end
- it "should write string" do
- @prot.write_string("this is a test string")
- @trans.read(@trans.available).should == "\"this is a test string\""
- end
+ it "should write string" do
+ @prot.write_string("this is a test string")
+ @trans.read(@trans.available).should == "\"this is a test string\""
+ end
- it "should write binary" do
- @prot.write_binary("this is a base64 string")
- @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
- end
+ it "should write binary" do
+ @prot.write_binary("this is a base64 string")
+ @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
+ end
- it "should get type name for type id" do
- expect {@prot.get_type_name_for_type_id(Types::STOP)}.to raise_error(NotImplementedError)
- expect {@prot.get_type_name_for_type_id(Types::VOID)}.to raise_error(NotImplementedError)
- @prot.get_type_name_for_type_id(Types::BOOL).should == "tf"
- @prot.get_type_name_for_type_id(Types::BYTE).should == "i8"
- @prot.get_type_name_for_type_id(Types::DOUBLE).should == "dbl"
- @prot.get_type_name_for_type_id(Types::I16).should == "i16"
- @prot.get_type_name_for_type_id(Types::I32).should == "i32"
- @prot.get_type_name_for_type_id(Types::I64).should == "i64"
- @prot.get_type_name_for_type_id(Types::STRING).should == "str"
- @prot.get_type_name_for_type_id(Types::STRUCT).should == "rec"
- @prot.get_type_name_for_type_id(Types::MAP).should == "map"
- @prot.get_type_name_for_type_id(Types::SET).should == "set"
- @prot.get_type_name_for_type_id(Types::LIST).should == "lst"
- 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"
+ 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 == Types::BOOL
- @prot.get_type_id_for_type_name("i8").should == Types::BYTE
- @prot.get_type_id_for_type_name("dbl").should == Types::DOUBLE
- @prot.get_type_id_for_type_name("i16").should == Types::I16
- @prot.get_type_id_for_type_name("i32").should == Types::I32
- @prot.get_type_id_for_type_name("i64").should == Types::I64
- @prot.get_type_id_for_type_name("str").should == Types::STRING
- @prot.get_type_id_for_type_name("rec").should == Types::STRUCT
- @prot.get_type_id_for_type_name("map").should == Types::MAP
- @prot.get_type_id_for_type_name("set").should == Types::SET
- @prot.get_type_id_for_type_name("lst").should == Types::LIST
- 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
+ end
- it "should read json syntax char" do
- @trans.write('F')
- expect {@prot.read_json_syntax_char('G')}.to raise_error(ProtocolException)
- @trans.write('H')
- @prot.read_json_syntax_char('H')
- end
+ it "should read json syntax char" do
+ @trans.write('F')
+ expect {@prot.read_json_syntax_char('G')}.to raise_error(Thrift::ProtocolException)
+ @trans.write('H')
+ @prot.read_json_syntax_char('H')
+ end
- it "should read json escape char" do
- @trans.write('0054')
- @prot.read_json_escape_char.should == 'T'
- end
+ it "should read json escape char" do
+ @trans.write('0054')
+ @prot.read_json_escape_char.should == 'T'
+ end
- it "should read json string" do
- @trans.write("\"\\P")
- expect {@prot.read_json_string(false)}.to raise_error(ProtocolException)
+ it "should read json string" do
+ @trans.write("\"\\P")
+ expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
- @trans.write("\"\\n\"")
- @prot.read_json_string(false).should == "\\n"
+ @trans.write("\"\\n\"")
+ @prot.read_json_string(false).should == "\\n"
- @trans.write("\"this is a test string\"")
- @prot.read_json_string.should == "this is a test string"
- end
+ @trans.write("\"this is a test string\"")
+ @prot.read_json_string.should == "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"
- end
+ it "should read json base64" do
+ @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
+ @prot.read_json_base64.should == "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
- 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
+ end
- it "should read json numeric chars" do
- @trans.write("1.453E45T")
- @prot.read_json_numeric_chars.should == "1.453E45"
- end
+ it "should read json numeric chars" do
+ @trans.write("1.453E45T")
+ @prot.read_json_numeric_chars.should == "1.453E45"
+ end
- it "should read json integer" do
- @trans.write("1.45\"\"")
- expect {@prot.read_json_integer}.to raise_error(ProtocolException)
- @prot.read_string
+ it "should read json integer" do
+ @trans.write("1.45\"\"")
+ expect {@prot.read_json_integer}.to raise_error(Thrift::ProtocolException)
+ @prot.read_string
- @trans.write("1453T")
- @prot.read_json_integer.should == 1453
- end
+ @trans.write("1453T")
+ @prot.read_json_integer.should == 1453
+ end
- it "should read json double" do
- @trans.write("1.45e3e01\"\"")
- expect {@prot.read_json_double}.to raise_error(ProtocolException)
- @prot.read_string
+ it "should read json double" do
+ @trans.write("1.45e3e01\"\"")
+ expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
+ @prot.read_string
- @trans.write("\"1.453e01\"")
- expect {@prot.read_json_double}.to raise_error(ProtocolException)
+ @trans.write("\"1.453e01\"")
+ expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
- @trans.write("1.453e01\"\"")
- @prot.read_json_double.should == 14.53
- @prot.read_string
+ @trans.write("1.453e01\"\"")
+ @prot.read_json_double.should == 14.53
+ @prot.read_string
- @trans.write("\"NaN\"")
- @prot.read_json_double.nan?.should == true
+ @trans.write("\"NaN\"")
+ @prot.read_json_double.nan?.should == true
- @trans.write("\"Infinity\"")
- @prot.read_json_double.should == +1.0/0.0
+ @trans.write("\"Infinity\"")
+ @prot.read_json_double.should == +1.0/0.0
- @trans.write("\"-Infinity\"")
- @prot.read_json_double.should == -1.0/0.0
- end
+ @trans.write("\"-Infinity\"")
+ @prot.read_json_double.should == -1.0/0.0
+ end
- it "should read json object start" do
- @trans.write("{")
- @prot.read_json_object_start.should == nil
- end
+ it "should read json object start" do
+ @trans.write("{")
+ @prot.read_json_object_start.should == nil
+ end
- it "should read json object end" do
- @trans.write("}")
- @prot.read_json_object_end.should == nil
- end
+ it "should read json object end" do
+ @trans.write("}")
+ @prot.read_json_object_end.should == nil
+ end
- it "should read json array start" do
- @trans.write("[")
- @prot.read_json_array_start.should == nil
- end
+ it "should read json array start" do
+ @trans.write("[")
+ @prot.read_json_array_start.should == nil
+ end
- it "should read json array end" do
- @trans.write("]")
- @prot.read_json_array_end.should == nil
- end
+ it "should read json array end" do
+ @trans.write("]")
+ @prot.read_json_array_end.should == nil
+ end
- it "should read_message_begin" do
- @trans.write("[2,")
- expect {@prot.read_message_begin}.to raise_error(ProtocolException)
+ it "should read_message_begin" do
+ @trans.write("[2,")
+ expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
- @trans.write("[1,\"name\",12,32\"\"")
- @prot.read_message_begin.should == ["name", 12, 32]
- end
+ @trans.write("[1,\"name\",12,32\"\"")
+ @prot.read_message_begin.should == ["name", 12, 32]
+ end
- it "should read message end" do
- @trans.write("]")
- @prot.read_message_end.should == nil
- end
+ it "should read message end" do
+ @trans.write("]")
+ @prot.read_message_end.should == nil
+ end
- it "should read struct begin" do
- @trans.write("{")
- @prot.read_struct_begin.should == nil
- end
+ it "should read struct begin" do
+ @trans.write("{")
+ @prot.read_struct_begin.should == nil
+ end
- it "should read struct end" do
- @trans.write("}")
- @prot.read_struct_end.should == nil
- end
+ it "should read struct end" do
+ @trans.write("}")
+ @prot.read_struct_end.should == nil
+ end
- it "should read field begin" do
- @trans.write("1{\"rec\"")
- @prot.read_field_begin.should == [nil, 12, 1]
- end
+ it "should read field begin" do
+ @trans.write("1{\"rec\"")
+ @prot.read_field_begin.should == [nil, 12, 1]
+ end
- it "should read field end" do
- @trans.write("}")
- @prot.read_field_end.should == nil
- end
+ it "should read field end" do
+ @trans.write("}")
+ @prot.read_field_end.should == nil
+ end
- it "should read map begin" do
- @trans.write("[\"rec\",\"lst\",2,{")
- @prot.read_map_begin.should == [12, 15, 2]
- end
+ it "should read map begin" do
+ @trans.write("[\"rec\",\"lst\",2,{")
+ @prot.read_map_begin.should == [12, 15, 2]
+ end
- it "should read map end" do
- @trans.write("}]")
- @prot.read_map_end.should == nil
- end
+ it "should read map end" do
+ @trans.write("}]")
+ @prot.read_map_end.should == nil
+ end
- it "should read list begin" do
- @trans.write("[\"rec\",2\"\"")
- @prot.read_list_begin.should == [12, 2]
- end
+ it "should read list begin" do
+ @trans.write("[\"rec\",2\"\"")
+ @prot.read_list_begin.should == [12, 2]
+ end
- it "should read list end" do
- @trans.write("]")
- @prot.read_list_end.should == nil
- end
+ it "should read list end" do
+ @trans.write("]")
+ @prot.read_list_end.should == nil
+ end
- it "should read set begin" do
- @trans.write("[")
- @prot.read_set_begin.should == nil
- end
+ it "should read set begin" do
+ @trans.write("[")
+ @prot.read_set_begin.should == nil
+ end
- it "should read set end" do
- @trans.write("]")
- @prot.read_set_end.should == nil
- end
+ it "should read set end" do
+ @trans.write("]")
+ @prot.read_set_end.should == nil
+ end
- it "should read bool" do
- @trans.write("0\"\"")
- @prot.read_bool.should == false
- @prot.read_string
+ it "should read bool" do
+ @trans.write("0\"\"")
+ @prot.read_bool.should == false
+ @prot.read_string
- @trans.write("1\"\"")
- @prot.read_bool.should == true
- end
+ @trans.write("1\"\"")
+ @prot.read_bool.should == true
+ end
- it "should read byte" do
- @trans.write("60\"\"")
- @prot.read_byte.should == 60
- end
+ it "should read byte" do
+ @trans.write("60\"\"")
+ @prot.read_byte.should == 60
+ end
- it "should read i16" do
- @trans.write("1000\"\"")
- @prot.read_i16.should == 1000
- end
+ it "should read i16" do
+ @trans.write("1000\"\"")
+ @prot.read_i16.should == 1000
+ end
- it "should read i32" do
- @trans.write("3000000000\"\"")
- @prot.read_i32.should == 3000000000
- end
+ it "should read i32" do
+ @trans.write("3000000000\"\"")
+ @prot.read_i32.should == 3000000000
+ end
- it "should read i64" do
- @trans.write("6000000000\"\"")
- @prot.read_i64.should == 6000000000
- end
+ it "should read i64" do
+ @trans.write("6000000000\"\"")
+ @prot.read_i64.should == 6000000000
+ end
- it "should read double" do
- @trans.write("12.23\"\"")
- @prot.read_double.should == 12.23
- end
+ it "should read double" do
+ @trans.write("12.23\"\"")
+ @prot.read_double.should == 12.23
+ end
- it "should read string" do
- @trans.write("\"this is a test string\"")
- @prot.read_string.should == "this is a test string"
- end
+ it "should read string" do
+ @trans.write("\"this is a test string\"")
+ @prot.read_string.should == "this is a test string"
+ end
- it "should read binary" do
- @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
- @prot.read_binary.should == "this is a test string"
+ it "should read binary" do
+ @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
+ @prot.read_binary.should == "this is a test string"
+ end
end
- describe JsonProtocolFactory do
+ describe Thrift::JsonProtocolFactory do
it "should create a JsonProtocol" do
- JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(JsonProtocol)
+ Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol)
end
end
end
diff --git a/lib/rb/spec/mongrel_http_server_spec.rb b/lib/rb/spec/mongrel_http_server_spec.rb
index 5375bece3..643630f70 100644
--- a/lib/rb/spec/mongrel_http_server_spec.rb
+++ b/lib/rb/spec/mongrel_http_server_spec.rb
@@ -17,27 +17,24 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
require 'thrift/server/mongrel_http_server'
-class ThriftHTTPServerSpec < Spec::ExampleGroup
- include Thrift
+describe 'HTTPServer' do
- Handler = MongrelHTTPServer::Handler
-
- describe MongrelHTTPServer do
+ describe Thrift::MongrelHTTPServer do
it "should have appropriate defaults" do
mock_factory = mock("BinaryProtocolFactory")
mock_proc = mock("Processor")
- BinaryProtocolFactory.should_receive(:new).and_return(mock_factory)
+ Thrift::BinaryProtocolFactory.should_receive(:new).and_return(mock_factory)
Mongrel::HttpServer.should_receive(:new).with("0.0.0.0", 80).and_return do
mock("Mongrel::HttpServer").tee do |mock|
handler = mock("Handler")
- Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
+ Thrift::MongrelHTTPServer::Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
mock.should_receive(:register).with("/", handler)
end
end
- MongrelHTTPServer.new(mock_proc)
+ Thrift::MongrelHTTPServer.new(mock_proc)
end
it "should understand :ip, :port, :path, and :protocol_factory" do
@@ -46,19 +43,19 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
Mongrel::HttpServer.should_receive(:new).with("1.2.3.4", 1234).and_return do
mock("Mongrel::HttpServer").tee do |mock|
handler = mock("Handler")
- Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
+ Thrift::MongrelHTTPServer::Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
mock.should_receive(:register).with("/foo", handler)
end
end
- MongrelHTTPServer.new(mock_proc, :ip => "1.2.3.4", :port => 1234, :path => "foo",
+ Thrift::MongrelHTTPServer.new(mock_proc, :ip => "1.2.3.4", :port => 1234, :path => "foo",
:protocol_factory => mock_factory)
end
it "should serve using Mongrel::HttpServer" do
- BinaryProtocolFactory.stub!(:new)
+ Thrift::BinaryProtocolFactory.stub!(:new)
Mongrel::HttpServer.should_receive(:new).and_return do
mock("Mongrel::HttpServer").tee do |mock|
- Handler.stub!(:new)
+ Thrift::MongrelHTTPServer::Handler.stub!(:new)
mock.stub!(:register)
mock.should_receive(:run).and_return do
mock("Mongrel::HttpServer.run").tee do |runner|
@@ -67,15 +64,15 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
end
end
end
- MongrelHTTPServer.new(nil).serve
+ Thrift::MongrelHTTPServer.new(nil).serve
end
end
- describe MongrelHTTPServer::Handler do
+ describe Thrift::MongrelHTTPServer::Handler do
before(:each) do
@processor = mock("Processor")
@factory = mock("ProtocolFactory")
- @handler = Handler.new(@processor, @factory)
+ @handler = described_class.new(@processor, @factory)
end
it "should return 404 for non-POST requests" do
@@ -91,7 +88,7 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
response = mock("response")
head = mock("head")
head.should_receive(:[]=).with("Content-Type", "application/x-thrift")
- IOStreamTransport.stub!(:new)
+ Thrift::IOStreamTransport.stub!(:new)
@factory.stub!(:get_protocol)
@processor.stub!(:process)
response.should_receive(:start).with(200).and_yield(head, nil)
@@ -107,7 +104,7 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
out = mock("out")
protocol = mock("protocol")
transport = mock("transport")
- IOStreamTransport.should_receive(:new).with(body, out).and_return(transport)
+ Thrift::IOStreamTransport.should_receive(:new).with(body, out).and_return(transport)
@factory.should_receive(:get_protocol).with(transport).and_return(protocol)
@processor.should_receive(:process).with(protocol, protocol)
response.should_receive(:start).with(200).and_yield(head, out)
diff --git a/lib/rb/spec/nonblocking_server_spec.rb b/lib/rb/spec/nonblocking_server_spec.rb
index 720050462..712cf45c2 100644
--- a/lib/rb/spec/nonblocking_server_spec.rb
+++ b/lib/rb/spec/nonblocking_server_spec.rb
@@ -17,11 +17,9 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftNonblockingServerSpec < Spec::ExampleGroup
- include Thrift
- include SpecNamespace
+describe 'NonblockingServer' do
class Handler
def initialize
@@ -55,7 +53,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
end
end
- class SpecTransport < BaseTransport
+ class SpecTransport < Thrift::BaseTransport
def initialize(transport, queue)
@transport = transport
@queue = queue
@@ -89,7 +87,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
end
end
- class SpecServerSocket < ServerSocket
+ class SpecServerSocket < Thrift::ServerSocket
def initialize(host, port, queue)
super(host, port)
@queue = queue
@@ -105,13 +103,13 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
before(:each) do
@port = 43251
handler = Handler.new
- processor = NonblockingService::Processor.new(handler)
+ processor = SpecNamespace::NonblockingService::Processor.new(handler)
queue = Queue.new
@transport = SpecServerSocket.new('localhost', @port, queue)
- transport_factory = FramedTransportFactory.new
+ transport_factory = Thrift::FramedTransportFactory.new
logger = Logger.new(STDERR)
logger.level = Logger::WARN
- @server = NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
+ @server = Thrift::NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
handler.server = @server
@server_thread = Thread.new(Thread.current) do |master_thread|
begin
@@ -136,9 +134,9 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
end
def setup_client(queue = nil)
- transport = SpecTransport.new(FramedTransport.new(Socket.new('localhost', @port)), queue)
- protocol = BinaryProtocol.new(transport)
- client = NonblockingService::Client.new(protocol)
+ transport = SpecTransport.new(Thrift::FramedTransport.new(Thrift::Socket.new('localhost', @port)), queue)
+ protocol = Thrift::BinaryProtocol.new(transport)
+ client = SpecNamespace::NonblockingService::Client.new(protocol)
transport.open
@clients << [client, transport]
client
@@ -178,8 +176,8 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
it "should handle basic message passing" do
client = setup_client
- client.greeting(true).should == Hello.new
- client.greeting(false).should == Hello.new(:greeting => 'Aloha!')
+ client.greeting(true).should == SpecNamespace::Hello.new
+ client.greeting(false).should == SpecNamespace::Hello.new(:greeting => 'Aloha!')
@server.shutdown
end
@@ -214,15 +212,15 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
queues[4] << :hello
queues[5] << :hello
queues[6] << :hello
- 3.times { result.pop.should == Hello.new }
- client.greeting(true).should == Hello.new
+ 3.times { result.pop.should == SpecNamespace::Hello.new }
+ client.greeting(true).should == SpecNamespace::Hello.new
queues[5] << [:unblock, 4]
4.times { result.pop.should be_true }
queues[2] << :hello
- result.pop.should == Hello.new
- client.greeting(false).should == Hello.new(:greeting => 'Aloha!')
+ result.pop.should == SpecNamespace::Hello.new
+ client.greeting(false).should == SpecNamespace::Hello.new(:greeting => 'Aloha!')
7.times { queues.shift << :exit }
- client.greeting(true).should == Hello.new
+ client.greeting(true).should == SpecNamespace::Hello.new
@server.shutdown
end
@@ -257,7 +255,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
it "should allow shutting down in response to a message" do
client = setup_client
- client.greeting(true).should == Hello.new
+ client.greeting(true).should == SpecNamespace::Hello.new
client.shutdown
@server_thread.join(2).should_not be_nil
end
diff --git a/lib/rb/spec/processor_spec.rb b/lib/rb/spec/processor_spec.rb
index d78edac04..ef3bc85b3 100644
--- a/lib/rb/spec/processor_spec.rb
+++ b/lib/rb/spec/processor_spec.rb
@@ -17,16 +17,15 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftProcessorSpec < Spec::ExampleGroup
- include Thrift
+describe 'Processor' do
class ProcessorSpec
include Thrift::Processor
end
- describe "Processor" do
+ describe Thrift::Processor do
before(:each) do
@processor = ProcessorSpec.new(mock("MockHandler"))
@prot = mock("MockProtocol")
@@ -41,21 +40,19 @@ class ThriftProcessorSpec < Spec::ExampleGroup
end
it "should call process_<message> when it receives that message" do
- @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 17]
+ @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
end
it "should raise an ApplicationException when the received message cannot be processed" do
- @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 4]
- @prot.should_receive(:skip).with(Types::STRUCT).ordered
+ @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', MessageTypes::EXCEPTION, 4).ordered
- ApplicationException.should_receive(:new).with(ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return do
- mock(ApplicationException).tee do |e|
- e.should_receive(:write).with(@prot).ordered
- end
- end
+ @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
mock_trans(@prot)
@processor.process(@prot, @prot)
@@ -72,7 +69,7 @@ class ThriftProcessorSpec < Spec::ExampleGroup
end
it "should write out a reply when asked" do
- @prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::REPLY, 23).ordered
+ @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
diff --git a/lib/rb/spec/serializer_spec.rb b/lib/rb/spec/serializer_spec.rb
index 2ecb85b97..599b454bb 100644
--- a/lib/rb/spec/serializer_spec.rb
+++ b/lib/rb/spec/serializer_spec.rb
@@ -17,53 +17,51 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftSerializerSpec < Spec::ExampleGroup
- include Thrift
- include SpecNamespace
+describe 'Serializer' do
- describe Serializer do
+ describe Thrift::Serializer do
it "should serialize structs to binary by default" do
- serializer = Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
- data = serializer.serialize(Hello.new(:greeting => "'Ello guv'nor!"))
+ 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"
end
it "should serialize structs to the given protocol" do
- protocol = BaseProtocol.new(mock("transport"))
+ protocol = Thrift::BaseProtocol.new(mock("transport"))
protocol.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
- protocol.should_receive(:write_field_begin).with("greeting", Types::STRING, 1)
+ 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)
- serializer = Serializer.new(protocol_factory)
- serializer.serialize(Hello.new(:greeting => "Good day"))
+ serializer = Thrift::Serializer.new(protocol_factory)
+ serializer.serialize(SpecNamespace::Hello.new(:greeting => "Good day"))
end
end
- describe Deserializer do
+ describe Thrift::Deserializer do
it "should deserialize structs from binary by default" do
- deserializer = Deserializer.new
+ deserializer = Thrift::Deserializer.new
data = "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
- deserializer.deserialize(Hello.new, data).should == Hello.new(:greeting => "'Ello guv'nor!")
+ deserializer.deserialize(SpecNamespace::Hello.new, data).should == SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!")
end
it "should deserialize structs from the given protocol" do
- protocol = BaseProtocol.new(mock("transport"))
+ 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", Types::STRING, 1],
- [nil, Types::STOP, 0])
+ protocol.should_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)
- deserializer = Deserializer.new(protocol_factory)
- deserializer.deserialize(Hello.new, "").should == Hello.new(:greeting => "Good day")
+ deserializer = Thrift::Deserializer.new(protocol_factory)
+ deserializer.deserialize(SpecNamespace::Hello.new, "").should == 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 071acba46..1301d540f 100644
--- a/lib/rb/spec/server_socket_spec.rb
+++ b/lib/rb/spec/server_socket_spec.rb
@@ -17,15 +17,14 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
-class ThriftServerSocketSpec < Spec::ExampleGroup
- include Thrift
+describe 'Thrift::ServerSocket' do
- describe ServerSocket do
+ describe Thrift::ServerSocket do
before(:each) do
- @socket = ServerSocket.new(1234)
+ @socket = Thrift::ServerSocket.new(1234)
end
it "should create a handle when calling listen" do
@@ -34,7 +33,7 @@ class ThriftServerSocketSpec < Spec::ExampleGroup
end
it "should accept an optional host argument" do
- @socket = ServerSocket.new('localhost', 1234)
+ @socket = Thrift::ServerSocket.new('localhost', 1234)
TCPServer.should_receive(:new).with('localhost', 1234)
@socket.listen
end
@@ -46,7 +45,7 @@ class ThriftServerSocketSpec < Spec::ExampleGroup
sock = mock("sock")
handle.should_receive(:accept).and_return(sock)
trans = mock("Socket")
- Socket.should_receive(:new).and_return(trans)
+ Thrift::Socket.should_receive(:new).and_return(trans)
trans.should_receive(:handle=).with(sock)
@socket.accept.should == trans
end
diff --git a/lib/rb/spec/server_spec.rb b/lib/rb/spec/server_spec.rb
index a6339562a..0e952ab09 100644
--- a/lib/rb/spec/server_spec.rb
+++ b/lib/rb/spec/server_spec.rb
@@ -16,39 +16,30 @@
# specific language governing permissions and limitations
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftServerSpec < Spec::ExampleGroup
- include Thrift
+describe 'Server' do
- describe BaseServer do
+ describe Thrift::BaseServer do
it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
- server = BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
- server.instance_variable_get(:'@transport_factory').should be_an_instance_of(BaseTransportFactory)
- server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(BinaryProtocolFactory)
+ 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)
end
# serve is a noop, so can't test that
end
- shared_examples_for "servers" do
+ describe Thrift::SimpleServer do
before(:each) do
@processor = mock("Processor")
@serverTrans = mock("ServerTransport")
@trans = mock("BaseTransport")
@prot = mock("BaseProtocol")
@client = mock("Client")
- @server = server_type.new(@processor, @serverTrans, @trans, @prot)
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
- end
-
- describe SimpleServer do
- it_should_behave_like "servers"
-
- def server_type
- SimpleServer
- end
-
+
it "should serve in the main thread" do
@serverTrans.should_receive(:listen).ordered
@serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
@@ -68,11 +59,14 @@ class ThriftServerSpec < Spec::ExampleGroup
end
end
- describe ThreadedServer do
- it_should_behave_like "servers"
-
- def server_type
- ThreadedServer
+ describe Thrift::ThreadedServer do
+ before(:each) do
+ @processor = mock("Processor")
+ @serverTrans = mock("ServerTransport")
+ @trans = mock("BaseTransport")
+ @prot = mock("BaseProtocol")
+ @client = mock("Client")
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should serve using threads" do
@@ -95,16 +89,18 @@ class ThriftServerSpec < Spec::ExampleGroup
end
end
- describe ThreadPoolServer do
- it_should_behave_like "servers"
-
- def server_type
- # put this stuff here so it runs before the server is created
+ describe Thrift::ThreadPoolServer do
+ before(:each) do
+ @processor = mock("Processor")
+ @serverTrans = mock("ServerTransport")
+ @trans = mock("BaseTransport")
+ @prot = mock("BaseProtocol")
+ @client = mock("Client")
@threadQ = mock("SizedQueue")
SizedQueue.should_receive(:new).with(20).and_return(@threadQ)
@excQ = mock("Queue")
Queue.should_receive(:new).and_return(@excQ)
- ThreadPoolServer
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
end
it "should set up the queues" do
@@ -113,21 +109,13 @@ class ThriftServerSpec < Spec::ExampleGroup
end
it "should serve inside a thread" do
- Thread.should_receive(:new).and_return do |block|
- @server.should_receive(:serve)
- block.call
- @server.rspec_verify
- end
+ @server.should_receive(:serve)
@excQ.should_receive(:pop).and_throw(:popped)
lambda { @server.rescuable_serve }.should throw_symbol(:popped)
end
it "should avoid running the server twice when retrying rescuable_serve" do
- Thread.should_receive(:new).and_return do |block|
- @server.should_receive(:serve)
- block.call
- @server.rspec_verify
- end
+ @server.should_receive(:serve)
@excQ.should_receive(:pop).twice.and_throw(:popped)
lambda { @server.rescuable_serve }.should throw_symbol(:popped)
lambda { @server.rescuable_serve }.should throw_symbol(:popped)
diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb
index d5ae6b03e..ef8a0a119 100644
--- a/lib/rb/spec/socket_spec.rb
+++ b/lib/rb/spec/socket_spec.rb
@@ -17,15 +17,14 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
-class ThriftSocketSpec < Spec::ExampleGroup
- include Thrift
+describe 'Socket' do
- describe Socket do
+ describe Thrift::Socket do
before(:each) do
- @socket = Socket.new
+ @socket = Thrift::Socket.new
@handle = mock("Handle", :closed? => false)
@handle.stub!(:close)
@handle.stub!(:connect_nonblock)
@@ -50,12 +49,12 @@ class ThriftSocketSpec < Spec::ExampleGroup
::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true))
::Socket.should_receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
::Socket.should_receive(:sockaddr_in)
- Socket.new('my.domain', 1234).open
+ Thrift::Socket.new('my.domain', 1234).open
end
it "should accept an optional timeout" do
::Socket.stub!(:new)
- Socket.new('localhost', 8080, 5).timeout.should == 5
+ Thrift::Socket.new('localhost', 8080, 5).timeout.should == 5
end
end
end
diff --git a/lib/rb/spec/socket_spec_shared.rb b/lib/rb/spec/socket_spec_shared.rb
index 8d2dae72e..5fddc16a7 100644
--- a/lib/rb/spec/socket_spec_shared.rb
+++ b/lib/rb/spec/socket_spec_shared.rb
@@ -17,7 +17,7 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
shared_examples_for "a socket" do
it "should open a socket" do
diff --git a/lib/rb/spec/spec_helper.rb b/lib/rb/spec/spec_helper.rb
index ccb1adf1d..9701c7cc9 100644
--- a/lib/rb/spec/spec_helper.rb
+++ b/lib/rb/spec/spec_helper.rb
@@ -18,7 +18,7 @@
#
require 'rubygems'
-require 'spec'
+require 'rspec'
$:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
@@ -26,7 +26,7 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
# will get screwed up
# $" << 'fastthread.bundle'
-require File.dirname(__FILE__) + '/../lib/thrift'
+require 'thrift'
class Object
# tee is a useful method, so let's let our tests have it
@@ -36,15 +36,15 @@ class Object
end
end
-Spec::Runner.configure do |configuration|
+RSpec.configure do |configuration|
configuration.before(:each) do
Thrift.type_checking = true
end
end
$:.unshift File.join(File.dirname(__FILE__), *%w[.. test debug_proto gen-rb])
-require "srv"
-require "debug_proto_test_constants"
+require 'srv'
+require 'debug_proto_test_constants'
$:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb])
require 'thrift_spec_types'
diff --git a/lib/rb/spec/struct_nested_containers_spec.rb b/lib/rb/spec/struct_nested_containers_spec.rb
index e1ea64d59..dc8ce5f58 100644
--- a/lib/rb/spec/struct_nested_containers_spec.rb
+++ b/lib/rb/spec/struct_nested_containers_spec.rb
@@ -17,11 +17,9 @@
# under the License.
#
-require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
+require 'spec_helper'
-class StructNestedContainersSpec < Spec::ExampleGroup
- include Thrift
- include SpecNamespace
+describe 'StructNestedContainers' do
def with_type_checking
saved_type_checking, Thrift.type_checking = Thrift.type_checking, true
@@ -32,11 +30,11 @@ class StructNestedContainersSpec < Spec::ExampleGroup
end
end
- describe Struct do
+ describe Thrift::Struct do
# Nested container tests, see THRIFT-369.
it "should support nested lists inside lists" do
with_type_checking do
- a, b = NestedListInList.new, NestedListInList.new
+ a, b = SpecNamespace::NestedListInList.new, SpecNamespace::NestedListInList.new
[a, b].each do |thrift_struct|
thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ]
thrift_struct.validate
@@ -49,7 +47,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested lists inside sets" do
with_type_checking do
- a, b = NestedListInSet.new, NestedListInSet.new
+ a, b = SpecNamespace::NestedListInSet.new, SpecNamespace::NestedListInSet.new
[a, b].each do |thrift_struct|
thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ].to_set
thrift_struct.validate
@@ -62,7 +60,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested lists in map keys" do
with_type_checking do
- a, b = NestedListInMapKey.new, NestedListInMapKey.new
+ a, b = SpecNamespace::NestedListInMapKey.new, SpecNamespace::NestedListInMapKey.new
[a, b].each do |thrift_struct|
thrift_struct.value = { [1, 2, 3] => 1, [2, 3, 4] => 2 }
thrift_struct.validate
@@ -75,7 +73,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested lists in map values" do
with_type_checking do
- a, b = NestedListInMapValue.new, NestedListInMapValue.new
+ a, b = SpecNamespace::NestedListInMapValue.new, SpecNamespace::NestedListInMapValue.new
[a, b].each do |thrift_struct|
thrift_struct.value = { 1 => [1, 2, 3], 2 => [2, 3, 4] }
thrift_struct.validate
@@ -88,7 +86,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested sets inside lists" do
with_type_checking do
- a, b = NestedSetInList.new, NestedSetInList.new
+ a, b = SpecNamespace::NestedSetInList.new, SpecNamespace::NestedSetInList.new
[a, b].each do |thrift_struct|
thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ]
thrift_struct.validate
@@ -101,7 +99,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested sets inside sets" do
with_type_checking do
- a, b = NestedSetInSet.new, NestedSetInSet.new
+ a, b = SpecNamespace::NestedSetInSet.new, SpecNamespace::NestedSetInSet.new
[a, b].each do |thrift_struct|
thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ].to_set
thrift_struct.validate
@@ -114,7 +112,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested sets in map keys" do
with_type_checking do
- a, b = NestedSetInMapKey.new, NestedSetInMapKey.new
+ a, b = SpecNamespace::NestedSetInMapKey.new, SpecNamespace::NestedSetInMapKey.new
[a, b].each do |thrift_struct|
thrift_struct.value = { [1, 2, 3].to_set => 1, [2, 3, 4].to_set => 2 }
thrift_struct.validate
@@ -127,7 +125,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested sets in map values" do
with_type_checking do
- a, b = NestedSetInMapValue.new, NestedSetInMapValue.new
+ a, b = SpecNamespace::NestedSetInMapValue.new, SpecNamespace::NestedSetInMapValue.new
[a, b].each do |thrift_struct|
thrift_struct.value = { 1 => [1, 2, 3].to_set, 2 => [2, 3, 4].to_set }
thrift_struct.validate
@@ -140,7 +138,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested maps inside lists" do
with_type_checking do
- a, b = NestedMapInList.new, NestedMapInList.new
+ a, b = SpecNamespace::NestedMapInList.new, SpecNamespace::NestedMapInList.new
[a, b].each do |thrift_struct|
thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ]
thrift_struct.validate
@@ -153,7 +151,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested maps inside sets" do
with_type_checking do
- a, b = NestedMapInSet.new, NestedMapInSet.new
+ a, b = SpecNamespace::NestedMapInSet.new, SpecNamespace::NestedMapInSet.new
[a, b].each do |thrift_struct|
thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ].to_set
thrift_struct.validate
@@ -166,7 +164,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested maps in map keys" do
with_type_checking do
- a, b = NestedMapInMapKey.new, NestedMapInMapKey.new
+ a, b = SpecNamespace::NestedMapInMapKey.new, SpecNamespace::NestedMapInMapKey.new
[a, b].each do |thrift_struct|
thrift_struct.value = { { 1 => 2, 3 => 4} => 1, {2 => 3, 4 => 5} => 2 }
thrift_struct.validate
@@ -179,7 +177,7 @@ class StructNestedContainersSpec < Spec::ExampleGroup
it "should support nested maps in map values" do
with_type_checking do
- a, b = NestedMapInMapValue.new, NestedMapInMapValue.new
+ a, b = SpecNamespace::NestedMapInMapValue.new, SpecNamespace::NestedMapInMapValue.new
[a, b].each do |thrift_struct|
thrift_struct.value = { 1 => { 1 => 2, 3 => 4}, 2 => {2 => 3, 4 => 5} }
thrift_struct.validate
diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb
index 12013bda1..6534d616a 100644
--- a/lib/rb/spec/struct_spec.rb
+++ b/lib/rb/spec/struct_spec.rb
@@ -17,25 +17,23 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftStructSpec < Spec::ExampleGroup
- include Thrift
- include SpecNamespace
+describe 'Struct' do
- describe Struct do
+ describe Thrift::Struct do
it "should iterate over all fields properly" do
fields = {}
- Foo.new.each_field { |fid,field_info| fields[fid] = field_info }
- fields.should == Foo::FIELDS
+ SpecNamespace::Foo.new.each_field { |fid,field_info| fields[fid] = field_info }
+ fields.should == SpecNamespace::Foo::FIELDS
end
it "should initialize all fields to defaults" do
- validate_default_arguments(Foo.new)
+ validate_default_arguments(SpecNamespace::Foo.new)
end
it "should initialize all fields to defaults and accept a block argument" do
- Foo.new do |f|
+ SpecNamespace::Foo.new do |f|
validate_default_arguments(f)
end
end
@@ -43,7 +41,7 @@ class ThriftStructSpec < Spec::ExampleGroup
def validate_default_arguments(object)
object.simple.should == 53
object.words.should == "words"
- object.hello.should == Hello.new(:greeting => 'hello, world!')
+ 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])
@@ -51,79 +49,79 @@ class ThriftStructSpec < Spec::ExampleGroup
it "should not share default values between instances" do
begin
- struct = Foo.new
+ struct = SpecNamespace::Foo.new
struct.ints << 17
- Foo.new.ints.should == [1,2,2,3]
+ SpecNamespace::Foo.new.ints.should == [1,2,2,3]
ensure
# ensure no leakage to other tests
- Foo::FIELDS[4][:default] = [1,2,2,3]
+ SpecNamespace::Foo::FIELDS[4][:default] = [1,2,2,3]
end
end
it "should properly initialize boolean values" do
- struct = BoolStruct.new(:yesno => false)
+ struct = SpecNamespace::BoolStruct.new(:yesno => false)
struct.yesno.should be_false
end
it "should have proper == semantics" do
- Foo.new.should_not == Hello.new
- Foo.new.should == Foo.new
- Foo.new(:simple => 52).should_not == Foo.new
+ 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
end
it "should print enum value names in inspect" do
- StructWithSomeEnum.new(:some_enum => SomeEnum::ONE).inspect.should == "<SpecNamespace::StructWithSomeEnum some_enum:ONE (0)>"
+ SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::StructWithSomeEnum some_enum:ONE (0)>"
- StructWithEnumMap.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::StructWithEnumMap my_map:{ONE (0): [TWO (1)]}>"
+ SpecNamespace::StructWithEnumMap.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::StructWithEnumMap my_map:{ONE (0): [TWO (1)]}>"
end
it "should pretty print binary fields" do
- Foo2.new(:my_binary => "\001\002\003").inspect.should == "<SpecNamespace::Foo2 my_binary:010203>"
+ SpecNamespace::Foo2.new(:my_binary => "\001\002\003").inspect.should == "<SpecNamespace::Foo2 my_binary:010203>"
end
it "should offer field? methods" do
- Foo.new.opt_string?.should be_false
- Foo.new(:simple => 52).simple?.should be_true
- Foo.new(:my_bool => false).my_bool?.should be_true
- Foo.new(:my_bool => true).my_bool?.should be_true
+ 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
end
it "should be comparable" do
- s1 = StructWithSomeEnum.new(:some_enum => SomeEnum::ONE)
- s2 = StructWithSomeEnum.new(:some_enum => SomeEnum::TWO)
+ 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 <=> StructWithSomeEnum.new()).should == -1
+ (s1 <=> SpecNamespace::StructWithSomeEnum.new()).should == -1
end
it "should read itself off the wire" do
- struct = Foo.new
- prot = BaseProtocol.new(mock("transport"))
+ 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(
- ['complex', Types::MAP, 5], # Foo
- ['words', Types::STRING, 2], # Foo
- ['hello', Types::STRUCT, 3], # Foo
- ['greeting', Types::STRING, 1], # Hello
- [nil, Types::STOP, 0], # Hello
- ['simple', Types::I32, 1], # Foo
- ['ints', Types::LIST, 4], # Foo
- ['shorts', Types::SET, 6], # Foo
- [nil, Types::STOP, 0] # Hello
+ ['complex', Thrift::Types::MAP, 5], # Foo
+ ['words', Thrift::Types::STRING, 2], # Foo
+ ['hello', Thrift::Types::STRUCT, 3], # Foo
+ ['greeting', Thrift::Types::STRING, 1], # Hello
+ [nil, Thrift::Types::STOP, 0], # Hello
+ ['simple', Thrift::Types::I32, 1], # Foo
+ ['ints', Thrift::Types::LIST, 4], # Foo
+ ['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(
- [Types::I32, Types::MAP, 2], # complex
- [Types::STRING, Types::DOUBLE, 2], # complex/1/value
- [Types::STRING, Types::DOUBLE, 1] # complex/2/value
+ [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([Types::I32, 4])
+ 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([Types::I16, 2])
+ 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(
1, 14, # complex keys
@@ -138,83 +136,83 @@ class ThriftStructSpec < Spec::ExampleGroup
struct.simple.should == 42
struct.complex.should == {1 => {"pi" => Math::PI, "e" => Math::E}, 14 => {"feigenbaum" => 4.669201609}}
- struct.hello.should == Hello.new(:greeting => "what's up?")
+ 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])
end
it "should serialize false boolean fields correctly" do
- b = BoolStruct.new(:yesno => false)
- prot = BinaryProtocol.new(MemoryBufferTransport.new)
+ b = SpecNamespace::BoolStruct.new(:yesno => false)
+ prot = Thrift::BinaryProtocol.new(Thrift::MemoryBufferTransport.new)
prot.should_receive(:write_bool).with(false)
b.write(prot)
end
it "should skip unexpected fields in structs and use default values" do
- struct = Foo.new
- prot = BaseProtocol.new(mock("transport"))
+ 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(
- ['simple', Types::I32, 1],
- ['complex', Types::STRUCT, 5],
- ['thinz', Types::MAP, 7],
- ['foobar', Types::I32, 3],
- ['words', Types::STRING, 2],
- [nil, Types::STOP, 0]
+ ['simple', Thrift::Types::I32, 1],
+ ['complex', Thrift::Types::STRUCT, 5],
+ ['thinz', Thrift::Types::MAP, 7],
+ ['foobar', Thrift::Types::I32, 3],
+ ['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(Types::STRUCT)
- prot.should_receive(:skip).with(Types::MAP)
- # prot.should_receive(:read_map_begin).and_return([Types::I32, Types::I32, 0])
+ prot.should_receive(:skip).with(Thrift::Types::STRUCT)
+ prot.should_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(Types::I32)
+ prot.should_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 == Hello.new(:greeting => 'hello, world!')
+ struct.hello.should == SpecNamespace::Hello.new(:greeting => 'hello, world!')
struct.ints.should == [1, 2, 2, 3]
struct.shorts.should == Set.new([5, 17, 239])
end
it "should write itself to the wire" do
- prot = BaseProtocol.new(mock("transport")) #mock("Protocol")
+ 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', Types::LIST, 4)
+ 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', Types::MAP, 5)
+ 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', Types::SET, 6)
+ 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', Types::I32, 1)
+ 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', Types::STRUCT, 3)
- prot.should_receive(:write_field_begin).with('greeting', Types::STRING, 1)
+ 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(Types::I32, Types::MAP, 1)
- prot.should_receive(:write_map_begin).with(Types::STRING, Types::DOUBLE, 1)
+ 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(Types::I32, 4)
+ prot.should_receive(:write_list_begin).with(Thrift::Types::I32, 4)
prot.should_receive(:write_list_end)
- prot.should_receive(:write_set_begin).with(Types::I16, 3)
+ prot.should_receive(:write_set_begin).with(Thrift::Types::I16, 3)
prot.should_receive(:write_set_end)
- struct = Foo.new
+ struct = SpecNamespace::Foo.new
struct.words = nil
struct.complex = {5 => {"foo" => 1.23}}
struct.write(prot)
@@ -222,48 +220,48 @@ class ThriftStructSpec < Spec::ExampleGroup
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 = Foo.new
+ struct = SpecNamespace::Foo.new
lambda { struct.send :write_container, nil, nil, {:type => "foo"} }.should 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 { Hello.new(:greeting => 3) }.should raise_error(TypeError, "Expected Types::STRING, received Fixnum for field greeting")
+ lambda { SpecNamespace::Hello.new(:greeting => 3) }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
ensure
Thrift.type_checking = false
end
- lambda { Hello.new(:greeting => 3) }.should_not raise_error(TypeError)
+ lambda { SpecNamespace::Hello.new(:greeting => 3) }.should_not raise_error(Thrift::TypeError)
end
it "should support optional type-checking in field accessors" do
Thrift.type_checking = true
begin
- hello = Hello.new
- lambda { hello.greeting = 3 }.should raise_error(TypeError, "Expected Types::STRING, received Fixnum for field greeting")
+ hello = SpecNamespace::Hello.new
+ lambda { hello.greeting = 3 }.should 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(TypeError)
+ lambda { hello.greeting = 3 }.should_not raise_error(Thrift::TypeError)
end
it "should raise an exception when unknown types are given to Thrift::Struct.new" do
- lambda { Hello.new(:fish => 'salmon') }.should raise_error(Exception, "Unknown key given to SpecNamespace::Hello.new: fish")
+ lambda { SpecNamespace::Hello.new(:fish => 'salmon') }.should raise_error(Exception, "Unknown key given to SpecNamespace::Hello.new: fish")
end
it "should support `raise Xception, 'message'` for Exception structs" do
begin
- raise Xception, "something happened"
+ raise SpecNamespace::Xception, "something happened"
rescue Thrift::Exception => e
e.message.should == "something happened"
e.code.should == 1
# ensure it gets serialized properly, this is the really important part
- prot = BaseProtocol.new(mock("trans"))
+ 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', Types::STRING, 1)#, "something happened")
+ 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', Types::I32, 2)#, 1)
+ 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
@@ -274,16 +272,16 @@ class ThriftStructSpec < Spec::ExampleGroup
it "should support the regular initializer for exception structs" do
begin
- raise Xception, :message => "something happened", :code => 5
+ raise SpecNamespace::Xception, :message => "something happened", :code => 5
rescue Thrift::Exception => e
e.message.should == "something happened"
e.code.should == 5
- prot = BaseProtocol.new(mock("trans"))
+ 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', Types::STRING, 1)
+ 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', Types::I32, 2)
+ 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
diff --git a/lib/rb/spec/types_spec.rb b/lib/rb/spec/types_spec.rb
index 47a3db112..b2c3a200d 100644
--- a/lib/rb/spec/types_spec.rb
+++ b/lib/rb/spec/types_spec.rb
@@ -17,10 +17,9 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftTypesSpec < Spec::ExampleGroup
- include Thrift
+describe Thrift::Types do
before(:each) do
Thrift.type_checking = true
@@ -30,87 +29,87 @@ class ThriftTypesSpec < Spec::ExampleGroup
Thrift.type_checking = false
end
- describe "Type checking" do
+ context 'type checking' do
it "should return the proper name for each type" do
- Thrift.type_name(Types::I16).should == "Types::I16"
- Thrift.type_name(Types::VOID).should == "Types::VOID"
- Thrift.type_name(Types::LIST).should == "Types::LIST"
+ 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
end
it "should check types properly" do
- # lambda { Thrift.check_type(nil, Types::STOP) }.should raise_error(TypeError)
- lambda { Thrift.check_type(3, {:type => Types::STOP}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::VOID}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(3, {:type => Types::VOID}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type(true, {:type => Types::BOOL}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(3, {:type => Types::BOOL}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type(42, {:type => Types::BYTE}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(42, {:type => Types::I16}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(42, {:type => Types::I32}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(42, {:type => Types::I64}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(3.14, {:type => Types::I32}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type(3.14, {:type => Types::DOUBLE}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(3, {:type => Types::DOUBLE}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type("3", {:type => Types::STRING}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(3, {:type => Types::STRING}, :foo) }.should raise_error(TypeError)
+ # 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)
hello = SpecNamespace::Hello.new
- lambda { Thrift.check_type(hello, {:type => Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type("foo", {:type => Types::STRUCT}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type({:foo => 1}, {:type => Types::MAP}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type([1], {:type => Types::MAP}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type([1], {:type => Types::LIST}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type({:foo => 1}, {:type => Types::LIST}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type(Set.new([1,2]), {:type => Types::SET}, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type([1,2], {:type => Types::SET}, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type({:foo => true}, {:type => Types::SET}, :foo) }.should raise_error(TypeError)
+ 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)
end
it "should error out if nil is passed and skip_types is false" do
- lambda { Thrift.check_type(nil, {:type => Types::BOOL}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::BYTE}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::I16}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::I32}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::I64}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::DOUBLE}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::STRING}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::STRUCT}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::LIST}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::SET}, :foo, false) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, {:type => Types::MAP}, :foo, false) }.should raise_error(TypeError)
+ 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)
end
it "should check element types on containers" do
- field = {:type => Types::LIST, :element => {:type => Types::I32}}
- lambda { Thrift.check_type([1, 2], field, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type([1, nil, 2], field, :foo) }.should raise_error(TypeError)
- field = {:type => Types::MAP, :key => {:type => Types::I32}, :value => {:type => Types::STRING}}
- lambda { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.should raise_error(TypeError)
- field = {:type => Types::SET, :element => {:type => Types::I32}}
- lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(TypeError)
- lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(TypeError)
- lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(TypeError)
-
- field = {:type => Types::STRUCT, :class => SpecNamespace::Hello}
- lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(TypeError)
+ 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)
+ 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)
+ 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)
+
+ field = {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}
+ lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(Thrift::TypeError)
end
- it "should give the TypeError a readable message" do
+ 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 => Types::STRING}, :foo) }.should raise_error(TypeError, msg)
+ lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError, msg)
msg = "Expected Types::STRING, received Fixnum for field foo.element"
- field = {:type => Types::LIST, :element => {:type => Types::STRING}}
- lambda { Thrift.check_type([3], field, :foo) }.should raise_error(TypeError, msg)
+ field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
+ lambda { Thrift.check_type([3], field, :foo) }.should raise_error(Thrift::TypeError, msg)
msg = "Expected Types::I32, received NilClass for field foo.element.key"
- field = {:type => Types::LIST,
- :element => {:type => Types::MAP,
- :key => {:type => Types::I32},
- :value => {:type => Types::I32}}}
- lambda { Thrift.check_type([{nil => 3}], field, :foo) }.should raise_error(TypeError, msg)
+ 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)
msg = "Expected Types::I32, received NilClass for field foo.element.value"
- lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should raise_error(TypeError, msg)
+ lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should 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 fad649cbc..db08cab71 100644
--- a/lib/rb/spec/union_spec.rb
+++ b/lib/rb/spec/union_spec.rb
@@ -17,21 +17,19 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
-class ThriftUnionSpec < Spec::ExampleGroup
- include Thrift
- include SpecNamespace
+describe 'Union' do
- describe Union do
+ describe Thrift::Union do
it "should return nil value in unset union" do
- union = My_union.new
+ union = SpecNamespace::My_union.new
union.get_set_field.should == nil
union.get_value.should == nil
end
it "should set a field and be accessible through get_value and the named field accessor" do
- union = My_union.new
+ union = SpecNamespace::My_union.new
union.integer32 = 25
union.get_set_field.should == :integer32
union.get_value.should == 25
@@ -39,30 +37,30 @@ class ThriftUnionSpec < Spec::ExampleGroup
end
it "should work correctly when instantiated with static field constructors" do
- union = My_union.integer32(5)
+ union = SpecNamespace::My_union.integer32(5)
union.get_set_field.should == :integer32
union.integer32.should == 5
end
it "should raise for wrong set field" do
- union = My_union.new
+ union = SpecNamespace::My_union.new
union.integer32 = 25
lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
end
-
+
it "should not be equal to nil" do
- union = My_union.new
+ union = SpecNamespace::My_union.new
union.should_not == nil
end
-
+
it "should not equate two different unions, i32 vs. string" do
- union = My_union.new(:integer32, 25)
- other_union = My_union.new(:some_characters, "blah!")
+ union = SpecNamespace::My_union.new(:integer32, 25)
+ other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
union.should_not == other_union
end
it "should properly reset setfield and setvalue" do
- union = My_union.new(:integer32, 25)
+ union = SpecNamespace::My_union.new(:integer32, 25)
union.get_set_field.should == :integer32
union.some_characters = "blah!"
union.get_set_field.should == :some_characters
@@ -71,24 +69,24 @@ class ThriftUnionSpec < Spec::ExampleGroup
end
it "should not equate two different unions with different values" do
- union = My_union.new(:integer32, 25)
- other_union = My_union.new(:integer32, 400)
+ union = SpecNamespace::My_union.new(:integer32, 25)
+ other_union = SpecNamespace::My_union.new(:integer32, 400)
union.should_not == other_union
end
it "should not equate two different unions with different fields" do
- union = My_union.new(:integer32, 25)
- other_union = My_union.new(:other_i32, 25)
+ union = SpecNamespace::My_union.new(:integer32, 25)
+ other_union = SpecNamespace::My_union.new(:other_i32, 25)
union.should_not == other_union
end
it "should inspect properly" do
- union = My_union.new(:integer32, 25)
+ union = SpecNamespace::My_union.new(:integer32, 25)
union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
end
it "should not allow setting with instance_variable_set" do
- union = My_union.new(:integer32, 27)
+ 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
@@ -99,42 +97,42 @@ class ThriftUnionSpec < Spec::ExampleGroup
trans = Thrift::MemoryBufferTransport.new
proto = Thrift::BinaryProtocol.new(trans)
- union = My_union.new(:integer32, 25)
+ union = SpecNamespace::My_union.new(:integer32, 25)
union.write(proto)
- other_union = My_union.new(:integer32, 25)
+ other_union = SpecNamespace::My_union.new(:integer32, 25)
other_union.read(proto)
other_union.should == union
end
it "should raise when validating unset union" do
- union = My_union.new
+ union = SpecNamespace::My_union.new
lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")
- other_union = My_union.new(:integer32, 1)
+ other_union = SpecNamespace::My_union.new(:integer32, 1)
lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
end
it "should validate an enum field properly" do
- union = TestUnion.new(:enum_field, 3)
+ union = SpecNamespace::TestUnion.new(:enum_field, 3)
union.get_set_field.should == :enum_field
- lambda { union.validate }.should raise_error(ProtocolException, "Invalid value of field enum_field!")
+ lambda { union.validate }.should raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
- other_union = TestUnion.new(:enum_field, 1)
- lambda { other_union.validate }.should_not raise_error(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!")
end
it "should properly serialize and match structs with a union" do
- union = My_union.new(:integer32, 26)
- swu = Struct_with_union.new(:fun_union => union)
+ union = SpecNamespace::My_union.new(:integer32, 26)
+ swu = SpecNamespace::Struct_with_union.new(:fun_union => union)
trans = Thrift::MemoryBufferTransport.new
proto = Thrift::CompactProtocol.new(trans)
swu.write(proto)
- other_union = My_union.new(:some_characters, "hello there")
- swu2 = Struct_with_union.new(:fun_union => other_union)
+ other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
+ swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
swu2.should_not == swu
@@ -143,30 +141,30 @@ class ThriftUnionSpec < Spec::ExampleGroup
end
it "should support old style constructor" do
- union = My_union.new(:integer32 => 26)
+ union = SpecNamespace::My_union.new(:integer32 => 26)
union.get_set_field.should == :integer32
union.get_value.should == 26
end
it "should not throw an error when inspected and unset" do
- lambda{TestUnion.new().inspect}.should_not raise_error
+ lambda{SpecNamespace::TestUnion.new().inspect}.should_not raise_error
end
it "should print enum value name when inspected" do
- My_union.new(:some_enum => SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
+ SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
- My_union.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
+ SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
end
it "should offer field? methods" do
- My_union.new.some_enum?.should be_false
- My_union.new(:some_enum => SomeEnum::ONE).some_enum?.should be_true
- My_union.new(:im_true => false).im_true?.should be_true
- My_union.new(:im_true => true).im_true?.should be_true
+ 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
end
it "should pretty print binary fields" do
- TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
+ SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
end
it "should be comparable" do
@@ -177,10 +175,10 @@ class ThriftUnionSpec < Spec::ExampleGroup
[1, 1, 1, 0]]
objs = [
- TestUnion.new(:string_field, "blah"),
- TestUnion.new(:string_field, "blahblah"),
- TestUnion.new(:i32_field, 1),
- TestUnion.new()]
+ SpecNamespace::TestUnion.new(:string_field, "blah"),
+ SpecNamespace::TestUnion.new(:string_field, "blahblah"),
+ SpecNamespace::TestUnion.new(:i32_field, 1),
+ SpecNamespace::TestUnion.new()]
for y in 0..3
for x in 0..3
diff --git a/lib/rb/spec/unix_socket_spec.rb b/lib/rb/spec/unix_socket_spec.rb
index 43818e0f2..cb6cff3f9 100644
--- a/lib/rb/spec/unix_socket_spec.rb
+++ b/lib/rb/spec/unix_socket_spec.rb
@@ -17,16 +17,15 @@
# under the License.
#
-require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
+require 'spec_helper'
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
-class ThriftUNIXSocketSpec < Spec::ExampleGroup
- include Thrift
+describe 'UNIXSocket' do
- describe UNIXSocket do
+ describe Thrift::UNIXSocket do
before(:each) do
@path = '/tmp/thrift_spec_socket'
- @socket = UNIXSocket.new(@path)
+ @socket = Thrift::UNIXSocket.new(@path)
@handle = mock("Handle", :closed? => false)
@handle.stub!(:close)
::UNIXSocket.stub!(:new).and_return(@handle)
@@ -41,14 +40,14 @@ class ThriftUNIXSocketSpec < Spec::ExampleGroup
it "should accept an optional timeout" do
::UNIXSocket.stub!(:new)
- UNIXSocket.new(@path, 5).timeout.should == 5
+ Thrift::UNIXSocket.new(@path, 5).timeout.should == 5
end
end
- describe UNIXServerSocket do
+ describe Thrift::UNIXServerSocket do
before(:each) do
@path = '/tmp/thrift_spec_socket'
- @socket = UNIXServerSocket.new(@path)
+ @socket = Thrift::UNIXServerSocket.new(@path)
end
it "should create a handle when calling listen" do
@@ -63,7 +62,7 @@ class ThriftUNIXSocketSpec < Spec::ExampleGroup
sock = mock("sock")
handle.should_receive(:accept).and_return(sock)
trans = mock("UNIXSocket")
- UNIXSocket.should_receive(:new).and_return(trans)
+ Thrift::UNIXSocket.should_receive(:new).and_return(trans)
trans.should_receive(:handle=).with(sock)
@socket.accept.should == trans
end
diff --git a/lib/rb/thrift.gemspec b/lib/rb/thrift.gemspec
index bc436dc8c..99856e8cb 100644
--- a/lib/rb/thrift.gemspec
+++ b/lib/rb/thrift.gemspec
@@ -27,8 +27,8 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib ext]
- s.add_development_dependency "rake"
- s.add_development_dependency "rspec", "1.3.2"
- s.add_development_dependency "mongrel"
+ s.add_development_dependency 'rake'
+ s.add_development_dependency 'rspec', '~> 2.11.0'
+ s.add_development_dependency 'mongrel', "1.2.0.pre2"
end