50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/corundum/rspec.rb', line 50
def define
super
in_namespace do
desc "Always run every spec"
test_task(:all)
desc "Generate specifications documentation"
docn = doc_task(:doc => file_dependencies) do |t|
t.rspec_opts = %w{-o /dev/null --failure-exit-code 0 -f h -o} + [t.doc_path]
end
file entry_path => :doc
task :verify => entry_path do |task|
require 'nokogiri'
require 'corundum/qa-report'
doc = Nokogiri::parse(File::read(entry_path))
rejections = QA::Report.new("RSpec[#{entry_path}]")
qa_rejections << rejections
def class_xpath(name)
"contains(concat(' ', normalize-space(@class), ' '), '#{name}')"
end
fails_path = "//*[" + %w{example failed}.map{|kind| class_xpath(kind)}.join(" and ") + "]"
doc.xpath(fails_path).each do |node|
backtrace_line =
node.xpath(".//*[#{class_xpath("backtrace")}]").first.content.split("\n").first
file,line,_ = backtrace_line.split(":")
label = "fail"
value = node.xpath(".//*[#{class_xpath("message")}]").first.content.gsub(/\s+/m, " ")
rejections.add(label, file, line, value)
end
unless rejections.empty?
rejections.fail "Spec fails, none allowed"
end
end
desc "Run only failing examples listed in last_run"
test_task(:quick) do |t|
examples = []
begin
File.open("last_run", "r") do |fail_list|
fail_list.each_line.grep(%r{^\s*\d+\)\s*(.*)}) do |line|
examples << $1.gsub(/'/){"[']"}
end
end
rescue
end
unless examples.empty?
t.rspec_opts << "--example"
t.rspec_opts << "\"#{examples.join("|")}\""
end
t.failure_message = "Spec examples failed."
end
end
desc "Run failing examples if any exist, otherwise, run the whole suite"
task root_task => in_namespace(:quick)
task :run_quality_assurance => in_namespace(:verify)
task :run_continuous_integration => in_namespace(:verify)
end
|