diff --git a/README.md b/README.md index 9b81e64..a570db6 100644 --- a/README.md +++ b/README.md @@ -50,32 +50,33 @@ Or, [Dispatch](https://github.com/tpope/vim-dispatch) and let g:rspec_command = "compiler rspec | set makeprg=zeus | Make rspec {spec}" ``` -### Custom runners +### MacVim command runners -Overwrite the `g:rspec_runner` variable to set a custom launch script. At the -moment there are two MacVim-specific runners, i.e. `os_x_terminal` and -`os_x_iterm`. The default is `os_x_terminal`, but you can set this to anything -you want, provided you include the appropriate script inside the plugin's -`bin/` directory. +If you are running your specs from MacVim, +you must set `g:rspec_runner` or `g:rspec_command`, or both. -#### iTerm instead of Terminal - -If you use iTerm, you can set `g:rspec_runner` to use the included iterm -launching script. This will run the specs in the last session of the current -terminal. +The `g:rspec_runner` variable specifies which launch script will be used: ```vim let g:rspec_runner = "os_x_iterm" ``` -If you use the iTerm2 nightlies, the `os_x_iterm` runner will not work -(due to AppleScript incompatibilities between the old and new versions of iTerm2). +At the moment the following MacVim-specific runners are supported: -Instead use the `os_x_iterm2` runner, configure it like so: +* `os_x_terminal` for OSX Terminal.app +* `os_x_iterm` for iTerm2 stable release + * If you use the iTerm2 nightlies, + this runner will not work due to AppleScript incompatibilities + between the old and new versions of iTerm2 +* `os_x_iterm2` for iTerm2 nightly builds -```vim -let g:rspec_runner = "os_x_iterm2" -``` +If `g:rspec_runner` isn't set, +the `g:rspec_command` will be executed from MacVim without a runner. +This enables commands like `Dispatch rspec {spec}` to work in GUI mode. + +You can set `g:rspec_runner` to anything you want, +provided you include the appropriate script +inside the plugin's `bin/` directory. ## Running tests diff --git a/plugin/rspec.vim b/plugin/rspec.vim index 2be9ebc..9762979 100644 --- a/plugin/rspec.vim +++ b/plugin/rspec.vim @@ -1,11 +1,6 @@ let s:plugin_path = expand(":p:h:h") -let s:default_command = "rspec {spec}" let s:force_gui = 0 -if !exists("g:rspec_runner") - let g:rspec_runner = "os_x_terminal" -endif - function! RunAllSpecs() let s:last_spec = "spec" call s:RunSpecs(s:last_spec) @@ -51,32 +46,42 @@ function! s:InSpecFile() endfunction function! s:RspecCommand() - if s:RspecCommandProvided() && s:IsMacGui() - let l:command = s:GuiCommand(g:rspec_command) - elseif s:RspecCommandProvided() + if s:RspecCommandProvided() let l:command = g:rspec_command - elseif s:IsMacGui() - let l:command = s:GuiCommand(s:default_command) else - let l:command = s:DefaultTerminalCommand() + let l:command = s:DefaultCommand() endif - return l:command + if s:IsMacGui() && s:RspecRunnerProvided() + return s:RunnerCommand(l:command) + else + return l:command + endif endfunction function! s:RspecCommandProvided() return exists("g:rspec_command") endfunction -function! s:DefaultTerminalCommand() - return "!" . s:ClearCommand() . " && echo " . s:default_command . " && " . s:default_command +function! s:RspecRunnerProvided() + return exists("g:rspec_runner") +endfunction + +function! s:DefaultCommand() + let l:default_command = "rspec {spec}" + + if s:IsMacGui() + return l:default_command + else + return "!" . s:ClearCommand() . " && echo " . l:default_command . " && " . l:default_command + endif endfunction function! s:CurrentFilePath() return @% endfunction -function! s:GuiCommand(command) +function! s:RunnerCommand(command) return "silent ! '" . s:plugin_path . "/bin/" . g:rspec_runner . "' '" . a:command . "'" endfunction diff --git a/t/rspec_test.vim b/t/rspec_test.vim index 50d0e18..90b0333 100644 --- a/t/rspec_test.vim +++ b/t/rspec_test.vim @@ -13,16 +13,21 @@ describe "RunSpecs" end context "when in GUI" - context "when g:rspec_runner is defined" + before + call Set("s:force_gui", 1) + end + + after + call Set("s:force_gui", 0) + end + + context "when rspec_runner is defined" before - call Set("s:force_gui", 1) - let s:original_runner = g:rspec_runner let g:rspec_runner = "iterm" end after - let g:rspec_runner = s:original_runner - call Set("s:force_gui", 0) + unlet g:rspec_runner end it "sets the command with provided runner" @@ -35,20 +40,15 @@ describe "RunSpecs" end context "when rspec_runner is not defined" - before - call Set("s:force_gui", 1) - end - - after - call Set("s:force_gui", 0) - end - - it "sets the command with default runner" - let expected = "^silent ! '\.\*/bin/os_x_terminal' 'rspec " . s:filename . "'$" - - call Call("s:RunSpecs", s:filename) - - Expect Ref("s:rspec_command") =~ expected + it "sets the default command" + let expected = "rspec " . s:filename + + try + call Call("s:RunSpecs", s:filename) + catch + finally + Expect Ref("s:rspec_command") =~ expected + endtry end end end @@ -83,11 +83,30 @@ describe "RunSpecs" call Set("s:force_gui", 0) end - it "sets the provided GUI command" - let expected = "^silent ! '\.\*/bin/os_x_terminal' '!Dispatch rspec " . s:filename . "'$" - call Call("s:RunSpecs", s:filename) + context "and rspec_runner is defined" + before + let g:rspec_runner = "fake_runner" + end + + after + unlet g:rspec_runner + end + + it "sets the provided GUI command" + let expected = "^silent ! '\.\*/bin/fake_runner' '!Dispatch rspec " . s:filename . "'$" + call Call("s:RunSpecs", s:filename) - Expect Ref("s:rspec_command") =~ expected + Expect Ref("s:rspec_command") =~ expected + end + end + + context "and rspec_runner is not defined" + it "sets the provided rspec command" + let expected = "Dispatch rspec " . s:filename + call Call("s:RunSpecs", s:filename) + + Expect Ref("s:rspec_command") =~ expected + end end end end