Skip to content

Require g:rspec_runner explicitly #94

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

Open
wants to merge 2 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
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for this to point to something more in the users control? Perhaps a script in ~/bin? They might need to hard code the path, and I believe the script execution in the plugin would need to be updated, but I think that could be a better approach. Otherwise they would need to either gitignore their script, or rebase a branch, or otherwise manage it as an addition to the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea. It think this would be a good approach, with allowing people to override the default bin/ path. However, there's no evidence that people are even using this feature. Thus, it would be low priority to focus on something, that's not a reported problem.


## Running tests

Expand Down
35 changes: 20 additions & 15 deletions plugin/rspec.vim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
let s:plugin_path = expand("<sfile>: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)
Expand Down Expand Up @@ -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

Expand Down
65 changes: 42 additions & 23 deletions t/rspec_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down