4

While it is easy to run the whole test suite with projectile-rails, this takes too much time. I'd like to be able to run the current test (i.e., the test point is located in) with a shortcut. Is this possible?

3

Assuming rspec:

Install rspec-mode, which will activate itself automatically in ruby-mode or enh-ruby-mode then you can use C-c,s to run rspec-verify-single which will run the test at point.

  • Is there something similiar for ActionController::TestCase? – ckruse Dec 5 '14 at 7:57
  • I do not know but writing your own wouldn't be hard, from what I see all you need to do is write code that gets the name of the test at point. then do something like this: (let ((default-directory (get-project-root-from-projectile))) (compile (format "rake test %s %s" (expand-file-name (buffer-file-name)) (get-your-test-name)))) – Jordon Biondo Dec 6 '14 at 2:46
1

This way it works:

(defun get-current-test-name ()
  (save-excursion
    (let ((pos)
          (test-name))
      (re-search-backward "test \"\\([^\"]+\\)\" do")
      (setq test-name (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
      (concat "test_" (replace-regexp-in-string " " "_" test-name)))))


(defun run-test-at-point ()
  (interactive)
  (let ((root-dir (projectile-project-root)))
    (compile (format "ruby -Ilib:test -I%s/test %s -n %s" root-dir (expand-file-name (buffer-file-name)) (get-current-test-name)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.