Skip to content

Running spec with debugger #137

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 3 commits into
base: main
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Example:
let g:rspec_command = "!rspec --drb {spec}"
```

If you want running spec with debugger(pry, debugger, etc), just
declare this in your vim config.
```vim
let g:rspec_with_debug = 1
```

This `g:rspec_command` variable can be used to support any number of test
runners or pre-loaders. For example, to use
[Dispatch](https://github.com/tpope/vim-dispatch):
Expand Down
14 changes: 13 additions & 1 deletion plugin/rspec.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ let s:plugin_path = expand("<sfile>:p:h:h")
let s:default_command = "rspec {spec}"
let s:force_gui = 0

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

if !exists("g:rspec_runner")
let g:rspec_runner = "os_x_terminal"
endif
Expand Down Expand Up @@ -58,7 +62,11 @@ function! s:RspecCommand()
elseif s:IsMacGui()
let l:command = s:GuiCommand(s:default_command)
else
let l:command = s:DefaultTerminalCommand()
if g:rspec_with_debug > 0
let l:command = s:TerminalCommandWithDebug()
else
let l:command = s:DefaultTerminalCommand()
endif
endif

return l:command
Expand All @@ -72,6 +80,10 @@ function! s:DefaultTerminalCommand()
return "!" . s:ClearCommand() . " && echo " . s:default_command . " && " . s:default_command
endfunction

function! s:TerminalCommandWithDebug()
return "split | terminal "." { " . s:default_command . " }"
endfunction

function! s:CurrentFilePath()
return @%
endfunction
Expand Down
19 changes: 19 additions & 0 deletions t/rspec_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ describe "RunSpecs"
end
end
end

context "when g:rspec_with_debug is defined"
before
let g:rspec_with_debug = 1
end

after
unlet g:rspec_with_debug
end

it "runs the current spec file at the current line"
call Set("s:last_spec_file_with_line", "model_spec.rb:42")
call Set("s:last_spec_file", "model_spec.rb")

call Call("RunNearestSpec")

Expect Ref("s:rspec_command") == "terminal { rspec controller_spec.rb:5 }"
end
end
end

describe "RunCurrentSpecFile"
Expand Down