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
116
117
118
|
# File 'lib/corundum/rspec.rb', line 57
def define
super
in_namespace do
desc "Always run every spec"
test_task(:all)
desc "Generate specifications documentation"
@report_task = doc_task(:doc => file_dependencies) do |t|
t.rspec_opts += %w{-o /dev/null --failure-exit-code 0}
t.formats["html"] = doc_path
t.formats["json"] = json_report
end
file entry_point => :doc
file json_report => :doc
task :verify => json_report do |task|
require 'json'
require 'corundum/qa-report'
doc = JSON::parse(File::read(json_report.to_s))
rejections = QA::Report.new("RSpec[#{json_report}]")
qa_rejections << rejections
doc["examples"].find_all do |example|
example["status"] == "failed"
end.each do |failed|
file,line,_ = failed["exception"]["backtrace"].first.split(":", 3)
value = failed["exception"]["message"]
rejections.add("fail", 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
|