Class: Ast::Merge::RSpec::ProviderConformanceMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/rspec/provider_conformance.rb

Overview

Interprets the complete provider fixture as an executable advertising gate.

Instance Method Summary collapse

Constructor Details

#initialize(fixture) ⇒ ProviderConformanceMatrix

Returns a new instance of ProviderConformanceMatrix.



33
34
35
36
37
# File 'lib/ast/merge/rspec/provider_conformance.rb', line 33

def initialize(fixture)
  @fixture = fixture.transform_keys(&:to_sym)
  @providers = @fixture.fetch(:providers)
  @conformance = @fixture.fetch(:executable_conformance)
end

Instance Method Details

#advertised_provider_idsObject



58
59
60
# File 'lib/ast/merge/rspec/provider_conformance.rb', line 58

def advertised_provider_ids
  tested_provider_ids.sort.freeze
end

#blocked_provider_idsObject



54
55
56
# File 'lib/ast/merge/rspec/provider_conformance.rb', line 54

def blocked_provider_ids
  fetch(@conformance, :blocked_provider_ids)
end

#tested?(provider_id:, dialect:, backend:, profile_id:) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
# File 'lib/ast/merge/rspec/provider_conformance.rb', line 62

def tested?(provider_id:, dialect:, backend:, profile_id:)
  tested_rows.any? do |row|
    fetch(row, :provider_id) == provider_id.to_s &&
      fetch(row, :dialect) == dialect.to_s &&
      fetch(row, :backend) == backend.to_s &&
      fetch(row, :profile_id) == profile_id.to_s &&
      fetch(row, :status) == 'tested'
  end
end

#tested_rowsObject



50
51
52
# File 'lib/ast/merge/rspec/provider_conformance.rb', line 50

def tested_rows
  fetch(@conformance, :tested_rows)
end

#validate!Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
# File 'lib/ast/merge/rspec/provider_conformance.rb', line 39

def validate!
  provider_ids = @providers.map { |provider| fetch(provider, :provider_id) }
  covered = tested_provider_ids | blocked_provider_ids
  unless covered.sort == provider_ids.sort
    raise ArgumentError, 'Conformance matrix does not cover every provider'
  end
  raise ArgumentError, 'Conformance matrix contains unknown providers' unless (covered - provider_ids).empty?

  self
end