Skip to content

Commit

Permalink
Merge pull request #98 from mvz/fix-string-arg-error-message
Browse files Browse the repository at this point in the history
Improve error message compatibility for instance_eval filename argument
  • Loading branch information
mvz authored Dec 28, 2023
2 parents 5840bbe + b3660aa commit 33418b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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

0 comments on commit 33418b7

Please sign in to comment.