Created
July 7, 2023 18:30
-
-
Save mscoutermarsh/4cde2d57daff183490927efb6f6f2fc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assert_equal(*args) | |
call_path = caller_locations(1, 1).first.path | |
call_line = caller_locations(1, 1).first.lineno | |
magic_enabled = args.length == 1 | |
if magic_enabled | |
expected_value = args.first | |
if expected_value.is_a?(String) || expected_value.is_a?(Symbol) || expected_value.is_a?(Numeric) | |
formatted_value = format_value(expected_value) | |
# Edit the file at call_path and call_line. Finish the test | |
file = File.read(call_path).lines | |
modified_line = file[call_line - 1].gsub("assert_equal ", "assert_equal #{formatted_value}, ") | |
modified_line = modified_line.gsub("assert_equal(", "assert_equal(#{formatted_value}, " ) | |
file[call_line - 1] = modified_line | |
modified_file = file.join | |
File.write(call_path, modified_file) | |
super(expected_value, args.first) | |
end | |
else | |
super(*args) | |
end | |
end | |
def format_value(value) | |
if value.is_a?(String) | |
"\"#{value}\"" | |
else | |
value.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment