Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Forked from purcell/rinari.el
Created June 10, 2011 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diasjorge/1018806 to your computer and use it in GitHub Desktop.
Save diasjorge/1018806 to your computer and use it in GitHub Desktop.
(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)))
(message command)
(if path (ruby-compilation-run command ruby-options)
(message "no test available"))))
(defun rinari-test-function-name()
(save-excursion
(end-of-line)
(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