Skip to content
Open
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
10 changes: 5 additions & 5 deletions lib/m/test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def self.create suite_class, test_method
# look up the ruby Method instance for it
method = suite_class.instance_method test_method

# Ruby can find the starting line for us, so pull that out of the array
start_line = method.source_location.last
# Ruby can find the starting line for us, so pull that out of the array.
# Ruby 3.5+ can also provide the ending line.
start_line, end_line = method.source_location.values_at(1, 3)

# Ruby can't find the end line however, and I'm too lazy to write
# Ruby < 3.5 can't find the end line however, and I'm too lazy to write
# a parser. Instead, `method_source` adds `Method#source` so we can
# deduce this ourselves.
#
# The end line should be the number of line breaks in the method source,
# added to the starting line and subtracted by one.

end_line = method.source.split("\n").size + start_line - 1
end_line ||= method.source.split("\n").size + start_line - 1

# Shove the given attributes into a new databag
new test_method, start_line, end_line
Expand Down