aboutsummaryrefslogtreecommitdiff
path: root/vim/plugin/vim-rspec.rb
blob: 4d7f4c3c2dc1c8db687e54d34dc834607f189f77 (plain)
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
require "rubygems"
require "hpricot"

doc		= Hpricot(STDIN.read)
h1			= (doc/"h1")
classes	= {"spec passed"=>"+","spec failed"=>"-","spec not_implemented"=>"#"}

puts "* #{h1.inner_html}"

stats = (doc/"script").select {|script| script.innerHTML =~ /duration|totals/ }.map {|script| script.inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"") }
stats.each do |stat|
	puts "* #{stat.gsub(/\"/,'')}"
end
puts "* Parsed with Hpricot (http://wiki.github.com/why/hpricot)"
puts " "

(doc/"div[@class='example_group']").each do |example|
	puts "[#{(example/"dl/dt").inner_html}]"
	(example/"dd").each do |dd|
		txt = (dd/"span:first").inner_html
		puts "#{classes[dd[:class]]} #{txt}"
		next if dd[:class]!="spec failed"
		failure  = (dd/"div[@class='failure']")
		msg		= (failure/"div[@class='message']/pre").inner_html
		back		= (failure/"div[@class='backtrace']/pre").inner_html
		ruby		= (failure/"pre[@class='ruby']/code").inner_html.scan(/(<span class="linenum">)(\d+)(<\/span>)([^<]+)/).map {|elem| "  "+elem[1]+": "+elem[3].chomp+"\n"}.join
		puts "  #{msg}"
		puts "  #{back}"
		puts ruby
	end
	puts " "
end