aboutsummaryrefslogtreecommitdiff
path: root/ruby/tests/basic.rb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-02-11 12:41:34 -0800
committerJoshua Haberman <jhaberman@gmail.com>2016-02-11 12:41:34 -0800
commitcaf1fb7197ee94c07108fc7cfbca07432b185a28 (patch)
tree83c11422b63312e782bfa722ea774b0b15b33017 /ruby/tests/basic.rb
parente088c2cf4b8f1bde0ce39d989d13ab48c3c05480 (diff)
parent3a5f213cca8dc7a541bd4fe63ea61c7634e44d5a (diff)
downloadprotobuf-caf1fb7197ee94c07108fc7cfbca07432b185a28.tar.gz
protobuf-caf1fb7197ee94c07108fc7cfbca07432b185a28.tar.bz2
protobuf-caf1fb7197ee94c07108fc7cfbca07432b185a28.zip
Merge pull request #997 from anderscarling/better_errors
ruby: Better exception text for common cases
Diffstat (limited to 'ruby/tests/basic.rb')
-rw-r--r--ruby/tests/basic.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb
index 40c20078..da85520f 100644
--- a/ruby/tests/basic.rb
+++ b/ruby/tests/basic.rb
@@ -191,6 +191,35 @@ module BasicTest
assert m1.hash != m2.hash
end
+ def test_unknown_field_errors
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello = "world"
+ end
+ assert_match(/hello/, e.message)
+ end
+
+ def test_initialization_map_errors
+ e = assert_raise ArgumentError do
+ TestMessage.new(:hello => "world")
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise ArgumentError do
+ MapMessage.new(:map_string_int32 => "hello")
+ end
+ assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
+
+ e = assert_raise ArgumentError do
+ TestMessage.new(:repeated_uint32 => "hello")
+ end
+ assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
+ end
+
def test_type_errors
m = TestMessage.new
assert_raise TypeError do