├── Guardfile.sample ├── README.markdown ├── spec └── support │ └── formatters │ └── vim_formatter.rb └── vim-rspec-quickfix.png /Guardfile.sample: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | rspec_quick = ' rspec ' 5 | rspec_quick << ' --require=support/formatters/vim_formatter.rb ' 6 | rspec_quick << ' --format VimFormatter ' 7 | rspec_quick << ' --out quickfix.out ' 8 | rspec_quick << ' --format progress ' 9 | 10 | guard :rspec, cmd: rspec_quick do 11 | watch(%r{^spec/.+_spec\.rb$}) 12 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } 13 | watch('spec/spec_helper.rb') { "spec" } 14 | 15 | # Rails example 16 | watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 17 | watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } 18 | watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } 19 | watch(%r{^spec/support/(.+)\.rb$}) { "spec" } 20 | watch('config/routes.rb') { "spec/routing" } 21 | watch('app/controllers/application_controller.rb') { "spec/controllers" } 22 | end 23 | 24 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # VIM Rspec Quickfix 2 | > Get your rspec errors in VIM's quickfix 3 | 4 | ## TL;DR, A Screen Shot 5 | ![vim-rspec-quickfix](https://raw.github.com/dapplebeforedawn/vim-rspec-quickfix/master/vim-rspec-quickfix.png) 6 | 7 | ## Installation 8 | This repo is more of a how-to, than packaged sofware. Imma show you how to do it, but once you see how all the pieces fit togeather, you gotta adapt it how you like. Don't worry ruby, VIM and rspec all play by the unix rule, "streams of text", so it's really simple! 9 | 10 | **In your shell:** 11 | ```bash 12 | # Setup the spec formatter, so VIM can read rspec's output: 13 | cp spec/support/formatters/VIM_formatter.rb YOURREPO/spec/support/formatters/vim_formatter.rb 14 | 15 | # Run rspec with the formatter, and put the output where VIM can get it. 16 | # (rspec lets you specify more than one formatter, so we still get nice 17 | # documentation/progress output too! ) 18 | rspec --require=support/formatters/VIM_formatter.rb --format VimFormatter --out quickfix.out --format progress 19 | 20 | # `quickfix.out` now has the VIM-friendly spec output. 21 | ``` 22 | 23 | **In VIM:** 24 | ``` 25 | # ( these are all VIM built-in commands ) 26 | :cg quickfix.out # load the quickfix file (you'll need to do this everytime the specs run) 27 | :cwindow # open the quickfix 28 | 29 | # In the quickfix buffer 30 | :cn # Jump to the first failure 31 | : # Jump to a specific failure 32 | 33 | # From any buffer 34 | :ccl # Close the quickfix 35 | 36 | # BONUS POINTS: 37 | :map s :cg quickfix.out \| cwindow #use leader-s to reload the file and open the quickfix 38 | ``` 39 | 40 | ## Working with Guard 41 | Yea, this works with Guard too, cause @mikegee loves guard. 42 | 43 | **In your Guardfile:** 44 | ``` 45 | # Requires guard >= 2.0.0 46 | 47 | rspec_quick = ' rspec ' 48 | rspec_quick << ' --require=support/formatters/VIM_formatter.rb ' 49 | rspec_quick << ' --format VimFormatter ' 50 | rspec_quick << ' --out quickfix.out ' 51 | rspec_quick << ' --format progress ' 52 | 53 | guard :rspec, cmd: rspec_quick do 54 | # normal guard config stuffs 55 | end 56 | ``` 57 | 58 | ## Konami Code: 59 | I generally dislike extensive extra-app tooling like guard. I also dislike leaving VIM to run rspec. So, lets map the mother of all leader commands: 60 | ``` 61 | # Run the specs, and open the updated quickfix on `s` 62 | :map s :call system('rspec --require=support/formatters/VIM_formatter.rb --format VimFormatter --out quickfix.out --format progress') \| cg quickfix.out \| cwindow 63 | 64 | # or, without the temp file: 65 | :map s :cgete system('rspec --require=support/formatters/vim_formatter.rb --format VimFormatter') \| cwindow 66 | ``` 67 | -------------------------------------------------------------------------------- /spec/support/formatters/vim_formatter.rb: -------------------------------------------------------------------------------- 1 | # Adapted from https://github.com/bronson/vim-runtest/blob/master/rspec_formatter.rb. 2 | require 'rspec/core/formatters/base_text_formatter' 3 | 4 | class VimFormatter < RSpec::Core::Formatters::BaseTextFormatter 5 | 6 | def example_failed example 7 | exception = example.execution_result[:exception] 8 | path = $1 if exception.backtrace.find do |frame| 9 | frame =~ %r{\b(spec/.*_spec\.rb:\d+)(?::|\z)} 10 | end 11 | message = format_message exception.message 12 | path = format_caller path 13 | output.puts "#{path}: #{example.example_group.description.strip} " + 14 | "#{example.description.strip}: #{message.strip}" if path 15 | end 16 | 17 | def example_pending *args; end 18 | def dump_failures *args; end 19 | def dump_pending *args; end 20 | def message msg; end 21 | def dump_summary *args; end 22 | def seed *args; end 23 | 24 | private 25 | 26 | def format_message msg 27 | msg.gsub("\n", ' ')[0,80] 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /vim-rspec-quickfix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markjlorenz/vim-rspec-quickfix/ccdfa0e5d13b3a42ac456b67d6eef6eb0a6cb218/vim-rspec-quickfix.png --------------------------------------------------------------------------------