Class: Riddler::TestGenerator
- Inherits:
-
Object
- Object
- Riddler::TestGenerator
- Includes:
- ERB::Util
- Defined in:
- lib/riddler/test_generator.rb
Instance Attribute Summary collapse
-
#input_filename ⇒ Object
readonly
Returns the value of attribute input_filename.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
-
#test_case ⇒ Object
readonly
Returns the value of attribute test_case.
Instance Method Summary collapse
- #class_name ⇒ Object
- #definition ⇒ Object
- #generate ⇒ Object
-
#initialize(project_root, input_filename) ⇒ TestGenerator
constructor
A new instance of TestGenerator.
- #test_case_name ⇒ Object
- #tests ⇒ Object
Constructor Details
#initialize(project_root, input_filename) ⇒ TestGenerator
Returns a new instance of TestGenerator.
8 9 10 11 12 |
# File 'lib/riddler/test_generator.rb', line 8 def initialize project_root, input_filename @project_root = project_root @input_filename = input_filename @test_case = YAML.safe_load File.read input_filename end |
Instance Attribute Details
#input_filename ⇒ Object (readonly)
Returns the value of attribute input_filename.
6 7 8 |
# File 'lib/riddler/test_generator.rb', line 6 def input_filename @input_filename end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
6 7 8 |
# File 'lib/riddler/test_generator.rb', line 6 def project_root @project_root end |
#test_case ⇒ Object (readonly)
Returns the value of attribute test_case.
6 7 8 |
# File 'lib/riddler/test_generator.rb', line 6 def test_case @test_case end |
Instance Method Details
#class_name ⇒ Object
18 19 20 |
# File 'lib/riddler/test_generator.rb', line 18 def class_name classify test_case_name end |
#definition ⇒ Object
22 23 24 |
# File 'lib/riddler/test_generator.rb', line 22 def definition test_case["definition"] end |
#generate ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/riddler/test_generator.rb', line 30 def generate folder = input_filename.dirname.basename.to_s output_filename = project_root.join *%W[ test cases #{folder} #{test_case_name}_test.rb ] puts "Generating #{output_filename.relative_path_from(project_root)}" output_filename.dirname.mkdir unless output_filename.dirname.exist? File.write output_filename, render end |
#test_case_name ⇒ Object
14 15 16 |
# File 'lib/riddler/test_generator.rb', line 14 def test_case_name test_case["name"] end |
#tests ⇒ Object
26 27 28 |
# File 'lib/riddler/test_generator.rb', line 26 def tests test_case["tests"] end |