Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

improved rails-test:run-current-method for shoulda

  • Loading branch information...
commit c5a8b9c6b016839b652351f7c8f625b931bbe333 1 parent 5689359
Remco van 't Veer authored July 28, 2011
20  rails-shoulda.el
@@ -23,15 +23,17 @@
23 23
 (defun rails-shoulda:current-test ()
24 24
   "Return the test name based on point"
25 25
   (save-excursion
26  
-    (ruby-end-of-block)
27  
-    (let* ((name-regex "\\(\\(:[a-z0-9_]+\\)\\|\\(\"\\([a-z0-9_ ]+\\)\"\\)\\)")
28  
-           (name-match (lambda () (or (match-string-no-properties 2) (match-string-no-properties 4))))
29  
-           (should (when (search-backward-regexp (concat "^[ \t]*should +" name-regex "[ \t]+do") nil t)
30  
-                     (funcall name-match)))
31  
-           (context (when (search-backward-regexp (concat "^[ \t]*context +" name-regex "[ \t]+do") nil t)
32  
-                      (funcall name-match))))
33  
-      (when (and should context)
34  
-        (concat context " should " should)))))
  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)))))))
35 37
 
36 38
 (defun rails-shoulda:current-context ()
37 39
   "Return the shoulda context name based on point"
9  rails-test.el
@@ -264,9 +264,14 @@ Used when it's determined that the output buffer needs to be shown."
264 264
         (method (rails-core:current-method-name))
265 265
         (description (or (rails-shoulda:current-test) (rails-test:active-support-test-case-current-test))))
266 266
     (cond (description
267  
-           (rails-test:run-single-file file (format "--name=/%s/" (replace-regexp-in-string "[^a-z0-9,-]" "." description))))
  267
+           (rails-test:run-single-file file
  268
+                                       (format "--name=/%s/"
  269
+                                               (replace-regexp-in-string "^\\.\\|\\.$" ""
  270
+                                                                         (replace-regexp-in-string "[^a-z0-9,-]+" "."
  271
+                                                                                                   description)))))
268 272
           (method
269  
-           (rails-test:run-single-file file (format "--name=%s" method))))))
  273
+           (rails-test:run-single-file file
  274
+                                       (format "--name=%s" method))))))
270 275
 
271 276
 ;; These functions were originally defined anonymously in ui. They are defined here so keys
272 277
 ;; can be added to them dryly

0 notes on commit c5a8b9c

Please sign in to comment.
Something went wrong with that request. Please try again.