Class: Minitest::ResultsDatabase

Inherits:
AbstractReporter
  • Object
show all
Defined in:
lib/minitest/proptest.rb

Instance Method Summary collapse

Constructor Details

#initialize(pathname) ⇒ ResultsDatabase

Returns a new instance of ResultsDatabase.



12
13
14
15
16
17
18
19
20
21
# File 'lib/minitest/proptest.rb', line 12

def initialize(pathname)
  super()

  results = if File.file?(pathname)
              YAML.load_file(pathname)
            else
              {}
            end
  self.class.instance_variable_set(:@_results, results) unless self.class.instance_variable_defined?(:@_results)
end

Instance Method Details

#lookup(file, classname, methodname) ⇒ Object



29
30
31
32
33
# File 'lib/minitest/proptest.rb', line 29

def lookup(file, classname, methodname)
  self.class.instance_variable_get(:@_results)
      .dig(file, classname, methodname)
      .to_a
end

#record_failure(file, classname, methodname, generated) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/minitest/proptest.rb', line 35

def record_failure(file, classname, methodname, generated)
  return unless Proptest.use_db?

  results = self.class.instance_variable_get(:@_results)
  results[file] ||= {}
  results[file][classname] ||= {}
  results[file][classname][methodname] = generated
end

#reportObject



23
24
25
26
27
# File 'lib/minitest/proptest.rb', line 23

def report
  return unless Proptest.use_db?

  File.write(Proptest.result_db, self.class.instance_variable_get(:@_results).to_yaml)
end

#strike_failure(file, classname, methodname) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/minitest/proptest.rb', line 44

def strike_failure(file, classname, methodname)
  return unless Proptest.use_db?

  results = self.class.instance_variable_get(:@_results)
  return unless results.key?(file)

  return unless results[file].key?(classname)

  results[file][classname].delete(methodname)
  results[file].delete(classname) if results[file][classname].empty?
  results.delete(file) if results[file].empty?
end