Skip to content

Instantly share code, notes, and snippets.

@cantin
Forked from rubiii/how_it_works.md
Created December 3, 2012 03:12
Show Gist options
  • Save cantin/4192396 to your computer and use it in GitHub Desktop.
Save cantin/4192396 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment