public
Last active

MacVim-Formatter for RSpec

  • Download Gist
gistfile1.sh
Shell
1
$ rspec --format MacVimFormatter --color spec
how_it_works.md
Markdown

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.

mac_vim_formatter.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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

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 :)

+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.

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

wow that's awesome! thanks @chendo

@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?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.