Skip to Content

Vim jump to request spec file

Posted on

One of my favorite vim plugin is tpope/vim-rails. There are a lot of usefull features for rails developer.

With :A feature of vim-rails, you can jump quickly from a model file to it’s model spec file, or jump from controller file to controller spec file. Howerver, since Rails 5.x, controller specs have fallend out. We use request specs now.

Unfortunately, vim-rails doesn’t know about request specs. Fortunately, we can teach it.

Add this configuration to .vimrc file:

let g:rails_projections = {
      \ "app/controllers/*_controller.rb": {
      \   "test": [
      \     "spec/controllers/{}_controller_spec.rb",
      \     "spec/requests/{}_spec.rb"
      \   ],
      \ },
      \ "spec/requests/*_spec.rb": {
      \   "alternate": [
      \     "app/controllers/{}_controller.rb",
      \   ],
      \ }}

Reference

comments powered by Disqus