From: Kevin Clark Date: Wed, 18 Jun 2008 01:18:14 +0000 (+0000) Subject: rb: Don't type-check when given a nil value. X-Git-Tag: 0.2.0~535 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=c3783f4cdb94cb5ee28df8026e1bc4fa6b8ce3a0;p=common%2Fthrift.git 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 bc091957..d7d4cec8 100644 --- a/lib/rb/lib/thrift/types.rb +++ b/lib/rb/lib/thrift/types.rb @@ -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 diff --git a/lib/rb/spec/spec_helper.rb b/lib/rb/spec/spec_helper.rb index 0d4a64e3..874ed2d1 100644 --- a/lib/rb/spec/spec_helper.rb +++ b/lib/rb/spec/spec_helper.rb @@ -21,3 +21,9 @@ class Object 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 d40e492b..8a739f76 100644 --- a/lib/rb/spec/types_spec.rb +++ b/lib/rb/spec/types_spec.rb @@ -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)