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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/corundum/simplecov.rb', line 69
def define
super
in_namespace do
task :example_config do
$stderr.puts "Try this in #{config_path}"
$stderr.puts "(You can just do #$0 > #{config_path})"
$stderr.puts
puts config_file_contents
end
config_exists = task :config_exists do
problems = []
File::exists?(config_path) or problems << "No .simplecov (try: rake #{self[:example_config]})"
config_string = File.read(config_path)
unless config_string =~ /coverage_dir.*#{target_dir.pathname.relative_path_from(Pathname.pwd)}/
problems << ".simplecov doesn't refer to #{target_dir}"
end
unless config_string =~ /SimpleCov::Formatter::JSONFormatter/
problems << ".simplecov doesn't refer to SimpleCov::Formatter::JSONFormatter"
problems << "in your .simplecov file, either: "
problems << " add 'formatter SimpleCov::Formatter::JSONFormatter'"
problems << " or"
problems << " add 'SimpleCov::Formatter::JSONFormatter' to an existing"
problems << " 'formatter SimpleCov::Formatter::MultiFormatter'"
end
fail problems.join("\n") unless problems.empty?
end
class << config_exists
attr_accessor :config_path
def timestamp
if File.exist?(config_path)
File.mtime(config_path.to_s)
else
Rake::EARLY
end
end
end
config_exists.config_path = config_path
@test_lib.report_task.rspec_opts << "-r simplecov"
file entry_point => @test_lib.report_task.name
file coverage_json => @test_lib.report_task.name
@test_lib.report_task. << coverage_json
task :verify_coverage => coverage_json do
require 'json'
require 'corundum/qa-report'
doc = JSON::parse(File::read(coverage_json.to_s))
percentage = doc["metrics"]["covered_percent"]
report = QA::Report.new("Coverage")
report.summary_counts = false
report.add("percentage", entry_point, nil, percentage.round(2))
report.add("threshold", entry_point, nil, threshold)
qa_rejections << report
if percentage < threshold
report.fail "Coverage below threshold"
end
end
task :find_stragglers => coverage_json do
require 'json'
require 'corundum/qa-report'
doc = JSON::parse(File::read(coverage_json.to_s))
pwd = Pathname.pwd
covered_files = doc["files"].map{|f| Pathname.new(f["filename"]).relative_path_from(pwd).to_s}
need_coverage = code_files.find_all(&coverage_filter)
report = QA::Report.new("Stragglers")
qa_rejections << report
(covered_files - need_coverage).each do |file|
report.add("Not in gemspec", file)
end
(need_coverage - covered_files).each do |file|
report.add("Not covered", file)
end
unless report.empty?
report.fail "Covered files and gemspec manifest don't match"
end
end
end
task @test_lib.report_task.name => in_namespace(:config_exists)
task @test_lib.report_task.name => all_files
task :preflight => in_namespace(:config_exists)
task :run_quality_assurance => in_namespace(:verify_coverage, :find_stragglers)
task :run_continuous_integration => in_namespace(:verify_coverage, :find_stragglers)
end
|