17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/rspec/covers/rake_task.rb', line 17
def install
namespace :covers do
desc "Print an rspec-covers JSON report summary"
task :report, [:path] do |_task, args|
path = args[:path] || RSpec::Covers.configuration.report_path || ".rspec-covers/result.json"
report = JSON.parse(File.read(path))
summary = report.fetch("summary")
puts "examples: #{summary.fetch("examples")}"
puts "risky: #{summary.fetch("risky")}"
puts "suggestions: #{summary.fetch("suggestions")}"
puts "declaration_warnings: #{summary.fetch("declaration_warnings", 0)}"
puts "orphan_methods: #{summary.fetch("orphan_methods", 0)}"
end
desc "Print covers metadata suggestions from an rspec-covers JSON report"
task :suggest, [:path] do |_task, args|
path = args[:path] || RSpec::Covers.configuration.report_path || ".rspec-covers/result.json"
report = JSON.parse(File.read(path))
report.fetch("examples").each do |example|
example.fetch("suggestions").each do |suggestion|
puts "#{example.fetch("file")}:#{example.fetch("line")}"
puts " suggestion: covers: #{suggestion.fetch("label").inspect} " \
"(score #{suggestion.fetch("score")}: #{suggestion.fetch("reasons").join(" + ")})"
end
end
end
desc "Evaluate suggestion precision/recall/F1 against ground truth JSON"
task :evaluate, [:ground_truth, :predictions] do |_task, args|
unless args[:ground_truth] && args[:predictions]
raise ArgumentError, "usage: rake covers:evaluate[ground_truth.json,predictions.json]"
end
result = Evaluation.evaluate(
ground_truth_path: args[:ground_truth],
predictions_path: args[:predictions]
)
puts JSON.pretty_generate(result)
end
end
end
|