Skip to content

Commit 293e0b1

Browse files
committed
Add templates for test navigation commands
1 parent 61906aa commit 293e0b1

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

autoload/rails.vim

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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\nclass %STest < ActiveSupport::TestCase\nend",
2164+
\ 'test/models/': "require 'test_helper'\n\nclass %STest < ActiveSupport::TestCase\nend",
2165+
\ 'test/helpers/': "require 'test_helper'\n\nclass %STest < ActionView::TestCase\nend",
2166+
\ 'spec/models/': "require 'spec_helper'\n\ndescribe %S do\nend",
2167+
\ 'spec/helpers/': "require 'spec_helper'\n\ndescribe %S do\nend"},
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\nclass %STest < ActionController::TestCase\nend",
2173+
\ 'test/controllers/': "require 'test_helper'\n\nclass %STest < ActionController::TestCase\nend",
2174+
\ 'test/mailers/': "require 'test_helper'\n\nclass %STest < ActionMailer::TestCase\nend",
2175+
\ 'spec/models/': "require 'spec_helper'\n\ndescribe %S do\nend",
2176+
\ 'spec/helpers/': "require 'spec_helper'\n\ndescribe %S do\nend"},
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\nclass %STest < ActionDispatch::IntegrationTest\nend",
2191+
\ 'spec/requests/': "require 'spec_helper'\n\ndescribe \"%h\" do\nend",
2192+
\ 'spec/integration/': "require 'spec_helper'\n\ndescribe \"%h\" do\nend",
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

Comments
 (0)