| 1 |
;;; rails-shoulda.el --- emacs-rails integraions with should plugin. |
| 2 |
|
| 3 |
;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com> |
| 4 |
;; Authors: Rob Christie <robchristie at gmail dot com>, |
| 5 |
;; Keywords: ruby rails languages oop |
| 6 |
|
| 7 |
;;; License |
| 8 |
|
| 9 |
;; This program is free software; you can redistribute it and/or |
| 10 |
;; modify it under the terms of the GNU General Public License |
| 11 |
;; as published by the Free Software Foundation; either version 2 |
| 12 |
;; of the License, or (at your option) any later version. |
| 13 |
|
| 14 |
;; This program is distributed in the hope that it will be useful, |
| 15 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
;; GNU General Public License for more details. |
| 18 |
|
| 19 |
;; You should have received a copy of the GNU General Public License |
| 20 |
;; along with this program; if not, write to the Free Software |
| 21 |
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 |
|
| 23 |
(defun rails-shoulda:current-test () |
| 24 |
"Return the test name based on point" |
| 25 |
(save-excursion |
| 26 |
(end-of-line) |
| 27 |
(let ((context-re "[ \t]context \\(:[a-z0-9_]+\\|\"[a-z0-9_ ]+\"\\|'[a-z0-9_ ]+\\)[ \t]+do")) |
| 28 |
(when (search-backward-regexp "^[ \t]*\\(context\\|should\\)" nil t) |
| 29 |
(if (string= "context" (match-string-no-properties 1)) |
| 30 |
(and (search-forward-regexp context-re nil t) |
| 31 |
(match-string-no-properties 1)) |
| 32 |
(let* ((should (and (search-forward-regexp "[ \t]\\(should.*?\\)\\([ \t]+do\\)?[ \t]*$" nil t) |
| 33 |
(match-string-no-properties 1))) |
| 34 |
(context (and (search-backward-regexp context-re nil t) |
| 35 |
(match-string-no-properties 1)))) |
| 36 |
(concat context " " should))))))) |
| 37 |
|
| 38 |
(defun rails-shoulda:current-context () |
| 39 |
"Return the shoulda context name based on point" |
| 40 |
(save-excursion |
| 41 |
(ruby-end-of-block) |
| 42 |
(when (search-backward-regexp "^[ ]*context \"\\([a-z0-9_ ]+\\)\"[ ]*do" nil t) |
| 43 |
(match-string-no-properties 1)))) |
| 44 |
|
| 45 |
(defun rails-shoulda:run-current-should () |
| 46 |
"Run should assertion based on the location of point." |
| 47 |
(interactive) |
| 48 |
(let ((file (substring (buffer-file-name) (length (rails-project:root)))) |
| 49 |
(method (replace-regexp-in-string "[\+\. \'\"\(\)]" "." (rails-shoulda:current-test)))) |
| 50 |
(when method |
| 51 |
(rails-test:run-single-file file (format "--name=/%s/" method))))) |
| 52 |
|
| 53 |
(defun rails-shoulda:run-current-context () |
| 54 |
"Run tests associated with the context based on the location of point." |
| 55 |
(interactive) |
| 56 |
(let ((file (substring (buffer-file-name) (length (rails-project:root)))) |
| 57 |
(method (replace-regexp-in-string "[\+\. \'\"\(\)]" "." (rails-shoulda:current-context)))) |
| 58 |
(when method |
| 59 |
(rails-test:run-single-file file (format "--name=/%s/" method))))) |
| 60 |
|
| 61 |
(provide 'rails-shoulda) |