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
diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb
index 2d29366..b016f13 100644
--- a/lib/rb/lib/thrift/struct.rb
+++ b/lib/rb/lib/thrift/struct.rb
@@ -9,7 +9,7 @@
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 6ff9bdb..6dd2868 100644
--- a/lib/rb/spec/struct_spec.rb
+++ b/lib/rb/spec/struct_spec.rb
@@ -196,7 +196,8 @@
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