Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # vi: ft=ruby
  3.  
  4. RSPEC_CMD = 'bundle exec rspec --no-color'
  5. VIM_CMD = 'gvim'
  6. EXTRA_FILE_WITH = 'e' # use sp to split open
  7.  
  8. # Append additional command line argument to rspec command
  9. rspec_command = ARGV.unshift(RSPEC_CMD).join(' ')
  10.  
  11. file_lines, last_trace = [], {}
  12. `#{rspec_command}`.split("\n").each do |line|
  13. mat = line.match(/\A\s*\#\s+(.+):(\d+)/)
  14. if mat # matched a backtrace line
  15. last_trace[mat[1]] = mat[2]
  16. next
  17. end
  18.  
  19. mat = line.match(/\Arspec\s+(.+):(\d+)/)
  20. next unless mat
  21. file, line = mat[1], last_trace[mat[1]]
  22. file_lines << "+#{line} #{file}"
  23. end
  24.  
  25. exit if file_lines.empty? # no error detected
  26.  
  27. # add files with line number to open by vim
  28. vim_command = [VIM_CMD, file_lines.shift]
  29. file_lines.each { |f| vim_command << %Q|+"#{EXTRA_FILE_WITH} #{f}"| }
  30.  
  31. # execute the vim command
  32. system vim_command.join(' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement