I am a big big fan of vim, but I struggled with it when I was coding with multiple project in the same time.
The big pain was also when I need to see the diffs before committing.
So I moved to spacemacs (vim mode) several years ago and I am loving it.
I still use vim to edit some config files but the main code in on spacemacs.
Now, I am coding a lot of ruby mainly for rails projects and testing function included in the official
ruby layer are not adapted for a modern rails test with
rails now, when we call
bundle exec rails test the code will try to find the
spring process and call the tests inside.
spring process improve a lot the boot-up time of ruby and the loading of all your rails project by caching it.
In spacemacs, your cursor is within test method and you hit
space m t t, this will run only this test but he is calling your test by using
ruby ..... [your test file] and this will not leverage all the optimization done in the rake test command shipped in rails.
More dangerous, this will flush your
dev database and populate it with your test fixture.
bad bad .... very bad thing.
I have a terminal somewhere open, and when I need to run test, I switch to it and try to type the name of the test and line number of the test.
bundle exec rails test test/system/ ... / ... / ... / my_test_file_test.rb:123
I have written a small functions in
Elisp because I want learn & practice this powerful language.
Here is the code, can be improved but who cares, it's doing the job :D
(defun run-rails-test-file () (interactive) (let ((filename (ruby-test-find-file))) (compile (format "bundle exec rails test %s" filename)))) (defun run-rails-test-at-point () (interactive) (let* ((filename (ruby-test-find-file)) (buffername (get-file-buffer filename))) (with-current-buffer buffername (let ((line (line-number-at-pos (point)))) (compile (format "bundle exec rails test %s:%s" filename line)))) ) ) (spacemacs/set-leader-keys "mtt" 'run-rails-test-at-point) (spacemacs/set-leader-keys "mtT" 'run-rails-test-file)
ruby-test-find-file: this function will output the path of the current buffer if it's a test file and .... wait for it .... it will also return the last visited test file if you are in a none-test file.
This is very useful, imagine your current buffer is a test file, you run the test, it fails, so you switch to the actual file containing the code, you tweak it and you want to re-run the test, no need to switch again to the test file, this function will handle it for you.
I am reusing the functions defined in the
spacemacs ruby layer.
In Emacs, Everything is a function, and you can read the actual code of all of them.
In spacemacs, the BEST helper is
Space h d f and it will autocomplete the name of your function and show you the doc/code.
Let's try to understand what means
SPACE h d f and start type the name of the function.
Oh look to this this cutie, hit
And we can recursively search and learn more things at each key's hit.
Hope you have learned something new and maybe this will help you with your rails workflow on this incredible piece of software Emacs !
Most people want to make things perfect. Sometimes we evaluate the complexity of an upcoming goal or a problem. So, the fear to not complete it perfectly or "wrong" (Yeah, who are judges? 🤔) stops us even from trying.