Class: Similatron::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/similatron/run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#comparisonsObject (readonly)

Returns the value of attribute comparisons.



4
5
6
# File 'lib/similatron/run.rb', line 4

def comparisons
  @comparisons
end

Instance Method Details

#compare(expected:, actual:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/similatron/run.rb', line 20

def compare(expected:, actual:)
  comparison = if File.exist?(expected)
                 real_comparison(expected, actual)
               else
                 copy_comparison(expected, actual)
               end
  comparisons << comparison

  comparison
end

#compare!(expected:, actual:) ⇒ Object



31
32
33
34
# File 'lib/similatron/run.rb', line 31

def compare!(expected:, actual:)
  comparison = compare(expected: expected, actual: actual)
  comparison.raise_when_different
end

#completeObject



16
17
18
# File 'lib/similatron/run.rb', line 16

def complete
  write_reports
end

#failed_comparisonsObject



54
55
56
# File 'lib/similatron/run.rb', line 54

def failed_comparisons
  comparisons.reject(&:same?)
end

#html_report_pathObject



50
51
52
# File 'lib/similatron/run.rb', line 50

def html_report_path
  File.join(run_path, "report.html")
end

#json_report_pathObject



46
47
48
# File 'lib/similatron/run.rb', line 46

def json_report_path
  File.join(run_path, "report.json")
end

#overwrite_comparisonsObject



58
59
60
# File 'lib/similatron/run.rb', line 58

def overwrite_comparisons
  comparisons.select(&:overwrite?)
end

#start(base_path: "tmp") ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/similatron/run.rb', line 6

def start(base_path: "tmp")
  run_id = SecureRandom.urlsafe_base64(8)
  @run_path = File.join(base_path, "run_#{run_id}")

  @engines = build_engines

  @comparisons = []
  FileUtils.mkdir_p(run_path)
end

#summaryObject



36
37
38
39
40
41
42
43
44
# File 'lib/similatron/run.rb', line 36

def summary
  return "" if failed_comparisons.empty? && overwrite_comparisons.empty?
  [
    "Similatron report:",
    "#{failed_comparisons.count} failures.",
    "#{overwrite_comparisons.count} new files.",
    "Report may be found in #{html_report_path}"
  ].join("\n")
end