Class: AIRspecWriter::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/ai_rspec_writer/generator.rb

Overview

Responsible for handling AI-based test generation

Instance Method Summary collapse

Constructor Details

#initialize(ai: nil, ec: nil, schema: nil) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
# File 'lib/ai_rspec_writer/generator.rb', line 10

def initialize(ai: nil, ec: nil, schema: nil)
  @ai = ai.presence || AiRspecWriter.configuration.ai_provider
  @extra_comment = ec
  @schema = schema
end

Instance Method Details

#generate(file_paths) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ai_rspec_writer/generator.rb', line 16

def generate(file_paths)
  file_contents = file_paths.map do |file_path|
    next "Error: File not found (#{file_path})" unless File.exist?(file_path)
    File.read(file_path)
  end.join("\n\n") # Combine multiple files
  
  generator = case @ai.downcase
              when "chatgpt" then AIProviders::ChatGPTGenerator.new(ec: @extra_comment, schema: @schema)
              when "gemini" then AIProviders::GeminiGenerator.new(ec: @extra_comment, schema: @schema)
              else
                raise "Unsupported AI. Use 'chatgpt' or 'gemini'."
              end

  generator.generate_spec(file_contents)
end