module Cucudocs::Parser
Public Class Methods
parse(file_path = '')
click to toggle source
# File lib/cucudocs/parser.rb, line 9 def self.parse(file_path = '') raise ArgumentError, 'Incorrect file path' if !File.exist?(file_path) fetch_test_file(file_path) content = generate_root_pages copy_generated_report(content) copy_template_files end
Private Class Methods
copy_generated_report(content)
click to toggle source
# File lib/cucudocs/parser.rb, line 35 def self.copy_generated_report(content) layout = Slim::Template.new File.expand_path('../../templates/layout.html.slim',__FILE__ ) test_html = layout.render { content.join('') } Dir.mkdir('build') if !Dir.exist?('build') myfile = File.new("build/test.html", "w+") myfile.puts(test_html) end
copy_template_files()
click to toggle source
# File lib/cucudocs/parser.rb, line 58 def self.copy_template_files FileUtils.copy_file( File.expand_path('../../templates/styles.css', __FILE__ ), 'build/styles.css', preserve = false, dereference = true ) FileUtils.copy_file( File.expand_path('../../templates/application.js', __FILE__ ), 'build/application.js', preserve = false, dereference = true ) end
fetch_test_file(file_path)
click to toggle source
# File lib/cucudocs/parser.rb, line 20 def self.fetch_test_file(file_path) file = File.open file_path @json_tests = JSON.load file end
generate_root_pages()
click to toggle source
# File lib/cucudocs/parser.rb, line 25 def self.generate_root_pages content = @json_tests.map do |test_object| template = Slim::Template.new File.expand_path('../../templates/test.html.slim', __FILE__ ) content = template.render(Object.new, test_description(test_object)) content end content end
test_description(test_object)
click to toggle source
# File lib/cucudocs/parser.rb, line 43 def self.test_description(test_object) test = {} test[:name] = test_object['name'] test[:elements] = test_object['elements'].map do |element| { keyword: element['keyword'], type: element['type'], steps: element['steps'], name: element['name'] } end test end