Created
June 9, 2011 21:08
-
-
Save purcell/1017754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun rinari-test (&optional edit-cmd-args) | |
"Test the current ruby function. If current function is not a | |
test, then try to jump to the related test using | |
`rinari-find-test'. Dump output to a compilation buffer allowing | |
jumping between errors and source code. With optional prefix | |
argument allows editing of the test command arguments." | |
(interactive "P") | |
(or (string-match "test" (or (ruby-add-log-current-method) | |
(file-name-nondirectory (buffer-file-name)))) | |
(rinari-find-test)) | |
(let* ((fn (rinari-test-function-name)) | |
(path (buffer-file-name)) | |
(ruby-options (list "-I" (expand-file-name "test" (rinari-root)) path)) | |
(default-command (mapconcat | |
'identity | |
(append (list path) (if fn (list "--name" (concat "/" fn "/")))) | |
" ")) | |
(command (if edit-cmd-args | |
(read-string "Run w/Compilation: " default-command) | |
default-command))) | |
(if path (ruby-compilation-run command ruby-options) | |
(message "no test available")))) | |
(defun rinari-test-function-name() | |
(save-excursion | |
(if (re-search-backward (concat "^[ \t]*\\(def\\|test\\)[ \t]+" | |
"\\([\"'].*?[\"']\\|" ruby-symbol-re "*\\)" | |
"[ \t]*") nil t) | |
(let ((name (match-string 2))) | |
(if (string-match "^[\"']\\(.*\\)[\"']$" name) | |
(replace-regexp-in-string " +" "_" (match-string 1 name)) | |
(unless (string-equal "setup" name) | |
name)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment