-
-
Save mikebridge/1297022 to your computer and use it in GitHub Desktop.
RSpec formatter for Emacs E-x compile feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
return nil if configuration.cleaned_from_backtrace?(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