Class: RSpec::Covers::DeclarationValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/covers/declaration_validation.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DeclarationValidator

Returns a new instance of DeclarationValidator.



31
32
33
# File 'lib/rspec/covers/declaration_validation.rb', line 31

def initialize(config)
  @config = config
end

Instance Method Details

#call(declaration:, suggestions:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec/covers/declaration_validation.rb', line 35

def call(declaration:, suggestions:)
  declared_labels = declaration.covers.map(&:label).uniq
  return empty_validation if declared_labels.empty?

  scores = suggestions.to_h { |suggestion| [suggestion.label, suggestion.score] }
  supported = declared_labels.select { |label| scores.fetch(label, 0.0) >= @config.validation_threshold }
  unsupported = declared_labels - supported

  DeclarationValidation.new(
    valid: unsupported.empty?,
    declared_labels: declared_labels,
    supported_labels: supported,
    unsupported_labels: unsupported,
    suggestions: suggestions
  )
end