Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message compatibility for instance_eval filename argument #98

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/live_ast/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion test/full/replace_eval_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down