Skip to content

Instantly share code, notes, and snippets.

@mwise
Created July 16, 2013 14:25
Show Gist options
  • Save mwise/6009211 to your computer and use it in GitHub Desktop.
Save mwise/6009211 to your computer and use it in GitHub Desktop.
nnoremap <leader>ls :OpenSpecInSplit<cr>
nnoremap <leader>FF :ToggleCurrentDescribeFocus<cr>
nnoremap <leader>FA :FocusCurrentDescribe<cr>
nnoremap <leader>FD :UnFocusCurrentDescribe<cr>
fun! OpenSpecInSplit()
let file = expand('%:p')
if match(file, "app/") >= 0
if match(file, "assets/javascripts") >= 0
let f1 = substitute(file, "\\.js\.coffee", ".spec.coffee", "")
let f2 = substitute(f1, "app\/assets\/javascripts\\/", "spec/javascripts/spec/", "")
else
let f1 = substitute(file, "\\.rb", "_spec.rb", "")
let f2 = substitute(f1, "app\\/", "spec/", "")
endif
call OpenFilesInSplit(f2, file)
exec "w"
else
if match(file, "spec/") >= 0
if match(file, "spec/javascripts") >= 0
let f1 = substitute(file, "\.spec\.coffee", ".js.coffee", "")
let f2 = substitute(f1, "spec/javascripts/spec", "app/assets/javascripts", "")
else
let f1 = substitute(file, "\_spec", "", "")
let f2 = substitute(f1, "spec/", "app/", "")
endif
call OpenFilesInSplit(file, f2)
exec "w"
endif
endif
endfun
com! OpenSpecInSplit :call OpenSpecInSplit()
fun! ToggleCurrentDescribeFocus()
let match = search('describe', 'bWn')
:let line = getline(match)
if match(line, "focus") >= 0
call UnFocusCurrentDescribe()
else
call FocusCurrentDescribe()
endif
endfun
com! ToggleCurrentDescribeFocus :call ToggleCurrentDescribeFocus()
fun! FocusCurrentDescribe()
let match = search('describe', 'bWn')
:let line = getline(match)
if match(line, "focus") >= 0
else
:let repl = substitute(line, ' do$', ", focus: true do", "")
:call setline(match, repl)
endif
endfun
com! FocusCurrentDescribe :call FocusCurrentDescribe()
fun! UnFocusCurrentDescribe()
let match = search('describe', 'bWn')
:let line = getline(match)
:let repl = substitute(line, ', focus: true', "", "g")
:call setline(match, repl)
endfun
com! UnFocusCurrentDescribe :call UnFocusCurrentDescribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment