diff options
author | Florian Frank <flori@ping.de> | 2013-02-20 23:47:56 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2013-02-21 00:16:55 +0100 |
commit | 22da7f38a2670a9afbd2352c7265697c5db8afb4 (patch) | |
tree | ea4926b64a904d1305332daf263ffdf4a68012a7 /tests | |
parent | be7320fe65ddb20998fa0d7bccfcddcbc7cb09b9 (diff) | |
download | json-22da7f38a2670a9afbd2352c7265697c5db8afb4.tar.gz |
Try to convert first with to_hash, then to_h
rb_convert_type doesn't return if conversion fails, so use
rb_check_convert_type and the raise vi rb_convert_type. Make sure, that
this behaviour is consisten across all generator implementations.
Fixes https://github.com/flori/json/issues/162
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_json_generate.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb index 978c625..ab3c74c 100755 --- a/tests/test_json_generate.rb +++ b/tests/test_json_generate.rb @@ -251,6 +251,22 @@ EOT assert_equal '5', state2.array_nl end + def test_configure_hash_conversion + state = JSON.state.new + state.configure(:indent => '1') + assert_equal '1', state.indent + state = JSON.state.new + foo = 'foo' + assert_raise(TypeError) do + state.configure(foo) + end + def foo.to_h + { :indent => '2' } + end + state.configure(foo) + assert_equal '2', state.indent + end + if defined?(JSON::Ext::Generator) def test_broken_bignum # [ruby-core:38867] pid = fork do |