rb: Don't type-check when given a nil value.
Turn on type-checking for all specs
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669016 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/types.rb b/lib/rb/lib/thrift/types.rb
index bc09195..d7d4cec 100644
--- a/lib/rb/lib/thrift/types.rb
+++ b/lib/rb/lib/thrift/types.rb
@@ -26,7 +26,7 @@
end
def self.check_type(value, type)
- return unless Thrift.type_checking
+ return unless Thrift.type_checking and not value.nil?
klasses = case type
when Types::VOID
NilClass
diff --git a/lib/rb/spec/spec_helper.rb b/lib/rb/spec/spec_helper.rb
index 0d4a64e..874ed2d 100644
--- a/lib/rb/spec/spec_helper.rb
+++ b/lib/rb/spec/spec_helper.rb
@@ -21,3 +21,9 @@
self
end
end
+
+Spec::Runner.configure do |configuration|
+ configuration.before(:each) do
+ Thrift.type_checking = true
+ end
+end
diff --git a/lib/rb/spec/types_spec.rb b/lib/rb/spec/types_spec.rb
index d40e492..8a739f7 100644
--- a/lib/rb/spec/types_spec.rb
+++ b/lib/rb/spec/types_spec.rb
@@ -16,12 +16,13 @@
it "should check types properly" do
Thrift.type_checking = true
begin
- lambda { Thrift.check_type(nil, Types::STOP) }.should raise_error(TypeError)
+ # lambda { Thrift.check_type(nil, Types::STOP) }.should raise_error(TypeError)
+ lambda { Thrift.check_type(3, Types::STOP) }.should raise_error(TypeError)
lambda { Thrift.check_type(nil, Types::VOID) }.should_not raise_error(TypeError)
lambda { Thrift.check_type(3, Types::VOID) }.should raise_error(TypeError)
lambda { Thrift.check_type(true, Types::BOOL) }.should_not raise_error(TypeError)
lambda { Thrift.check_type(3, Types::BOOL) }.should raise_error(TypeError)
- lambda { Thrift.check_type(nil, Types::BOOL) }.should raise_error(TypeError)
+ # lambda { Thrift.check_type(nil, Types::BOOL) }.should raise_error(TypeError)
lambda { Thrift.check_type(42, Types::BYTE) }.should_not raise_error(TypeError)
lambda { Thrift.check_type(42, Types::I16) }.should_not raise_error(TypeError)
lambda { Thrift.check_type(42, Types::I32) }.should_not raise_error(TypeError)