rb: Don't type-check when given a nil value.
authorKevin Clark <kclark@apache.org>
Wed, 18 Jun 2008 01:18:14 +0000 (01:18 +0000)
committerKevin Clark <kclark@apache.org>
Wed, 18 Jun 2008 01:18:14 +0000 (01:18 +0000)
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

lib/rb/lib/thrift/types.rb
lib/rb/spec/spec_helper.rb
lib/rb/spec/types_spec.rb

index bc09195..d7d4cec 100644 (file)
@@ -26,7 +26,7 @@ module Thrift
   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
index 0d4a64e..874ed2d 100644 (file)
@@ -21,3 +21,9 @@ class Object
     self
   end
 end
+
+Spec::Runner.configure do |configuration|
+  configuration.before(:each) do
+    Thrift.type_checking = true
+  end
+end
index d40e492..8a739f7 100644 (file)
@@ -16,12 +16,13 @@ class ThriftTypesSpec < Spec::ExampleGroup
     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)