Skip to content

Commit

Permalink
Feature: verify-single with line number when minitest-use-rails is t
Browse files Browse the repository at this point in the history
minitest-verify-single calls a new function minitest--verify-single-rails when
the minitest-use-rails custom variable is true. this will pass the line number
of the line the point is on to the bin/rails test command. rails version 5 and
above has functionality to run the test for the given line number that is not
built into minitest.

this should solve several issues for rails + minitest users.
  • Loading branch information
gcentauri committed Feb 21, 2020
1 parent de1c0b8 commit a336851
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions minitest.el
Expand Up @@ -35,12 +35,13 @@
:group 'minitest)

(defcustom minitest-use-rails nil
"Use `bin/rails test' as the default runner"
"Use `bin/rails test' as the default runner.
This is intended for use with Rails versions 5+."
:type 'boolean
:group 'minitest)

(defcustom minitest-use-docker nil
"Execute test command inside `minitest-docker-container' with `minitest-docker-command`'"
"Execute test command inside `minitest-docker-container' with `minitest-docker-command'"
:type 'boolean
:group 'minitest)

Expand Down Expand Up @@ -159,6 +160,18 @@ Returns a (CMD . NAME) pair or nil."
(minitest--match-point (nth closest minitest--test-regexps))
`(,(match-string 1) . ,(match-string 2))))))

(defun minitest--verify-single-with-regex ()
(let ((test (minitest--extract-test)))
(if test
(minitest--file-command (minitest--test-name-flag (minitest--post-command test)))
(error "No test found. Make sure you are on a file that has `def test_foo` or `test \"foo\"`"))))

(defun minitest--verify-single-rails ()
"Runs `bin/rails test path/to/test_file.rb:NN' with the current line number."
(let ((line-number (line-number-at-pos (point)))
(file-name (file-relative-name (buffer-file-name) (minitest-project-root))))
(minitest-run-file (format "%s:%s" file-name line-number))))

(defun minitest-verify-all ()
"Run all tests."
(interactive)
Expand All @@ -176,10 +189,8 @@ Returns a (CMD . NAME) pair or nil."
(defun minitest-verify-single ()
"Run the test closest to the cursor, searching backwards."
(interactive)
(let ((test (minitest--extract-test)))
(if test
(minitest--file-command (minitest--test-name-flag (minitest--post-command test)))
(error "No test found. Make sure you are on a file that has `def test_foo` or `test \"foo\"`"))))
(if minitest-use-rails (minitest--verify-single-rails)
(minitest--verify-with-regex)))

(defun minitest--post-command (test)
(let ((name (cdr test)))
Expand Down

0 comments on commit a336851

Please sign in to comment.