Class: Riddler::TestGenerator

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/riddler/test_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_filenameObject (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_rootObject (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_caseObject (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_nameObject



18
19
20
# File 'lib/riddler/test_generator.rb', line 18

def class_name
  classify test_case_name
end

#definitionObject



22
23
24
# File 'lib/riddler/test_generator.rb', line 22

def definition
  test_case["definition"]
end

#generateObject



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_nameObject



14
15
16
# File 'lib/riddler/test_generator.rb', line 14

def test_case_name
  test_case["name"]
end

#testsObject



26
27
28
# File 'lib/riddler/test_generator.rb', line 26

def tests
  test_case["tests"]
end