Class: RailsProof::AiTestWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_proof/ai_test_writer.rb

Defined Under Namespace

Classes: InvalidConcern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_class_name:, superclass:, concerns:) ⇒ AiTestWriter

Returns a new instance of AiTestWriter.



7
8
9
10
11
# File 'lib/rails_proof/ai_test_writer.rb', line 7

def initialize(test_class_name:, superclass:, concerns:)
  @test_class_name = test_class_name
  @superclass = superclass
  @concerns = concerns
end

Instance Attribute Details

#concernsObject (readonly)

Returns the value of attribute concerns.



5
6
7
# File 'lib/rails_proof/ai_test_writer.rb', line 5

def concerns
  @concerns
end

#superclassObject (readonly)

Returns the value of attribute superclass.



5
6
7
# File 'lib/rails_proof/ai_test_writer.rb', line 5

def superclass
  @superclass
end

#test_class_nameObject (readonly)

Returns the value of attribute test_class_name.



5
6
7
# File 'lib/rails_proof/ai_test_writer.rb', line 5

def test_class_name
  @test_class_name
end

Instance Method Details

#renderObject



13
14
15
16
17
# File 'lib/rails_proof/ai_test_writer.rb', line 13

def render
  concerns.map do |concern|
    indent(test_code_for(concern), 2)
  end.join("\n\n")
end

#render_test_fileObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_proof/ai_test_writer.rb', line 19

def render_test_file
  [
    'require "test_helper"',
    "",
    "class #{test_class_name} < #{superclass}",
    render,
    "end",
    ""
  ].join("\n")
end