You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2012/09/28 03:59:05 UTC
svn commit: r1391280 [2/2] - in /thrift/trunk/lib/rb: ./ spec/
Modified: thrift/trunk/lib/rb/spec/server_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/server_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/server_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/server_spec.rb Fri Sep 28 01:59:04 2012
@@ -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::ExampleGr
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::ExampleGr
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::ExampleGr
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)
Modified: thrift/trunk/lib/rb/spec/socket_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/socket_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/socket_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/socket_spec.rb Fri Sep 28 01:59:04 2012
@@ -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::ExampleGr
::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
Modified: thrift/trunk/lib/rb/spec/socket_spec_shared.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/socket_spec_shared.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/socket_spec_shared.rb (original)
+++ thrift/trunk/lib/rb/spec/socket_spec_shared.rb Fri Sep 28 01:59:04 2012
@@ -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
Modified: thrift/trunk/lib/rb/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/spec_helper.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/spec_helper.rb (original)
+++ thrift/trunk/lib/rb/spec/spec_helper.rb Fri Sep 28 01:59:04 2012
@@ -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
# 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'
Modified: thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb Fri Sep 28 01:59:04 2012
@@ -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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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
Modified: thrift/trunk/lib/rb/spec/struct_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/struct_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/struct_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/struct_spec.rb Fri Sep 28 01:59:04 2012
@@ -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::ExampleGr
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::ExampleGr
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::ExampleGr
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::ExampleGr
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::ExampleGr
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
Modified: thrift/trunk/lib/rb/spec/types_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/types_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/types_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/types_spec.rb Fri Sep 28 01:59:04 2012
@@ -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::ExampleGro
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
Modified: thrift/trunk/lib/rb/spec/union_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/union_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/union_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/union_spec.rb Fri Sep 28 01:59:04 2012
@@ -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::ExampleGro
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::ExampleGro
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::ExampleGro
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::ExampleGro
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::ExampleGro
[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
Modified: thrift/trunk/lib/rb/spec/unix_socket_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/unix_socket_spec.rb?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/unix_socket_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/unix_socket_spec.rb Fri Sep 28 01:59:04 2012
@@ -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::Examp
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::Examp
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
Modified: thrift/trunk/lib/rb/thrift.gemspec
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/thrift.gemspec?rev=1391280&r1=1391279&r2=1391280&view=diff
==============================================================================
--- thrift/trunk/lib/rb/thrift.gemspec (original)
+++ thrift/trunk/lib/rb/thrift.gemspec Fri Sep 28 01:59:04 2012
@@ -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