Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HspecOpenTest command and default mapping #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Haskell.

### Installation

Compatible with *Vundle*, *Pathogen*, *Vim-plug*, etc.

If you are using [pathogen.vim](https://github.com/tpope/vim-pathogen), then
you can install `hspec.vim` with:

Expand All @@ -27,6 +29,15 @@ highlight link hspecDescription Comment

![screenshot of vim with hspec.vim](https://raw.github.com/hspec/hspec.vim/master/screenshot.png "hspec.vim awesomeness in pictures")

### Commands

The plugin includes the `HspecOpenTest` command, that allows you to open the
Spec test for the current source file. It also provides a default mapping `ghs`
(Go Hspec).

By default `HspecOpenTest` will recursively find your tests in `test/` and
`../test`.

### Snippets

The plugin includes [UltiSnips] snippets for the Hspec DSL. If you have
Expand All @@ -40,6 +51,32 @@ common triggers: `spec`, `des`, `con`, `it`, etc.
[Hspec]: http://hspec.github.io/
[UltiSnips]: https://github.com/SirVer/ultisnips

### Configuration

Remove the default mapping with (default = `0`):

```vims
let g:hspec_disable_maps = 1
```

Add directories where your tests reside (default = `['test', '../test']`):

```vim
let g:hspec_tests_dir = ['test', '../test', 'some_dir']
```

Change the test files prefix (default = `''`):

```vim
let g:hspec_tests_prefix = 'prefix'
```

Change the test files suffix (default = `'Spec'`):

```vim
let g:hspec_tests_suffix = 'Spec'
```

### License

Distributed under the [MIT license](http://www.opensource.org/licenses/MIT).
Expand Down
26 changes: 26 additions & 0 deletions autoload/hspec.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if !exists("g:hspec_tests_dir")
let g:hspec_tests_dir = ['test', '../test']
endif

if !exists("g:hspec_tests_prefix")
let g:hspec_tests_prefix = ''
endif

if !exists("g:hspec_tests_suffix")
let g:hspec_tests_suffix = 'Spec'
endif

function! hspec#OpenTest()
let l:current_filename = expand("%:t:r")
let l:test_filename = g:hspec_tests_prefix . l:current_filename . g:hspec_tests_suffix . ".hs"

for dir in g:hspec_tests_dir
let l:test_file = findfile(l:test_filename, dir . "/**/")
if l:test_file !=? ""
exe ":e " . l:test_file
return
endif
endfor

echom "Test file \"" . l:test_filename . "\" does not exist!"
endfunction
12 changes: 12 additions & 0 deletions plugin/hspec.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
command! HspecOpenTest call hspec#OpenTest()

if !exists("g:hspec_disable_maps")
let g:hspec_disable_maps = 0
endif

if exists("g:hspec_disable_maps") && g:hspec_disable_maps == 0
augroup hspec
au!
au FileType haskell nnoremap ghs :HspecOpenTest<CR>
augroup END
endif