rb: When passing unknown keys to Thrift::Struct.new, report those keys in the excepti...
authorKevin Clark <kclark@apache.org>
Tue, 24 Jun 2008 01:32:03 +0000 (01:32 +0000)
committerKevin Clark <kclark@apache.org>
Tue, 24 Jun 2008 01:32:03 +0000 (01:32 +0000)
Author: kevin@rapleaf.com

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@670989 13f79535-47bb-0310-9956-ffa450edef68

lib/rb/lib/thrift/struct.rb
lib/rb/spec/struct_spec.rb

index 2d29366..b016f13 100644 (file)
@@ -9,7 +9,7 @@ module Thrift
         Thrift.check_type(value, type)
         instance_variable_set("@#{name}", value)
       end
-      raise Exception, "Unknown arguments given to #{self.class}.new" unless d.empty?
+      raise Exception, "Unknown keys given to #{self.class}.new: #{d.keys.join(", ")}" unless d.empty?
     end
 
     def struct_fields
index 6ff9bdb..6dd2868 100644 (file)
@@ -196,7 +196,8 @@ class ThriftStructSpec < Spec::ExampleGroup
     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 arguments given to SpecNamespace::Hello.new")
+      lambda { Hello.new(:fish => 'salmon') }.should raise_error(Exception, "Unknown keys given to SpecNamespace::Hello.new: fish")
+      lambda { Hello.new(:foo => 'bar', :baz => 'blah', :greeting => 'Good day') }.should raise_error(Exception, /^Unknown keys given to SpecNamespace::Hello.new: (foo, baz|baz, foo)$/)
     end
   end
 end