Skip to content

Commit

Permalink
Added support so that should assertion in focus will get run in the s…
Browse files Browse the repository at this point in the history
…ame manner as a test unit test.
  • Loading branch information
rwc9u committed May 7, 2008
1 parent afddcb6 commit 5f61572
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
48 changes: 48 additions & 0 deletions rails-shoulda.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
;;; rails-shoulda.el --- emacs-rails integraions with should plugin.

;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
;; Keywords: ruby rails languages oop


;;; License

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


(defun rails-shoulda:current-test ()
"Return the test name based on point"
(save-excursion
(ruby-end-of-block)
(let ((should (when (search-backward-regexp "^[ ]*should \"\\([a-z0-9_ ]+\\)\"[ ]*do" nil t)
(match-string-no-properties 1)))
(context (when (search-backward-regexp "^[ ]*context \"\\([a-z0-9_ ]+\\)\"[ ]*do" nil t)
(match-string-no-properties 1))))
(when (and should context)
(concat context " should " should)))))


(defun rails-shoulda:run-current-should ()
"Run should assertion based on the location of point."
(interactive)
(let ((file (substring (buffer-file-name) (length (rails-project:root))))
(method (replace-regexp-in-string "[\+\. \'\"\(\)]" "." (rails-shoulda:current-test))))
(when method
(rails-test:run-single-file file (format "--name=/%s/" method)))))




(provide 'rails-shoulda)
7 changes: 5 additions & 2 deletions rails-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ Used when it's determined that the output buffer needs to be shown."
"Run a test for the current method."
(interactive)
(let ((file (substring (buffer-file-name) (length (rails-project:root))))
(method (rails-core:current-method-name)))
(method (rails-core:current-method-name))
(shoulda-method (rails-shoulda:current-test)))
(when method
(rails-test:run-single-file file (format "--name=%s" method)))))
(rails-test:run-single-file file (format "--name=%s" method)))
(when shoulda-method
(rails-test:run-single-file file (format "--name=/%s/" (replace-regexp-in-string "[\+\. \'\"\(\)]" "." shoulda-method))))))

;; These functions were originally defined anonymously in ui. They are defined here so keys
;; can be added to them dryly
Expand Down

0 comments on commit 5f61572

Please sign in to comment.