-
Notifications
You must be signed in to change notification settings - Fork 5
/
vim_rspec2_formatter.rb
41 lines (34 loc) · 1.18 KB
/
vim_rspec2_formatter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'rspec/core/formatters/base_text_formatter'
class VimFormatter < RSpec::Core::Formatters::BaseTextFormatter
def example_failed(example)
exception = example.execution_result[:exception]
spec_path = $1 if exception.backtrace.find do |frame|
frame =~ %r{\b(spec/.*_spec\.rb:\d+)(?::|\z)}
end
message = format_message exception.message
path = format_caller spec_path
output.puts message.strip if path
output.puts "#{spec_path}: #{example.example_group.description.strip} #{example.description.strip}" if path
output.puts remove_spec_from_backtrace(format_backtrace(exception.backtrace, example), spec_path)
end
def example_pending *args; end
def dump_failures *args; end
def dump_pending *args; end
def message msg; end
def dump_summary *args; end
def seed *args; end
private
def format_message msg
msg.gsub('\\n', "\n").gsub(/[\n]+/, ' ').gsub(/[ ]+/, ' ')
end
def remove_spec_from_backtrace(backtrace, spec_path)
custom_format_backtrace(backtrace).reject { |line|
line.match(/#{spec_path}/)
}
end
def custom_format_backtrace(backtrace)
backtrace.map do |line|
line.gsub('./', '')
end
end
end