Permalink
Browse files

Version 0.2

Added syntax highlighting for spec output, and spec assertion failure 'jumping'.  Screencast available for your viewing pleasure.
  • Loading branch information...
1 parent 3d23bd2 commit c8e95479af8f8feba65fdd9005d9ca4e5c20c26e @mahlonsmith mahlonsmith committed with vim-scripts Jul 9, 2008
Showing with 131 additions and 8 deletions.
  1. +56 −8 plugin/specky.vim
  2. +75 −0 syntax/specrun.vim
View
@@ -2,7 +2,7 @@
"
" Specky!
" Mahlon E. Smith <mahlon@martini.nu>
-" $Id: specky.vim 75 2008-07-07 04:37:52Z mahlon $
+" $Id: specky.vim 80 2008-07-09 06:58:41Z mahlon $
"
" Some documentation {{{
"
@@ -26,8 +26,15 @@
" now do with a single key stroke:
"
" - Switch back and forth from code to testing spec
-" - Run the spec, with results going to a new buffer
+"
+" - Run the spec, with results going to a new, syntax highlighted buffer
+"
+" - Jump quickly to spec failures and failure detail
+" - 'e' to move to each failed assertion, and 'E' to jump
+" to the details for it. 'q' to close the spec output buffer.
+"
" - View rdoc of the word under the cursor
+"
" - Dynamically switch string types for the word under the cursor
" (double quoted, quoted, symbol)
"
@@ -88,7 +95,7 @@
"
" g:speckySpecFlags
" -----------------
-" Any additional flags for the 'spec' program. Defaults to '-fp'.
+" Any additional flags for the 'spec' program. Defaults to '-fs'.
"
"
" g:speckyVertSplit
@@ -106,7 +113,7 @@
" let g:speckyRunRdocCmd = 'fri'
" let g:speckyRunRdocFlags = '-L -f plain'
" let g:speckyRunSpecKey = '<C-S>s'
-" let g:speckySpecFlags = '-fp -r loadpath.rb'
+" let g:speckySpecFlags = '-fs -r extra_libs.rb'
" let g:speckyVertSplit = 1
@@ -130,6 +137,12 @@ if exists( 'g:speckyRunRdocKey' )
endif
+if exists( 'specky_loaded' )
+ finish
+endif
+let specky_loaded = '$Rev: 80 $'
+
+
"}}}
" Menu configuration {{{
"
@@ -261,20 +274,28 @@ function! <SID>:RunSpec()
endif
execute ( exists('g:speckyVertSplit') ? 'vert new ' : 'new ') . l:buf
- execute 'setlocal buftype=nofile bufhidden=delete noswapfile filetype=spec'
+ execute 'setlocal buftype=nofile bufhidden=delete noswapfile filetype=specrun'
+ set foldtext='--'.getline(v:foldstart).v:folddashes
+
+ " Set up some convenient keybindings.
+ "
+ execute 'nnoremap <silent> <buffer> q :close<CR>'
+ execute 'nnoremap <silent> <buffer> e :call <SID>:FindSpecError(0)<CR>'
+ execute 'nnoremap <silent> <buffer> E :call <SID>:FindSpecError(1)<CR>'
" Default flags for spec
"
if !exists( 'g:speckySpecFlags' )
- let g:speckySpecFlags = '-fp'
+ let g:speckySpecFlags = '-fs'
endif
" Call spec and gather up the output
"
let l:cmd = 'spec ' . g:speckySpecFlags . ' ' . l:spec
let l:output = system( l:cmd )
call append( 0, split( l:output, "\n" ) )
- call append( 0, 'Output of: ' . l:cmd )
+ call append( 0, '' )
+ call append( 0, 'Output of: ' . l:cmd )
execute 'normal gg'
" Lockdown the buffer
@@ -336,6 +357,7 @@ function! <SID>:RunRdoc()
execute ( exists('g:speckyVertSplit') ? 'vert new ' : 'new ') . l:buf
execute 'setlocal buftype=nofile bufhidden=delete noswapfile filetype=rdoc'
+ execute 'nnoremap <silent> <buffer> q :close<CR>'
" Call the documentation and gather up the output
"
@@ -351,10 +373,36 @@ endfunction
" }}}
+" specky:FindSpecError( detail ) {{{
+"
+" Convenience searches for jumping to spec failures.
+"
+function! <SID>:FindSpecError( detail )
+
+ if ( a:detail )
+ " Find the detailed failure text for the current failure line,
+ " and unfold it.
+ "
+ call search('^' . matchstr(getline('.'),'\d\+)$') )
+ if has('folding')
+ execute 'normal za'
+ endif
+
+ else
+ " Find the 'regular' failure line
+ "
+ call search('(ERROR - \d\+)$')
+ execute 'nohl'
+
+ endif
+endfunction
+
+
+" }}}
" s:err( msg ) "{{{
" Notify of problems in a consistent fashion.
"
function! s:err( msg )
echohl WarningMsg|echomsg 'specky: ' . a:msg|echohl None
-endfunction "}}}
+endfunction " }}}
View
@@ -0,0 +1,75 @@
+"
+" specky: syntax highlighting for the 'spec' script output
+" $Id: specrun.vim 80 2008-07-09 06:58:41Z mahlon $
+"
+
+if has("folding")
+ setlocal foldmethod=syntax
+endif
+
+" Command line as it was called, inserted by Specky
+"
+syntax match specSpeckyCmd /^Output of: .*/
+highlight link specSpeckyCmd Question
+"syntax match WarningMsg /\.\./
+
+" Plain output block (...P..F...)
+"
+syntax region specPlain start="^[\.PF]\+" end="^$" contains=specFailedPlain,specPendingPlain
+highlight link specPlain MoreMsg
+
+" Passed specs (specdoc output)
+"
+syntax match specPassed /^- .*/ contains=specFailed,specPending
+highlight link specPassed MoreMsg
+
+" Pending specs (specdoc output)
+"
+syntax match specPending /.*PENDING: Not Yet Implemented)/ contained
+highlight link specPending Function
+"
+" (Plain output)
+syntax match specPendingPlain /P/ contained
+highlight link specPendingPlain Function
+
+" Failed specs (specdoc output)
+"
+syntax match specFailed /.*ERROR - \d\+)/ contained
+highlight link specFailed WarningMsg
+"
+" (Plain output)
+syntax match specFailedPlain /F/ contained
+highlight link specFailedPlain WarningMsg
+
+" Warning details
+"
+syntax region specFailedDetails start="^\d\+)" end="^$" fold
+highlight link specFailedDetails WarningMsg
+
+" Pending specs
+"
+syntax region specPendingDetails start="^Pending:" end="^$" fold
+highlight link specPendingDetails Function
+
+" Timing information
+"
+syntax match specTimedRun /^Finished in.*/
+highlight link specTimedRun Question
+
+" Status summary
+"
+syntax match specExamplesTotal /^\d\+ examples, .\+/ contains=specTotalFailed,specNoFailures,specTotalPending
+highlight link specExamplesTotal Special
+"
+syntax match specTotalFailed /\d\+ failure\%[s]/ contained
+highlight link specTotalFailed WarningMsg
+"
+syntax match specTotalPending /\d pending/ contained
+highlight link specTotalPending Function
+"
+syntax match specNoFailures /0 failures/ contained
+highlight link specNoFailures MoreMsg
+
+
+let b:current_syntax = "specrun"
+

0 comments on commit c8e9547

Please sign in to comment.