Skip to content

Commit b9d1f61

Browse files
committed
Update rspec templates
1 parent 0872eec commit b9d1f61

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

autoload/rails.vim

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,9 +3036,18 @@ function! s:stylesheetList(A, L, P) abort
30363036
endfunction
30373037

30383038
function! s:specEdit(cmd,...) abort
3039-
let describe = s:sub(s:sub(rails#camelize(a:0 ? a:1 : ''), '^[^:]*::', ''), '!.*', '')
3039+
let describe = s:sub(s:sub(a:0 ? a:1 : '', '^[^/]*/', ''), '!.*', '')
3040+
let type = rails#singularize(matchstr(a:0 ? a:1 : '', '\w\+'))
3041+
if type =~# '^\%(request\|routing\|integration\|feature\)$'
3042+
let describe = '"' . tr(s:transformations.capitalize(describe, {}), '_', ' ') . '"'
3043+
elseif type ==# 'view'
3044+
let describe = '"' . describe . '"'
3045+
else
3046+
let describe = rails#camelize(describe)
3047+
endif
3048+
let describe .= ', type: :' . type
30403049
return rails#buffer().open_command(a:cmd, a:0 ? a:1 : '', 'spec', [
3041-
\ {'pattern': 'spec/*_spec.rb', 'template': "require 'rails_helper'\n\ndescribe ".describe." do\nend"},
3050+
\ {'pattern': 'spec/*_spec.rb', 'template': "require 'rails_helper'\n\nRSpec.describe ".describe." do\nend"},
30423051
\ {'pattern': 'spec/spec_helper.rb'},
30433052
\ {'pattern': 'spec/rails_helper.rb'}])
30443053
endfunction
@@ -4713,7 +4722,7 @@ let s:has_projections = {
47134722
\ "template": [
47144723
\ "require 'rails_helper'",
47154724
\ "",
4716-
\ "describe {camelcase|capitalize|colons} do",
4725+
\ "RSpec.describe {camelcase|capitalize|colons}, type: :controller do",
47174726
\ "end"
47184727
\ ],
47194728
\ "type": "functional test"
@@ -4722,7 +4731,7 @@ let s:has_projections = {
47224731
\ "template": [
47234732
\ "require 'rails_helper'",
47244733
\ "",
4725-
\ "describe \"{underscore|capitalize|blank}\" do",
4734+
\ "RSpec.describe \"{underscore|capitalize|blank}\", type: :feature do",
47264735
\ "end"
47274736
\ ],
47284737
\ "type": "integration test"
@@ -4731,7 +4740,7 @@ let s:has_projections = {
47314740
\ "template": [
47324741
\ "require 'rails_helper'",
47334742
\ "",
4734-
\ "describe {camelcase|capitalize|colons} do",
4743+
\ "RSpec.describe {camelcase|capitalize|colons}, type: :helper do",
47354744
\ "end"
47364745
\ ],
47374746
\ "type": "unit test"
@@ -4740,7 +4749,7 @@ let s:has_projections = {
47404749
\ "template": [
47414750
\ "require 'rails_helper'",
47424751
\ "",
4743-
\ "describe \"{underscore|capitalize|blank}\" do",
4752+
\ "RSpec.describe \"{underscore|capitalize|blank}\", type: :integration do",
47444753
\ "end"
47454754
\ ],
47464755
\ "type": "integration test"
@@ -4751,7 +4760,7 @@ let s:has_projections = {
47514760
\ "template": [
47524761
\ "require 'rails_helper'",
47534762
\ "",
4754-
\ "describe {camelcase|capitalize|colons} do",
4763+
\ "RSpec.describe {camelcase|capitalize|colons}, type: :mailer do",
47554764
\ "end"
47564765
\ ],
47574766
\ "type": "functional test"
@@ -4761,7 +4770,7 @@ let s:has_projections = {
47614770
\ "template": [
47624771
\ "require 'rails_helper'",
47634772
\ "",
4764-
\ "describe {camelcase|capitalize|colons} do",
4773+
\ "RSpec.describe {camelcase|capitalize|colons}, type: :model do",
47654774
\ "end"
47664775
\ ],
47674776
\ "type": "unit test"
@@ -4771,7 +4780,7 @@ let s:has_projections = {
47714780
\ "template": [
47724781
\ "require 'rails_helper'",
47734782
\ "",
4774-
\ "describe \"{underscore|capitalize|blank}\" do",
4783+
\ "RSpec.describe \"{underscore|capitalize|blank}\", type: :request do",
47754784
\ "end"
47764785
\ ],
47774786
\ "type": "integration test"

0 commit comments

Comments
 (0)