Class: RailsProof::ControllerTestWriter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_class_name:, concerns:) ⇒ ControllerTestWriter

Returns a new instance of ControllerTestWriter.



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

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

Instance Attribute Details

#concernsObject (readonly)

Returns the value of attribute concerns.



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

def concerns
  @concerns
end

#controller_class_nameObject (readonly)

Returns the value of attribute controller_class_name.



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

def controller_class_name
  @controller_class_name
end

Instance Method Details

#renderObject



10
11
12
13
14
# File 'lib/rails_proof/controller_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/controller_test_writer.rb', line 16

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