Giter VIP home page Giter VIP logo

vim-rubytest's Introduction

Rubytest.vim

Rubytest.vim is a vim (http://www.vim.org) plugin, which helps you to run ruby test (including vanilla test, rspec, shoulda etc.) in vim.

Installation

Copy all files to your ~/.vim directory.

Usage

After installation, press <Leader>t will run the test under your cursor if you are editing a ruby test file.

Example:

$ cd <your rails/merb root>
$ vim test/unit/user_test.rb

(move cursor into a test case, press <Leader>t)

(<Leader> is mapping to '' by default in vim)

Be default, the plugin will print output in terminal. You can change this behavior by putting this line in your vimrc file:

let g:rubytest_output = <output>

The following <output> values are supported:

  • quickfix - show failed tests in a quickfix window
  • vim_terminal - run the tests in a vim terminal (vim version 8.1 or higher)

With this set, test errors will be displayed in quickfix window, and you can jump to the error location quickly by select the error message and hit return (or Ctrl-w return to open it in new window).

You can customize the command which will be used to run the test case by setting these options in your vimrc file:

let g:rubytest_cmd_test = "ruby %p"
let g:rubytest_cmd_testcase = "ruby %p -n '/%c/'"
let g:rubytest_cmd_spec = "spec -f specdoc %p"
let g:rubytest_cmd_example = "spec -f specdoc %p -e '%c'"
let g:rubytest_cmd_feature = "cucumber %p"
let g:rubytest_cmd_story = "cucumber %p -n '%c'"

Using Spork

let g:rubytest_cmd_test = "bundle exec testdrb %p"
let g:rubytest_cmd_testcase = "bundle exec testdrb %p -- -n '/%c/'"

Using Spring

let g:rubytest_cmd_test = "bundle exec spring testunit %p"
let g:rubytest_cmd_testcase = "bundle exec spring testunit %p -n '/%c/'"

Using Zeus

Note that Zeus is not typically run from within the project's bundle context, so bundle exec is omitted from example

let g:rubytest_cmd_test = "zeus test %p"
let g:rubytest_cmd_testcase = "zeus test %p -n '/%c/'"

Placeholders:

  • %p: path of test file

  • %c: test case name

  • %s: only for minitest, replaced by closest suite name (class whose name begin with 'Test'). This can be used to match test case more exactly:

    let g:rubytest_cmd_testcase = "ruby %p -n '%s#%c'"

Default Key Bindings

  • <Leader>t: run test case under cursor
  • <Leader>T: run all tests in file
  • <Leader>l: run the last test, from any buffer

You can change default key bindings:

map <Leader>\ <Plug>RubyTestRun     " change from <Leader>t to <Leader>\
map <Leader>] <Plug>RubyFileRun     " change from <Leader>T to <Leader>]
map <Leader>/ <Plug>RubyTestRunLast " change from <Leader>l to <Leader>/

Tip

Contributors

  • Bogdan Gusiev
  • Yung Hwa Kwon (nowk)
  • J. Weir
  • Ben Simpson (bsimpson)
  • Alexander Belyaev (alexbel)
  • Ivan Tkalin (ivalkeen)
  • Dejan Simić (dejan)

vim-rubytest's People

Contributors

bogdan avatar bsimpson avatar dejan avatar ivalkeen avatar jweir avatar martijnbolhuis avatar nashbridges avatar nowk avatar weexpectedthis avatar wkrsz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vim-rubytest's Issues

<leader> t for spec files produces wrong rspec command

Say I have a rails model post.rb and a spec post_spec.rb.

If I input <leader>T while the post_spec.rb buffer is open, the command is as follows:

rspec spec/models/post_spec.rb  -l 16

This works just fine.

However, let's say I input <leader>t while my cursor is on line 16 of the spec. This is the following command:

rspec spec/models/post_spec.rb  -l 16

However, the actual command should be:

rspec spec/models/post_spec.rb:16

I have the current version of rspec installed, 3.4.1. Let me know if you need any other pieces of information.

Quickfix output not allowing first error to be opened

After setting let g:rubytest_in_quickfix = 1 everything looked to function as expected:

  • Run test
  • Errors added to quickfix

However when the output finishes and the first error is opened the following happens:

screenshot 2014-10-15 10 12 27

It looks like the filename is getting prepended with [ which is leading to the inability to open the actual file.

I am a quickfix noob and tried to use :set modifiable in hopes that I could just remove the [ char and the file would open as desired. Hopefully someone has seen this issue before and there is a quick fix. (in the meantime I'll dig into the code and see if anything stands out)

Investigation
How quickfix list is created in the ExecTest(cmd) function

cex system(cmd)

<leader>t fails if in directory with a space in it

The code I'm editing is at "/home/joe/Rails Projects/myproject/test/unit/auth_test.rb" When I run t I get a "ruby: No such file or directory /home/joe/Rails" error.

It looks like rubytest can't handle spaces in the directory

test results disappear immediately

I'm sure this is my local problem, but when I run a single unit test (leader-t, which I have remapped to leader-\ ) the tests run in a new split window at the bottom of macvim, but as soon as they complete, they disappear - so you can't see the results.

This happens regardless of whether the test passes or fails.

This is not in the quickfix window, this is in the default mode.

I'm just trying to get to grips with vim, and I really can't figure this out. Any pointers?

I have the janus plugin bungle installed, and my .vimrc.before looks like this:

map \ RubyTestRun " change from t to
map ] RubyFileRun " change from T to ]
map / RubyTestRunLast " change from l to /

and the .vimrc.after looks like this:

" launch peepopen via command T
if has("gui_macvim")
map PeepOpen
end

" execute the current file as ruby with command R
map :!ruby %

" don't run the rubytest actions in the quickfix window
let g:rubytest_in_quickfix = 0

color pastelsondark
set gfn=Monaco:h12

" disable the macvim toolbar
if has("gui_macvim")
set guioptions=egmrt
endif

" show / hide NERDTree with \d
nnoremap d :NERDTreeToggle

" remove trailing spaces with \s
nnoremap s :%s/\s+$//e

" remove trailing spaces when saving any ruby file
autocmd BufWritePre *rb :%s/\s+$//e

Unproperly incorporating %c in MiniTest::Spec style syntax.

I use this plugin with MiniTest::Spec.
I added new variables to my vimrc as follows:

let g:rubytest_cmd_spec = "ruby %p"
let g:rubytest_cmd_example = "ruby %p -n /%c/"

When I run the testcase(spec) by pressing t,
It seems it doesn't reflect proper spec.
Seems doesn't detect the proper line properly.

Segfault in cucumber file

I'm getting this segfault when hitting -t in a cucumber feature:

cucumber features/sign_up.feature -n Create an account from the homepage                                                                                         
/Users/adarsh/.rvm/gems/ruby-1.9.3-p125/gems/json-1.6.5/ext/json/ext/json/ext/parser.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

Command terminated

Press ENTER or type command to continue

I'm using ruby 1.9.3p125 so this error confuses me.

Call 52_RunLast(), but no response.

I use Vim 7.4 and writing cucumber features for a rails app. I use the default mapping, ,t nad ,T works both fine, but ,l not. it only shows :call <SNR>52_RunLast() under the status line, but not running the last feature.

I suppose this maybe a bug, please take a look into it, thanks.

Using ruby-test with rvm results in load path issues

I am currently running the git master version of ruby-test and using a
rvm gemset with 1.9.3 ruby. From the cli everything works but when hitting \t or \T

I get an error in the form of:
~/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb|36| in `require': cannot load such file -- spork (LoadError)

Is this a known issue or am I doing something wrong? (which I guess seems very plausible)

-I and -r should not be added to test command

On line 88, I see the test command defined by the user (or the script default) is replaced with one that includes -Itest -rtest_helper.

This is bad for me for two reasons:

  1. My work app already requires test_helper fully qualified in-test so this results in warnings about reassigning constants
  2. Some of my apps don't have a test_helper so I can't use this plugin without touching an empty one

If -Iwhatever and -rwhatever are needed, the user can add them using your configuration options.

This looked intentional so I thought an Issue vs a Pull req would be better since there might be an explanation for it.

Thanks!

Quickfix Mode doesn't work

When attempting to output results to Quickfix, the plugin simply echos call <72>Run(1). Nothing else happens and the quickfix buffer remains empty.

Use exact match instead of pattern match for running single tests

I've noticed that many Vim ruby test runners use something like this to run individual Test::Unit cases:

let g:rubytest_cmd_testcase = "ruby %p -n '/%c/'"

I'm not sure if there's a reason for the // in this command, but it causes multiple tests to run when the name of one test is a substring of the name of another test. For example, if you have the following:

def test_foo; end
def test_foo_bar; end
def test_foo_baz; end

...then there is no way to run test_foo alone. It will run all three tests.

Simply omitting the // here will make it run the desired single test.

Is there something I'm missing or is this just a convention that's been carried over from earlier test runners?

Loading test_helper fails when rubytest_cmd is set to use bundle exec

The problem is that the "test" directory is not added to my LOAD_PATH when the rubytest_cmd_* does not start with "ruby".

In my vimrc I use bundle exec when running my ruby tests:

let g:rubytest_cmd_test = "bundle exec ruby %p"
let g:rubytest_cmd_testcase = "bundle exec ruby %p -n '/%c/'"

When I run a single test case I get the following:

bundle exec ruby test/controllers/training_controller_test.rb -n /test_get_content_inserts_base_tag_if_none_exists/
test/controllers/training_controller_test.rb:1:in `require': cannot load such file -- test_helper (LoadError)
        from test/controllers/training_controller_test.rb:1:in `<main>'

shell returned 1

Changing this line to: let cmd = substitute(cmd, 'ruby ', 'ruby -Itest ', '') fixes my issue. I can submit a PR but wanted to ask for thoughts on a better way to handle this.

Closes the terminal before I can see results

When I run my tests the tests run fine, but where it should wait for me to press a key to close the terminal window it does not wait, so I can never see the results of my tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.