Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0629ea8

Browse files
Made the plugin more robust against output done from within the rspec tests:
- The formatter wraps progress indicators in "<progress></progress>" tags - The Vim script extracts those indicators from the tags and clears the tags at the end
1 parent 95d532b commit 0629ea8

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

plugin/sweet-vim-rspec.vim

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function! s:PollingSystemCall(systemcall)
139139
let pid = system(a:systemcall . " > " . output_file . " & echo $!") " the echo $! returns the process id
140140
let running = 1
141141
while running
142-
let progress = system("cat " . output_file . " | head -1")
142+
let progress = s:ExtractProgressIndicators(system("cat " . output_file))
143143
let old_length = progress_length
144144
let progress_length = strlen(progress)
145145
let new_output = strpart(progress, old_length, progress_length - old_length)
@@ -148,11 +148,34 @@ function! s:PollingSystemCall(systemcall)
148148
sleep 100m
149149
endwhile
150150
echohl Special | echon " √Done" | echohl Normal
151-
let result = readfile(output_file)[1:] " Omitting the first line, since it contains the progress indicators
151+
let result = s:FilterProgressIndicatorWrappers(readfile(output_file))
152152
call delete(output_file)
153153
return result
154154
endfunction
155155

156+
" The formatter wraps every .,F or * in a <progress></progress> tag pair.
157+
" That way potential output that is done by the RSpec test itself can be
158+
" ignored
159+
function! s:ExtractProgressIndicators(string)
160+
let result = ""
161+
let start = 0
162+
while start != -1
163+
let start = match(a:string, '\c<progress>\zs\(.\{1,1}\)\ze<\/progress>', start)
164+
if start != -1
165+
let result .= strpart(a:string, start, 1)
166+
endif
167+
endwhile
168+
return result
169+
endfunction
170+
171+
function! s:FilterProgressIndicatorWrappers(list)
172+
let result = []
173+
for line in a:list
174+
call add(result, substitute(line, '<\/\?progress>', "", "g"))
175+
endfor
176+
return result
177+
endfunction
178+
156179
function! s:ColoredOutput(string)
157180
let i = 0
158181
while i < len(a:string)

plugin/sweet_vim_rspec2_formatter.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class SweetVimRspecFormatter < BaseTextFormatter
88
@@passes = []
99
@@pending = []
1010

11+
def my_print(string)
12+
output.print "<progress>#{string}</progress>"
13+
end
14+
1115
def example_failed(example)
1216
data = ""
1317
data << "+-+ "
@@ -23,7 +27,7 @@ def example_failed(example)
2327
data << exception.backtrace.join("\n")
2428
data << "\n-+-\n" * 2
2529
@@failures << data
26-
output.print "F"
30+
my_print "F"
2731
end
2832

2933
def example_pending(example)
@@ -35,23 +39,23 @@ def example_pending(example)
3539
data << example.location + ": in `#{example.description}'"
3640
data << "\n\n-+-\n"
3741
@@pending << data
38-
output.print "*"
42+
my_print "*"
3943
end
4044

4145
def example_passed(example)
4246
if ENV['SWEET_VIM_RSPEC_SHOW_PASSING'] == 'true'
4347
@@passes << "[PASS] #{example.full_description}\n"
4448
end
45-
output.print "."
49+
my_print "."
4650
end
4751

4852
def dump_failures
49-
output.puts @@failures.join("")
53+
my_print @@failures.join("")
5054
end
5155

5256
def dump_pending
53-
output.puts
54-
output.puts @@pending.join("")
57+
my_print "\n"
58+
my_print @@pending.join("")
5559
end
5660

5761
def message msg; end

0 commit comments

Comments
 (0)