Skip to content

Commit 745ed2a

Browse files
author
Yan Pritzker
committed
Merge pull request #8 from thenoseman/master
* Make it work with rspec2 and rspec1 * Allow lines in output to be ignored * Automatically find which window has the spec file
2 parents cea6657 + a523326 commit 745ed2a

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

plugin/lib/context_renderer.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
# -*- encoding : utf-8 -*-
12
class RSpecContextRenderer
23
# context: an html representation of an rspec context from rspec output
34
# counts: a hash with :passed, :failed, :not_implemented counters
45
def initialize(context, counts)
56
@context=context
67
@counts=counts
7-
8+
@classes = {"passed"=>"+","failed"=>"-","not_implemented"=>"#"}
89
render_context_header
910
render_specs
1011
puts " "
@@ -18,15 +19,15 @@ def render_context_header
1819
def render_specs
1920
(@context/"dd").each do |dd|
2021
render_spec_descriptor(dd)
21-
FailureRenderer.new(dd/"div[@class='failure']") if dd[:class]=="spec failed"
22+
FailureRenderer.new(dd/"div[@class~='failure']") if dd[:class] =~ /failed/
2223
end
2324
end
2425

2526
def render_spec_descriptor(dd)
26-
classes = {"spec passed"=>"+","spec failed"=>"-","spec not_implemented"=>"#"}
2727
txt = (dd/"span:first").inner_html
28-
puts "#{classes[dd[:class]]} #{txt}"
29-
outcome = dd[:class].gsub(/\s*spec\s*/,'').to_sym
28+
clazz = dd[:class].gsub(/(?:example|spec) /,'')
29+
puts "#{@classes[clazz]} #{txt}"
30+
outcome = clazz.to_sym
3031
@counts[outcome] += 1
3132
end
3233
end

plugin/lib/failure_renderer.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding : utf-8 -*-
12
class FailureRenderer
23
include StringUtil
34

@@ -21,7 +22,7 @@ def failure_location
2122
end
2223

2324
def failure_message
24-
indent(unescape((@failure/"div[@class='message']/pre").inner_html.gsub(/\n/,'').gsub(/\s+/,' ')))
25+
indent(unescape((@failure/"div[@class~='message']/pre").inner_html.gsub(/\n/,'').gsub(/\s+/,' ')))
2526
end
2627

2728
def backtrace_details
@@ -36,7 +37,11 @@ def backtrace_details
3637
end
3738

3839
def backtrace_lines
39-
(@failure/"pre[@class='ruby']/code").inner_html.scan(/(<span class="linenum">)(\d+)(<\/span>)(.*)/)
40+
(@failure/"pre[@class='ruby']/code").inner_html.scan(/(<span class="linenum">)(\d+)(<\/span>)(.*)/).reject { |line| line[3] =~ ignore_line_if_matches }
41+
end
42+
43+
def ignore_line_if_matches
44+
/install syntax to get syntax highlighting/
4045
end
4146

4247
end

plugin/vim-rspec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding : utf-8 -*-
12
require "rubygems"
23
require "hpricot"
34
require 'cgi'
@@ -25,6 +26,7 @@ def render_header
2526
stats.map! do |script|
2627
script.inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"").gsub(/\"/,'')
2728
end
29+
# results in ["Finished in 0.00482 seconds", "2 examples, 1 failure"]
2830
failure_success_messages,other_stats = stats.partition {|stat| stat =~ /failure/}
2931
render_red_green_header(failure_success_messages.first)
3032
other_stats.each do |stat|
@@ -51,7 +53,7 @@ def render_red_green_header(failure_success_messages)
5153
end
5254

5355
def render_examples
54-
(@doc/"div[@class='example_group']").each do |context|
56+
(@doc/"div[@class~='example_group']").each do |context|
5557
RSpecContextRenderer.new(context, @counts)
5658
end
5759
end

plugin/vim-rspec.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ function! s:SwitchToWindowByName(buffername)
182182
endfunction
183183

184184
function! s:TryToOpen()
185+
" Search up to find '*_spec.rb'
186+
call search("_spec","bcW")
185187
let l:line = getline(".")
186-
if match(l:line,'^ [\/\.]')<0
187-
call s:error_msg("No file found.")
188+
if match(l:line,'^ .*_spec.rb')<0
189+
call s:error_msg("No spec file found.")
188190
return
189191
end
190192
let l:tokens = split(l:line,":")

test/test_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- encoding : utf-8 -*-
2+
class TestVimRspec
3+
def testme
4+
true
5+
end
6+
end
7+
describe "vim-rspec" do
8+
it "shows failures in red" do
9+
false.should == TestVimRspec.new.testme
10+
end
11+
12+
it "shows successes in green" do
13+
true.should be_true
14+
end
15+
16+
xit "shows pending specs in yellow"
17+
end

0 commit comments

Comments
 (0)