diff --git a/lib/live_ast/common.rb b/lib/live_ast/common.rb index 094a92a..81a57c0 100644 --- a/lib/live_ast/common.rb +++ b/lib/live_ast/common.rb @@ -18,7 +18,12 @@ def arg_to_str2(arg) rescue NameError thing = arg&.class - message = "wrong argument type #{thing.inspect} (expected String)" + message = if arg.nil? + "wrong argument type #{thing.inspect} (expected String)" + else + "no implicit conversion of #{thing.inspect} into String" + end + raise TypeError, message end diff --git a/test/full/replace_eval_test.rb b/test/full/replace_eval_test.rb index 6dea861..669c921 100644 --- a/test/full/replace_eval_test.rb +++ b/test/full/replace_eval_test.rb @@ -172,7 +172,7 @@ def test_instance_eval_code_argument_type_error_no_block end end - def test_instance_eval_filename_argument_type_error_no_block + def test_instance_eval_filename_argument_nil_type_error_no_block orig = assert_raises TypeError do Object.new.live_ast_original_instance_eval("1", nil) end @@ -184,6 +184,18 @@ def test_instance_eval_filename_argument_type_error_no_block assert_equal orig.class, live.class end + def test_instance_eval_filename_argument_conversion_type_error_no_block + orig = assert_raises TypeError do + Object.new.live_ast_original_instance_eval("1", 23) + end + live = assert_raises TypeError do + Object.new.instance_eval("1", 23) + end + + assert_equal orig.message, live.message + assert_equal orig.class, live.class + end + def test_instance_eval_arity_error_with_block orig = assert_raises ArgumentError do Object.new.live_ast_original_instance_eval(3, 4, 5) { nil }