Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Created June 3, 2011 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diasjorge/1006410 to your computer and use it in GitHub Desktop.
Save diasjorge/1006410 to your computer and use it in GitHub Desktop.
diff --git a/rinari.el b/rinari.el
index f74494b..febdd5f 100644
--- a/rinari.el
+++ b/rinari.el
@@ -195,10 +195,15 @@ argument allows editing of the test command arguments."
(or (string-match "test" (or (ruby-add-log-current-method)
(file-name-nondirectory (buffer-file-name))))
(rinari-find-test))
- (let* ((funname (ruby-add-log-current-method))
+ (let* ((funname (rinari-test-function-name))
(fn (and funname
- (string-match "#\\(.*\\)" funname)
- (match-string 1 funname)))
+ (or
+ (and (string-match "#\\(.*\\)" funname)
+ (and (not (string-equal (match-string 1 funname) "setup"))
+ (match-string 1 funname)))
+ (and (string-match "[\"']\\(.*\\)[\"']" funname)
+ (replace-regexp-in-string "[ ]+" "_"
+ (match-string 1 funname))))))
(path (buffer-file-name))
(ruby-options (list "-I" (expand-file-name "test" (rinari-root)) path))
(default-command (mapconcat
@@ -211,6 +216,19 @@ argument allows editing of the test command arguments."
(if path (ruby-compilation-run command ruby-options)
(message "no test available"))))
+(defun rinari-test-function-name()
+ (let (funname str)
+ (progn
+ (setq str (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position)))
+ (if (string-match
+ (concat "^[ \t]*test[ \t]+"
+ "\\([\"'].*[\"']\\)"
+ "[ \t]*do" )
+ str)
+ (setq funname (match-string 1 str))
+ (setq funname (ruby-add-log-current-method))))))
+
(defun rinari-console (&optional edit-cmd-args)
"Runs a Rails console in a compilation buffer, with command history
and links between errors and source code. With optional prefix
@@ -270,11 +288,11 @@ from your conf/database.sql file."
(server (or (cdr (assoc "host" database-alist)) "localhost"))
(port (cdr (assoc "port" database-alist)))
(sql-server (if port (concat server ":" port) server)))
- (cond ((string-match "mysql" adapter)
+ (cond ((string-match "mysql" adapter)
(setf adapter "mysql"))
- ((string-match "sqlite" adapter)
+ ((string-match "sqlite" adapter)
(setf adapter "sqlite"))
- ((string-match "postgresql" adapter)
+ ((string-match "postgresql" adapter)
(setf adapter "postgres")))
(eval (list (intern (concat "sql-" adapter))))
(rename-buffer (sql-name environment)) (rinari-launch))))))
@purcell
Copy link

purcell commented Jun 9, 2011

Hi Jorge - can you try out this alternate formulation please? - https://gist.github.com/1017754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment