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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/corundum/simplecov.rb', line 68
def define
in_namespace do
file "Rakefile"
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
task :config_exists do
File::exists?(File::join(Rake::original_dir, ".simplecov")) or fail "No .simplecov (try: rake #{self[:example_config]})"
end
directory File::dirname(report_path)
RSpecReportTask.new(@test_lib) do |t|
t.task_name = report_path
t.rspec_opts += %w{-r simplecov}
end
file report_path => all_files
task :generate_report => [:preflight, report_path]
desc "View coverage in browser"
BrowserTask.new(self) do |t|
t.index_html = report_path
end
task :verify_coverage => :generate_report do
require 'nokogiri'
doc = Nokogiri::parse(File::read(report_path))
coverage_total_xpath = "//span[@class='covered_percent']/span"
percentage = doc.xpath(coverage_total_xpath).first.content.to_f
raise "Coverage must be at least #{threshold} but was #{percentage}" if percentage < threshold
puts "Coverage is #{percentage}% (required: #{threshold}%)"
end
task :find_stragglers => :generate_report do
require 'nokogiri'
doc = Nokogiri::parse(File::read(report_path))
covered_files = doc.xpath(
"//table[@class='file_list']//td//a[@class='src_link']").map do |link|
link.content
end
need_coverage = @code_files.find_all(&coverage_filter)
not_listed = covered_files - need_coverage
not_covered = need_coverage - covered_files
unless not_listed.empty? and not_covered.empty?
raise ["Covered files and gemspec manifest don't match:",
"Not in gemspec: #{not_listed.inspect}",
"Not covered: #{not_covered.inspect}"].join("\n")
end
end
end
task :preflight => in_namespace(:config_exists)
task :qa => in_namespace(:verify_coverage, :find_stragglers)
end
|