Skip to content

Commit

Permalink
Fix setup/teardown bug.
Browse files Browse the repository at this point in the history
* Thank you, M.K!
  • Loading branch information
h1mesuke committed Apr 1, 2012
1 parent 67e1548 commit 9277877
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 5 deletions.
6 changes: 3 additions & 3 deletions autoload/unittest/testcase.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"
" File : autoload/unittest/testcase.vim
" Author : h1mesuke <himesuke+vim@gmail.com>
" Updated : 2012-01-27
" Updated : 2012-04-02
" Version : 0.6.0
" License : MIT license {{{
"
Expand Down Expand Up @@ -149,7 +149,7 @@ function! s:TestCase___setup__(test) dict
call self.setup()
endif
for suffix in self.__private__.setup_suffixes
if a:test =~# suffix
if substitute(a:test, '^test_', '', '') =~# '^'. suffix
call call(self['setup_' . suffix], [], self)
endif
endfor
Expand All @@ -158,7 +158,7 @@ call s:TestCase.method('__setup__')

function! s:TestCase___teardown__(test) dict
for suffix in self.__private__.teardown_suffixes
if a:test =~# suffix
if substitute(a:test, '^test_', '', '') =~# '^'. suffix
call call(self['teardown_' . suffix], [], self)
endif
endfor
Expand Down
1 change: 1 addition & 0 deletions test/test_almost.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ execute 'source' s:here . '/test_context.vim'
execute 'source' s:here . '/test_data.vim'
execute 'source' s:here . '/test_setup.vim'
execute 'source' s:here . '/test_should.vim'
execute 'source' s:here . '/test_should_setup.vim'
112 changes: 112 additions & 0 deletions test/test_setup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@
" Expected results:
"
" SETUP
"
" setup
" setup_a
" test_a
" teardown_a
" teardown
"
" setup
" setup_a
" setup_a_e
" test_a_e
" teardown_a_e
" teardown_a
" teardown
"
" setup
" setup_e
" test_e
" teardown_e
" teardown
"
" setup
" setup_e
" setup_e_a
" test_e_a
" teardown_e_a
" teardown_e
" teardown
"
" setup
" setup_foo
Expand Down Expand Up @@ -48,6 +76,62 @@ function! s:tc.setup()
call self.puts("setup")
endfunction

function! s:tc.setup_a()
call add(self.funcalls, "setup_a")
call self.puts("setup_a")
endfunction
function! s:tc.test_a()
call add(self.funcalls, "test_a")
call self.puts("test_a")
call self.assert(1) | " Not pending.
endfunction
function! s:tc.teardown_a()
call add(self.funcalls, "teardown_a")
call self.puts("teardown_a")
endfunction

function! s:tc.setup_e()
call add(self.funcalls, "setup_e")
call self.puts("setup_e")
endfunction
function! s:tc.test_e()
call add(self.funcalls, "test_e")
call self.puts("test_e")
call self.assert(1) | " Not pending.
endfunction
function! s:tc.teardown_e()
call add(self.funcalls, "teardown_e")
call self.puts("teardown_e")
endfunction

function! s:tc.setup_a_e()
call add(self.funcalls, "setup_a_e")
call self.puts("setup_a_e")
endfunction
function! s:tc.test_a_e()
call add(self.funcalls, "test_a_e")
call self.puts("test_a_e")
call self.assert(1) | " Not pending.
endfunction
function! s:tc.teardown_a_e()
call add(self.funcalls, "teardown_a_e")
call self.puts("teardown_a_e")
endfunction

function! s:tc.setup_e_a()
call add(self.funcalls, "setup_e_a")
call self.puts("setup_e_a")
endfunction
function! s:tc.test_e_a()
call add(self.funcalls, "test_e_a")
call self.puts("test_e_a")
call self.assert(1) | " Not pending.
endfunction
function! s:tc.teardown_e_a()
call add(self.funcalls, "teardown_e_a")
call self.puts("teardown_e_a")
endfunction

function! s:tc.setup_foo()
call add(self.funcalls, "setup_foo")
call self.puts("setup_foo")
Expand Down Expand Up @@ -117,6 +201,34 @@ function! s:tc.test_zetup_and_teardown()
\ "SETUP",
\
\ "setup",
\ "setup_a",
\ "test_a",
\ "teardown_a",
\ "teardown",
\
\ "setup",
\ "setup_a",
\ "setup_a_e",
\ "test_a_e",
\ "teardown_a_e",
\ "teardown_a",
\ "teardown",
\
\ "setup",
\ "setup_e",
\ "test_e",
\ "teardown_e",
\ "teardown",
\
\ "setup",
\ "setup_e",
\ "setup_e_a",
\ "test_e_a",
\ "teardown_e_a",
\ "teardown_e",
\ "teardown",
\
\ "setup",
\ "setup_foo",
\ "test_foo",
\ "teardown_foo",
Expand Down
4 changes: 2 additions & 2 deletions test/test_should.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" unittest.vim's test suite
"
" Test case of shoulda style tests
" Test case of shoulda-like tests
"
" thoughtbot/shoulda - GitHub
" https://github.com/thoughtbot/shoulda
Expand All @@ -12,7 +12,7 @@
"
"-----------------------------------------------------------------------------

let s:tc = unittest#testcase#new("Shoulda-style Test Names")
let s:tc = unittest#testcase#new("Shoulda-like Tests")

function! s:tc.one_should_be_true()
call self.assert(1)
Expand Down
Loading

0 comments on commit 9277877

Please sign in to comment.