Skip to content

Instantly share code, notes, and snippets.

@knu
Created March 8, 2018 09:15
Show Gist options
  • Save knu/b123aaffd2203f843a49206a7ee157e0 to your computer and use it in GitHub Desktop.
Save knu/b123aaffd2203f843a49206a7ee157e0 to your computer and use it in GitHub Desktop.
Teach the request spec file name convention to rspec-mode
(defadvice rspec-spec-file-for (around request-spec-support (a-file-name) activate)
(let ((file ad-do-it))
(setq ad-return-value
(cond ((file-exists-p file)
file)
((string-match "\\`\\(.*/spec/\\)controllers\\(/.+\\)_controller\\(_spec\\.rb\\)\\'" file)
(concat (match-string 1 file)
"requests"
(match-string 2 file)
(match-string 3 file)))
(t
file)))))
(defadvice rspec-target-file-for (around request-spec-support (a-spec-file-name) activate)
(cond ((string-match "\\`\\(.*/spec/\\)requests\\(/.+\\)\\(_spec\\.rb\\)\\'" a-spec-file-name)
(ad-set-arg 0
(concat (match-string 1 a-spec-file-name)
"controllers"
(match-string 2 a-spec-file-name)
"_controller"
(match-string 3 a-spec-file-name)))))
ad-do-it)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment