Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support so that should assertion in focus will get run in the s…

…ame manner as a test unit test.
  • Loading branch information...
commit 5f615728861c0a1234f8f54078a1404ad0d47023 1 parent afddcb6
@rwc9u rwc9u authored
Showing with 53 additions and 2 deletions.
  1. +48 −0 rails-shoulda.el
  2. +5 −2 rails-test.el
View
48 rails-shoulda.el
@@ -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)
View
7 rails-test.el
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.