Skip to content

Commit

Permalink
Extract minitest--post-command
Browse files Browse the repository at this point in the history
Extracts a function, minitest-post-command that generates the
post_command string passed to the minitest -n flag.
  • Loading branch information
Jake Romer committed Jun 25, 2016
1 parent 2379c33 commit 6351c68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions minitest.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ The current directory is assumed to be the project's root otherwise."
(if (minitest--extract-str)
(let* ((cmd (match-string 1))
(str (match-string 2))
(post_command (cond ((equal "test" cmd) (format "test_%s" (replace-regexp-in-string "[\s#:]" "_" str)))
((equal "it" cmd) str))))
(post_command (minitest--post-command cmd str)))
(minitest--file-command (minitest--test-name-flag post_command)))
(error "No test found. Make sure you are on a file that has `def test_foo` or `test \"foo\"`")))

(defun minitest--post-command (cmd str)
(format "test_%s" (replace-regexp-in-string "[\s#:]" "_" str)))

(defun minitest-rerun ()
"Run the last command"
(interactive)
Expand Down
6 changes: 6 additions & 0 deletions test/minitest-unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
(minitest--extract-str)
(should (equal (match-string 2) "hello"))))

(ert-deftest test-minitest--post-command ()
(defvar test-description "#method_name behavior of Module::Class")
(defvar method-name "test__method_name_behavior_of_Module__Class")
(should (equal method-name (minitest--post-command "test" test-description)))
(should (equal method-name (minitest--post-command "it" test-description))))

(ert-deftest test-minitest-test-extract-str-with-block ()
(with-temp-buffer
(insert "test \"hello\" do\nend")
Expand Down

0 comments on commit 6351c68

Please sign in to comment.