Class: Pangea::Testing::SpecGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/testing/spec_generator.rb

Overview

Auto-generates RSpec synthesis specs from resource metadata.

Usage:

generator = SpecGenerator.new(
  provider_module: 'Pangea::Resources::AWS',
  resource_type: 'aws_iam_instance_profile',
  attributes_class: 'Pangea::Resources::AWS::Types::IamInstanceProfileAttributes',
  required_attributes: { name: 'test-profile', role: 'test-role' },
  optional_attributes: { path: '/custom/', tags: { Env: 'test' } },
  expected_outputs: [:id, :arn, :name, :unique_id],
  mutually_exclusive: [[:name, :name_prefix]],
  terraform_ref_fields: [:role, :name],
  supports_tags: true,
)
puts generator.generate

Constant Summary collapse

HEADER =
<<~RUBY.freeze
  # frozen_string_literal: true
  # Auto-generated by Pangea::Testing::SpecGenerator
  # Regenerate with: pangea-core spec-gen or forge pangea-spec-gen

  require 'spec_helper'
RUBY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ SpecGenerator

Returns a new instance of SpecGenerator.



32
33
34
35
# File 'lib/pangea/testing/spec_generator.rb', line 32

def initialize(**config)
  @config = config
  validate_config!
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



30
31
32
# File 'lib/pangea/testing/spec_generator.rb', line 30

def config
  @config
end

Instance Method Details

#generateObject



37
38
39
40
41
42
# File 'lib/pangea/testing/spec_generator.rb', line 37

def generate
  [
    HEADER,
    describe_block,
  ].join("\n")
end