Class: RailsProof::TestFileInserter
- Inherits:
-
Object
- Object
- RailsProof::TestFileInserter
- Defined in:
- lib/rails_proof/test_file_inserter.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
-
#test_class_name ⇒ Object
readonly
Returns the value of attribute test_class_name.
Instance Method Summary collapse
-
#initialize(source:, test_class_name:, superclass:) ⇒ TestFileInserter
constructor
A new instance of TestFileInserter.
- #insert(rendered_test) ⇒ Object
Constructor Details
#initialize(source:, test_class_name:, superclass:) ⇒ TestFileInserter
Returns a new instance of TestFileInserter.
10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_proof/test_file_inserter.rb', line 10 def initialize( source:, test_class_name:, superclass: ) @source = source @test_class_name = test_class_name @superclass = superclass end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/rails_proof/test_file_inserter.rb', line 6 def source @source end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
6 7 8 |
# File 'lib/rails_proof/test_file_inserter.rb', line 6 def superclass @superclass end |
#test_class_name ⇒ Object (readonly)
Returns the value of attribute test_class_name.
6 7 8 |
# File 'lib/rails_proof/test_file_inserter.rb', line 6 def test_class_name @test_class_name end |
Instance Method Details
#insert(rendered_test) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails_proof/test_file_inserter.rb', line 20 def insert(rendered_test) lines = source.lines class_index, class_indent = find_test_class(lines) closing_index = find_class_end( lines, class_index, class_indent ) indented_test = indent_rendered_test( rendered_test, class_indent ) lines.insert( closing_index, "\n#{indented_test.rstrip}\n" ) lines.join end |