Skip to content

Instantly share code, notes, and snippets.

@rubiii
Created December 2, 2012 11:14
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rubiii/4188254 to your computer and use it in GitHub Desktop.
Save rubiii/4188254 to your computer and use it in GitHub Desktop.
MacVim-Formatter for RSpec
$ rspec --format MacVimFormatter --color spec

How it works

MacVim registers the mvim url handler to open files and directly jump to lines and columns.
We can use this to convert stacktraces reported by RSpec into clickable mvim-links.

screenshot

MacVim

Requires at least MacVim 7.3. To change how MacVim opens external files go to
'Preferences' > 'Open files from applications' and select 'in the current window' and from
the dropdown menu select 'and set the arglist' to open the file in the last active buffer.

iTerm2

Cmd-Click on an mvim-link to open the file.

require "rspec/core/formatters/progress_formatter"
class MacVimFormatter < RSpec::Core::Formatters::ProgressFormatter
def dump_backtrace(example)
format_backtrace(example.execution_result[:exception].backtrace, example.metadata).each do |backtrace_info|
backtrace_split = backtrace_info.split(":")
file = backtrace_split[0] # the file
file = file[2..-1] # remove ./ from the beginning of the file
file = File.join Dir.pwd, file # create an absolute path
line = backtrace_split[1] # line number
rest = backtrace_split[2..-1] # the rest
# output.puts cyan("#{long_padding}# #{backtrace_info}")
output.puts cyan("#{long_padding}# mvim://open?url=file://#{file}&line=#{line} #{rest.join(':')}")
end
end
end
@dennisreimann
Copy link

Awesome hackeria 🍰

@rubiii
Copy link
Author

rubiii commented Dec 2, 2012

😃

@lucascaton
Copy link

Awesome!

@ralph
Copy link

ralph commented Dec 2, 2012

Top! (y)

@gorkunov
Copy link

gorkunov commented Dec 2, 2012

My iTerm opens any file path in mvim (Cmd+click) by default in new buffer. I can't understand why you guys use this strange solution :)

@chendo
Copy link

chendo commented Dec 3, 2012

+1 @gorkunov.

I developed iTerm2's Semantic History feature for this very purpose. http://vimeo.com/21872771

You can Cmd+Click any path with or without a line number and it will open it in your text editor of choice.

Configure it by going to Preferences -> Profiles -> Advanced -> Semantic History.

@anthonylewis
Copy link

@chendo you just blew my mind. That is an awesome feature.

@rubiii
Copy link
Author

rubiii commented Dec 5, 2012

wow that's awesome! thanks @chendo

@rubiii
Copy link
Author

rubiii commented May 27, 2013

@chendo i just looked at the following line from an rspec test run and thought:

"what if you could click on this line and have iTerm execute the command to run the exact test again?"

rspec ./spec/wasabi/integration/data_exchange_spec.rb:21

i think this would be pretty useful and could be implemented in a pretty generic way
by extending semantic history and making it look at the command in that line.

what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment