Skip to content

Instantly share code, notes, and snippets.

@davedevelopment
Created August 6, 2012 12:09
Show Gist options
  • Select an option

  • Save davedevelopment/3273991 to your computer and use it in GitHub Desktop.

Select an option

Save davedevelopment/3273991 to your computer and use it in GitHub Desktop.
Run a whole feature or nearest scenario in vim
" Run behat features
function! RunFeature(...)
" Are we in a feature file?
let in_feature_file = match(expand("%"), '.feature$') != -1
let run_nearest_scenario = a:0
if in_feature_file
" if so, store the path for later
let t:dm_feature_file=@%
" if they requested the nearest scenario, search for it
if run_nearest_scenario
let t:dm_feature_line_num = search("\S*Scenario.*", 'bnW')
if !t:dm_feature_line_num
" return if not found
return
endif
endif
elseif !exists("t:dm_feature_file")
" if not, bail
return
elseif run_nearest_scenario && !exists("t:dm_feature_line_num")
" if not, but we do know of one, but don't know which line number, bail
return
end
if run_nearest_scenario
exec ":!bin/behat " . t:dm_feature_file . ":" . t:dm_feature_line_num
else
exec ":!bin/behat " . t:dm_feature_file
endif
endfunction
map <leader>s :call RunFeature(1)<cr>
map <leader>f :call RunFeature()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment