Skip to content

Instantly share code, notes, and snippets.

@kiyoka
Created August 22, 2011 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kiyoka/1163731 to your computer and use it in GitHub Desktop.
Save kiyoka/1163731 to your computer and use it in GitHub Desktop.
RSpec formatter for Emacs E-x compile feature
require 'rspec/core/formatters/progress_formatter'
# Example of a formatter with custom bactrace printing. Run me with:
# ruby bin/spec xxxxx.rb -r ./test/rspec_formatter_for_emacs.rb -f CustomFormatter
class CustomFormatter < RSpec::Core::Formatters::ProgressFormatter
def backtrace_line(line)
str = line.gsub(/([^:]*\.rb):([0-9]+):in /) do
path = "#{$1}"
lineno = "#{$2}"
if path.match( /lib/ ) and path.match( /rspec/ )
"#{File.expand_path(path)}:#{lineno} IN "
else
"#{File.expand_path(path)}:#{lineno}:in "
end
end
str
end
def dump_backtrace(example)
format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info|
output.puts cyan(" #{backtrace_info}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment