diff --git a/lib/m/test_method.rb b/lib/m/test_method.rb index 0601072..d3035fd 100644 --- a/lib/m/test_method.rb +++ b/lib/m/test_method.rb @@ -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