Class: RSpec::Hermetic::EvaluationTask

Inherits:
Object
  • Object
show all
Extended by:
Rake::DSL
Defined in:
lib/rspec/hermetic/evaluation_task.rb,
sig/rspec/hermetic.rbs

Constant Summary collapse

DEFAULT_OUTPUT =

Returns:

  • (String)
"tmp/rspec_hermetic_evaluation.json"

Class Method Summary collapse

Class Method Details

.install(name = "hermetic:evaluate") ⇒ Object

Parameters:

  • name (String) (defaults to: "hermetic:evaluate")

Returns:

  • (Object)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec/hermetic/evaluation_task.rb', line 15

def self.install(name = "hermetic:evaluate")
  namespace_name, short_name = name.to_s.split(":", 2)

  namespace namespace_name do
    desc "Run rspec-hermetic seeded pollution evaluation and write a JSON recall report"
    task short_name, [:output] do |_task, args|
      output = args[:output] || ENV["HERMETIC_EVALUATION_OUTPUT"] || DEFAULT_OUTPUT
      report = Evaluation.new(output_path: output).run
      seeded = report.fetch("seeded_pollution")
      puts "seeded recall #{seeded.fetch("detected")}/#{seeded.fetch("total")} (#{seeded.fetch("recall")})"
      puts "wrote #{output}"
    end
  end
end

.install_corpus(name = "hermetic:evaluate_corpus") ⇒ Object

Parameters:

  • name (String) (defaults to: "hermetic:evaluate_corpus")

Returns:

  • (Object)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec/hermetic/evaluation_task.rb', line 30

def self.install_corpus(name = "hermetic:evaluate_corpus")
  namespace_name, short_name = name.to_s.split(":", 2)

  namespace namespace_name do
    desc "Run corpus evaluation using HERMETIC_COMMAND and optional HERMETIC_BASELINE_COMMAND"
    task short_name, [:output] do |_task, args|
      command = ENV.fetch("HERMETIC_COMMAND")
      output = args[:output] || ENV["HERMETIC_CORPUS_OUTPUT"] || "tmp/rspec_hermetic_corpus.json"
      report = CorpusEvaluation.new(
        output_path: output,
        project_path: ENV["HERMETIC_PROJECT"] || Dir.pwd,
        baseline_command: ENV["HERMETIC_BASELINE_COMMAND"],
        hermetic_command: command,
        candidate_report_path: ENV["HERMETIC_CANDIDATES"] || "tmp/rspec_hermetic_candidates.json",
        judgments_path: ENV["HERMETIC_JUDGMENTS"]
      ).run
      puts "corpus candidates #{report.fetch("candidate_count")}"
      puts "wrote #{output}"
    end
  end
end