Skip to content

Commit

Permalink
Merge branch 'gelus-master'
Browse files Browse the repository at this point in the history
* gelus-master:
  tests for hot new run block functionality from @gelus
  bad paste fix
  Add run spec block
  Add run spec block
  • Loading branch information
burnettk committed Jul 30, 2014
2 parents 4f6d165 + a0e9e19 commit 8e4eca8
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ or the "run spec" mapping:
will toggle the spec between "it" and "iit." This works especially well if
you have a karma watch going, as shown in the [screencast][screencast].

You are able to do the same with a describe block using the run block command:

:AngularRunSpecBlock

or the corresponding mapping:

<leader>rb

### Syntastic syntax checker ignores

You know how you use syntastic to check your syntax as you edit, because
Expand Down
5 changes: 5 additions & 0 deletions doc/angular.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ have a karma watch going. Wut, you don't use karma watch? Dude!
files and running your tests automatically when you
save files.

*angular-:AngularRunSpecBlock*
:AngularRunSpecBlock Perform the same dance as :AngularRunSpec but using the
describe block in which the cursor is sitting,
effectively running all specs inside the describe block.

ABOUT *angular-about*

Grab the latest version or report a bug on GitHub:
Expand Down
34 changes: 34 additions & 0 deletions plugin/angular.vim
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,38 @@ function! s:SearchUpForPattern(pattern) abort
endfunction


function! s:AngularRunSpecBlock() abort
" save cursor position so we can go back
let b:angular_pos = getpos('.')

cal s:SearchUpForPattern('describe(')

let l:wordundercursor = expand('<cword>')

if l:wordundercursor == "describe"
" if there was a spec (anywhere in the file) highlighted with "ddescribe" before, revert it to "describe"
let l:positionofspectorun = getpos('.')

" this can move the cursor, hence setting the cursor back
%s/ddescribe/describe/ge
%s/iit/it/ge

" move cursor back to the spec we want to run
call setpos('.', l:positionofspectorun)

" change the current spec to "ddescribe"
execute 'silent normal! cwddescribe'
elseif l:wordundercursor == "ddescribe"
" delete the second d in "ddescribe"
execute 'silent normal! x'
endif

update " write the file if modified

" Reset cursor to previous position.
call setpos('.', b:angular_pos)
endfunction

function! s:AngularRunSpec() abort
" save cursor position so we can go back
let b:angular_pos = getpos('.')
Expand Down Expand Up @@ -230,5 +262,7 @@ augroup END
augroup angular_run_spec
autocmd!
autocmd FileType javascript command! -buffer AngularRunSpec :call s:AngularRunSpec()
autocmd FileType javascript command! -buffer AngularRunSpecBlock :call s:AngularRunSpecBlock()
autocmd FileType javascript nnoremap <silent><buffer> <Leader>rs :AngularRunSpec<CR>
autocmd FileType javascript nnoremap <silent><buffer> <Leader>rb :AngularRunSpecBlock<CR>
augroup END
72 changes: 71 additions & 1 deletion spec/runspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
EOF
end

specify "command untoggles" do
specify "command untoggles spec" do
write_file('test.js', <<-EOF)
iit('should work', function() {
var actualThing = 'cow';
Expand Down Expand Up @@ -115,4 +115,74 @@
});
EOF
end

specify "command runs describe block" do
write_file('test.js', <<-EOF)
describe('aThing', function() {
it('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});
});
EOF

vim.edit 'test.js'
vim.command 'AngularRunSpecBlock'

IO.read('test.js').strip.should eq normalize_string_indent(<<-EOF)
ddescribe('aThing', function() {
it('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});
});
EOF
end

specify "command to run describe block clears out any focused specs marked iit" do
write_file('test.js', <<-EOF)
describe('aThing', function() {
iit('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});
});
EOF

vim.edit 'test.js'
vim.command 'AngularRunSpecBlock'

IO.read('test.js').strip.should eq normalize_string_indent(<<-EOF)
ddescribe('aThing', function() {
it('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});
});
EOF
end

specify "command toggles describe blocks and it specs" do
write_file('test.js', <<-EOF)
ddescribe('aThing', function() {
it('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});
});
EOF

vim.edit 'test.js'
vim.command 'AngularRunSpecBlock'

IO.read('test.js').strip.should eq normalize_string_indent(<<-EOF)
describe('aThing', function() {
it('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});
});
EOF
end

end

0 comments on commit 8e4eca8

Please sign in to comment.