Class: RailsProof::TestWriter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class_name:, concerns:) ⇒ TestWriter

Returns a new instance of TestWriter.



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

def initialize(model_class_name:, concerns:)
  @model_class_name = model_class_name
  @concerns = concerns
end

Instance Attribute Details

#concernsObject (readonly)

Returns the value of attribute concerns.



3
4
5
# File 'lib/rails_proof/test_writer.rb', line 3

def concerns
  @concerns
end

#model_class_nameObject (readonly)

Returns the value of attribute model_class_name.



3
4
5
# File 'lib/rails_proof/test_writer.rb', line 3

def model_class_name
  @model_class_name
end

Instance Method Details

#renderObject



10
11
12
13
14
# File 'lib/rails_proof/test_writer.rb', line 10

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

#render_test_fileObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_proof/test_writer.rb', line 16

def render_test_file
  [
    'require "test_helper"',
    "",
    "class #{model_class_name}Test < ActiveSupport::TestCase",
    render,
    "end",
    ""
  ].join("\n")
end