Splot
Tired of having to reconfigure how you run tests for each project? Annoyed that Minitest::Unit doesn't let you supply a line number? Want to press a single button in your text editor of choice, and run the test most relevant to the file you're editing? If you answered yes to any of these, then splot is for you.
Installation
Add this line to your application's Gemfile:
gem 'splot', require: false
And then execute:
$ bundle
Or install it yourself as:
$ gem install splot
Usage
First, play with splot on the command line. Jump into a project root directory. Want to run a test? Try this:
splot -f test/models/foo_test.rb
Do you use rspec? Nothing changes, except for the path to the file.
splot -f spec/models/foo_spec.rb
Want to run a test on a specific line? No problem:
splot -f test/models/foo_test.rb -l 44
splot -f spec/models/foo_spec.rb -l 44
When using Test::Unit, splot will automatically figure out the name of the test corresponding to the line number you give.
Now, you need a faster feedback loop, so you decide you want a preloader:
splot -f test/models/foo_test.rb -p zeus
That's about all there is to the command line!
Running relevant tests
Editing app/models/foo.rb? splot can figure out which test to run:
splot -f app/models/foo.rb
In this case, it'll look for a test at test/models/foo_test.rb or spec/models/foo_spec.rb. This way, you can shove whatever file you happen to be looking at in your text editor at splot and it will "just work."
vim-dispatch integration
I'm a huge fan of vim dispatch. Here's my .vimrc entries that bind <F5> to "run the test at the current cursor position" and <F6> to "run the whole test file," respectively:
:map <f5> :w <cr> :execute "Dispatch splot -p spring -f % -l " . ( line(".") + 1 )<cr>
:map <f6> :w <cr> :Dispatch splot -p spring -f %<cr>
Notes and planned features
- When invoking a
Test::Unittest,splotdefaults to using therake test. This is to be compatible with preloaders likespringorzeus. - There is cucumber support, too. I hope it works.
- I'm planning on adding git integration. Think "auto stage my changes if the tests pass."
vim-dispatchseems to be unaware of when a test run passes, causing the "quickfix window" to stick around, even when there isn't a failure. I can potentially work around it insplot.- I may write a small vim plugin to simplify the above dispatch mappings. It doesn't seem super necessary at this point, and I like to keep my plugin list small.
- I'd like to implement project level configuration. That way, you can store the information necessary to teach
splothow to run your tests inside your project, kind of like how aruby-versionfile configures the version of ruby you use. - More context specific handlers. For example, running
sploton a.gemspecfile should build the gem (if the tests all pass). Ideally, this would be extensible and not bundled in this gem.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request