Use rspec-mode to run Ruby tests

This commit is contained in:
Jeremy Dormitzer 2024-09-05 06:18:36 -06:00
parent 1823e4bcf6
commit ad1ba5f7fa

View File

@ -12,41 +12,21 @@
("Guardfile\\'" . ruby-mode)
("Capfile\\'" . ruby-mode)
("Vagrantfile\\'" . ruby-mode))
:hook (ruby-mode . highlight-indent-guides-mode)
:config
(defun toggle-spec-file ()
"Find the spec file for the current non-spec buffer or the file under test for the current spec buffer."
(interactive)
(let* ((dir (if-let ((proj (project-current)))
(project-root proj)
default-directory))
(ext (file-name-extension (buffer-file-name)))
(filename-base (file-name-base (buffer-file-name)))
(spec? (s-ends-with? "_spec" filename-base))
(rx (if spec?
(format "%s.%s$" (s-chop-suffix "_spec" filename-base) ext)
(format "%s_spec.%s$" filename-base ext)))
(candidates (directory-files-recursively dir rx)))
(cond ((= (length candidates) 0)
(message "No matching file found"))
((= (length candidates) 1)
(find-file (car candidates)))
(t
(let ((choice (consult--read candidates
:prompt "Find file: "
:category 'file)))
(find-file choice))))))
:general
(ruby-mode-map "C-c C-t" #'toggle-spec-file))
:hook (ruby-mode . highlight-indent-guides-mode))
(use-package inf-ruby
:commands (inf-ruby inf-ruby-console-auto)
:general
([remap inf-ruby] #'inf-ruby-console-auto))
([remap inf-ruby] #'inf-ruby-console-auto)
:hook (after-init . inf-ruby-switch-setup))
(use-package rbenv
:hook (after-init . global-rbenv-mode)
:custom
(rbenv-show-active-ruby-in-modeline nil))
(use-package rspec-mode
:custom
(rspec-use-opts-file-when-available nil))
(provide 'init-ruby)