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
42
43
44
45
|
# File 'lib/batcave/command/smart-edit.rb', line 6
def execute
rspec_failure = /^ *Failure\/Error/
rspec_stack_trace = /^ *# (?<path>[^:]+):(?<line>[0-9]+):/
text = capture_tmux
if text =~ rspec_failure
lines = text.split("\n")
index = lines.find_index { |l| l =~ rspec_failure }
traces = []
last_line = index
lines[index..-1].each_with_index do |line, i|
m = rspec_stack_trace.match(line)
if m
traces << Hash[m.names.zip(m.captures)]
elsif traces.count > 0 && line =~ /^ *$/
last_line = i
break
end
end
if traces.any?
candidate = traces.sort_by { |t| File.stat(t["path"]).mtime }.reverse.first
Stud::Temporary.file do |fd|
lines[index .. last_line + index].each do |line|
fd.puts(line)
end
fd.flush
system("tmux split-window -l 7 'cat #{fd.path}; sleep 3000 ' \\; last-pane")
system("#{ENV["EDITOR"]} #{candidate["path"]} +#{candidate["line"]}")
system("tmux last-pane \\; kill-pane")
end
end
end
return 0
end
|