Permalink
Browse files

Support :after blocks

  • Loading branch information...
kana committed Jan 30, 2012
1 parent e60bdaa commit 8235b48943774cb3c8ef0a8bab470b0117f8bdf5
Showing with 215 additions and 129 deletions.
  1. +1 −1 after/indent/vim.vim
  2. +1 −0 after/syntax/vim/vspec.vim
  3. +21 −0 autoload/vspec.vim
  4. +9 −7 doc/vspec.txt
  5. +19 −0 t/after.vim
  6. +1 −1 t/error-in-it.t
  7. +1 −1 t/error-in-should-evaluating.t
  8. +1 −1 t/error-in-should-parsing.t
  9. +28 −0 t/indent.vim
  10. +133 −118 t/syntax.vim
View
@@ -37,7 +37,7 @@ function GetVimVspecIndent(base_indent)
let base_lnum = prevnonblank(v:lnum - 1)
let line = getline(base_lnum)
- if 0 <= match(line, '\(^\||\)\s*\(before\|describe\|it\)\>')
+ if 0 <= match(line, '\(^\||\)\s*\(after\|before\|describe\|it\)\>')
let indent += &l:shiftwidth
endif
@@ -22,6 +22,7 @@
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
+syntax keyword vimVspecCommand after
syntax keyword vimVspecCommand before
syntax keyword vimVspecCommand describe skipwhite nextgroup=vimString
syntax keyword vimVspecCommand end
View
@@ -288,6 +288,7 @@ function! vspec#test(specfile_path) "{{{2
echo '#' v:throwpoint
echo '#' v:exception
endtry
+ call suite.after_block()
endfor
call s:pop_current_suite()
endfor
@@ -330,6 +331,13 @@ endfunction
+function! s:suite.after_block() "{{{2
+ " No-op to avoid null checks.
+endfunction
+
+
+
+
function! s:suite.before_block() "{{{2
" No-op to avoid null checks.
endfunction
@@ -438,6 +446,15 @@ function! s:translate_script(slines) "{{{2
continue
endif
+ let tokens = matchlist(sline, '^\s*after\s*$')
+ if !empty(tokens)
+ call insert(stack, 'after', 0)
+ call extend(rlines, [
+ \ 'function! suite.after_block()',
+ \ ])
+ continue
+ endif
+
let tokens = matchlist(sline, '^\s*end\s*$')
if !empty(tokens)
let type = remove(stack, 0)
@@ -451,6 +468,10 @@ function! s:translate_script(slines) "{{{2
call extend(rlines, [
\ 'endfunction',
\ ])
+ elseif type ==# 'after'
+ call extend(rlines, [
+ \ 'endfunction',
+ \ ])
else
" Nothing to do.
endif
View
@@ -172,16 +172,18 @@ COMMANDS *vspec-commands*
:before *:before*
:end
- Define a code block which is run before each example
- defined by |:it|.
+:after *:after*
+:end
+ Define a code block which is run before/after each
+ example defined by |:it|.
Note that:
- - Only one |:before| block can be written in each
+ - Only one :before/:after block can be written in each
|:describe| block.
- - |:before| blocks cannot be defined for |:describe|
- blocks.
- - |:before| blocks cannot be defined for a specific
- |:it| block.
+ - :before/:after blocks cannot be defined for
+ |:describe| blocks.
+ - :before/:after blocks cannot be defined for
+ a specific |:it| block.
These limitations might be resolved later.
:ResetContext *:ResetContext*
View
@@ -0,0 +1,19 @@
+describe 'after'
+ let g:counter = 0
+
+ after
+ let g:counter += 1
+ end
+
+ it 'should call the after block for each example (the first time)'
+ Expect g:counter == 0
+ end
+
+ it 'should call the after block for each example (the second time)'
+ Expect g:counter == 1
+ end
+
+ it 'should call the after block for each example (the third time)'
+ Expect g:counter == 2
+ end
+end
View
@@ -29,7 +29,7 @@ END
) <(cat <<'END'
ok 1 - Suite 1 should be executed
not ok 2 - Suite 2 should be executed and fail
-# function <SNR>1_main..vspec#test..5..A..B..C, line 1
+# function <SNR>1_main..vspec#test..6..A..B..C, line 1
# Vim:E492: Not an editor command: ThisLineIsNotAValidVimScriptStatement
ok 3 - Suite 3 should be executed
1..3
@@ -20,7 +20,7 @@ END
) <(cat <<'END'
ok 1 - Suite 1 should be executed
not ok 2 - Suite 2 should be executed and fail
-# function <SNR>1_main..vspec#test..5, line 1
+# function <SNR>1_main..vspec#test..6, line 1
# Vim(call):E121: Undefined variable: foo
ok 3 - Suite 3 should be executed
1..3
@@ -20,7 +20,7 @@ END
) <(cat <<'END'
ok 1 - Suite 1 should be executed
not ok 2 - Suite 2 should be executed and fail
-# function <SNR>1_main..vspec#test..5..<SNR>2_parse_should_arguments, line 2
+# function <SNR>1_main..vspec#test..6..<SNR>2_parse_should_arguments, line 2
# Vim(let):E688: More targets than List items
ok 3 - Suite 3 should be executed
1..3
View
@@ -86,4 +86,32 @@ describe 'Automatic indentation'
call s:after()
end
+
+ it 'should indent lines after :after'
+ call s:before()
+
+ execute 'normal!' 'i' . join([
+ \ 'describe ''foo''',
+ \ 'after',
+ \ 'qux',
+ \ 'end',
+ \ 'it ''bar''',
+ \ 'baz',
+ \ 'end',
+ \ 'end',
+ \ ], "\<Return>")
+
+ Expect getline(1, '$') ==# [
+ \ 'describe ''foo''',
+ \ ' after',
+ \ ' qux',
+ \ ' end',
+ \ ' it ''bar''',
+ \ ' baz',
+ \ ' end',
+ \ 'end',
+ \ ]
+
+ call s:after()
+ end
end
Oops, something went wrong.

0 comments on commit 8235b48

Please sign in to comment.