From 1ce8b3d7d502cff253b1ac761d2326763f144101 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Tue, 24 Jun 2008 01:32:03 +0000 Subject: [PATCH] rb: When passing unknown keys to Thrift::Struct.new, report those keys in the exception [THRIFT-51] 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 | 2 +- lib/rb/spec/struct_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb index 2d293664..b016f136 100644 --- a/lib/rb/lib/thrift/struct.rb +++ b/lib/rb/lib/thrift/struct.rb @@ -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 diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb index 6ff9bdbf..6dd28682 100644 --- a/lib/rb/spec/struct_spec.rb +++ b/lib/rb/spec/struct_spec.rb @@ -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 -- 2.17.1