seattlerb/minitest — pull request #267 by floehopper (2013-04-12 16:37:26+00:00)
Title: Run a test by line number from the command line (a.k.a. "run focussed test")

This adds a `--line` command line option which is used to specify the
line number of the test you want to run.

Typical usage:-

$ ruby -Itest test/unit/foo_test.rb --line 43

The use case I have in mind is for text editors that want to implement
running the test near the current cursor position. This is sometimes
known as "run focussed test".

The file to which the line number refers is chosen fairly arbitrarily,
because it is assumed that the common usage will only involve loading
a single file. It would be possible to have a more sophisticated
implementation which added a `--file` option as well, but this is
overkill for what I need.

The test method is chosen by finding the first test method definition
*above* or at the supplied line number.

This solution will only work in Ruby 1.9 where
`Method#source_location` is available. There is currently no protection
against the situation where this functionality is not available, but it
would be simple to add.