@@ -2159,9 +2159,21 @@ function! s:BufFinderCommands()
21592159 if ! empty (tests)
21602160 call s: define_navcommand (' unittest' , {
21612161 \ ' pattern' : map (copy (tests), ' v:val[1]' ),
2162+ \ ' template' : {
2163+ \ ' test/unit/' : " require 'test_helper'\n\n class %STest < ActiveSupport::TestCase\n end" ,
2164+ \ ' test/models/' : " require 'test_helper'\n\n class %STest < ActiveSupport::TestCase\n end" ,
2165+ \ ' test/helpers/' : " require 'test_helper'\n\n class %STest < ActionView::TestCase\n end" ,
2166+ \ ' spec/models/' : " require 'spec_helper'\n\n describe %S do\n end" ,
2167+ \ ' spec/helpers/' : " require 'spec_helper'\n\n describe %S do\n end" },
21622168 \ ' affinity' : ' model' })
21632169 call s: define_navcommand (' functionaltest' , {
21642170 \ ' pattern' : map (copy (tests), ' v:val[2]' ),
2171+ \ ' template' : {
2172+ \ ' test/functional/' : " require 'test_helper'\n\n class %STest < ActionController::TestCase\n end" ,
2173+ \ ' test/controllers/' : " require 'test_helper'\n\n class %STest < ActionController::TestCase\n end" ,
2174+ \ ' test/mailers/' : " require 'test_helper'\n\n class %STest < ActionMailer::TestCase\n end" ,
2175+ \ ' spec/models/' : " require 'spec_helper'\n\n describe %S do\n end" ,
2176+ \ ' spec/helpers/' : " require 'spec_helper'\n\n describe %S do\n end" },
21652177 \ ' affinity' : ' controller' })
21662178 endif
21672179 let integration_tests = map (filter ([
@@ -2174,6 +2186,12 @@ function! s:BufFinderCommands()
21742186 if ! empty (integration_tests)
21752187 call s: define_navcommand (' integrationtest' , {
21762188 \ ' pattern' : integration_tests,
2189+ \ ' template' : {
2190+ \ ' test/integration/' : " require 'test_helper'\n\n class %STest < ActionDispatch::IntegrationTest\n end" ,
2191+ \ ' spec/requests/' : " require 'spec_helper'\n\n describe \" %h\" do\n end" ,
2192+ \ ' spec/integration/' : " require 'spec_helper'\n\n describe \" %h\" do\n end" ,
2193+ \ ' features/' : " Feature: %h" ,
2194+ \ ' spec/acceptance' : " Feature: %h" },
21772195 \ ' default' : [
21782196 \ ' test/test_helper.rb' ,
21792197 \ ' features/support/env.rb' ,
@@ -2911,10 +2929,15 @@ function! s:readable_open_command(cmd, argument, name, options) dict abort
29112929 if ! isdirectory (fnamemodify (file , ' :h' ))
29122930 call mkdir (fnamemodify (file , ' :h' ), ' p' )
29132931 endif
2914- let template = s: split (get (a: options , ' template' , ' ' ))
2932+ if type (get (a: options , ' template' , ' ' )) == type ({})
2933+ let template = s: split (get (a: options .template, prefix, ' ' ))
2934+ else
2935+ let template = s: split (get (a: options , ' template' , ' ' ))
2936+ endif
29152937 let placeholders = {
29162938 \ ' %s' : rails#underscore (root),
29172939 \ ' %S' : rails#camelize (root),
2940+ \ ' %h' : toupper (root[0 ]) . tr (rails#underscore (root), ' _' , ' ' )[1 :-1 ],
29182941 \ ' %%' : ' %' }
29192942 call map (template, ' substitute(v:val, "%.", "\\=get(placeholders, submatch(0), submatch(0))", "g")' )
29202943 call map (template, ' s:gsub(v:val, "\t", " ")' )
0 commit comments