Class: Hiptest::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Publisher

Returns a new instance of Publisher.



13
14
15
16
17
18
19
20
# File 'lib/hiptest-publisher.rb', line 13

def initialize(args)
  @options = OptionsParser.parse(args)

  xml = fetch_xml_file
  return if xml.nil?

  @project = get_project(xml)
end

Instance Method Details

#exportObject



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/hiptest-publisher.rb', line 108

def export
  @language_config = LanguageConfigParser.new(@options)
  Hiptest::Nodes::ParentAdder.add(@project)
  Hiptest::Nodes::ParameterTypeAdder.add(@project)
  Hiptest::DefaultArgumentAdder.add(@project)

  unless @options.actionwords_only
    @options.leafless_export ? export_tests : export_scenarios
  end

  export_actionwords unless @options.tests_only
end

#export_actionwordsObject



99
100
101
102
103
104
105
106
# File 'lib/hiptest-publisher.rb', line 99

def export_actionwords
  write_node_to_file(
    @language_config.aw_output_dir,
    @project.children[:actionwords],
    @language_config.actionword_render_context,
    "Exporting actionwords"
  )
end

#export_scenariosObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/hiptest-publisher.rb', line 78

def export_scenarios
  if @options.split_scenarios
    @project.children[:scenarios].children[:scenarios].each do |scenario|
      context = @language_config.tests_render_context
      context[:test_file_name] = @language_config.scenario_output_file(scenario.children[:name])

      write_node_to_file(
        @language_config.scenario_output_dir(scenario.children[:name]),
        scenario,
        context,
        "Exporting scenario \"#{scenario.children[:name]}\"")
    end
  else
    write_node_to_file(
      @language_config.tests_output_dir,
      @project.children[:scenarios],
      @language_config.tests_render_context,
      "Exporting scenarios")
  end
end

#export_testsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hiptest-publisher.rb', line 57

def export_tests
  if @options.split_scenarios
    @project.children[:tests].children[:tests].each do |test|
      context = @language_config.tests_render_context
      context[:test_file_name] = @language_config.scenario_output_file(test.children[:name])

      write_node_to_file(
        @language_config.scenario_output_dir(test.children[:name]),
        test,
        context,
        "Exporting test \"#{test.children[:name]}\"")
    end
  else
    write_node_to_file(
      @language_config.tests_output_dir,
      @project.children[:tests],
      @language_config.tests_render_context,
      "Exporting tests")
  end
end

#fetch_xml_fileObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hiptest-publisher.rb', line 22

def fetch_xml_file
  show_status_message "Fetching data from Hiptest"
  xml = fetch_project_export(@options)
  show_status_message "Fetching data from Hiptest", :success

  return xml
rescue Exception => err
  show_status_message "Fetching data from Hiptest", :failure
  puts "Unable to open the file, please check that the token is correct".red
  trace_exception(err) if @options.verbose
end

#get_project(xml) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/hiptest-publisher.rb', line 34

def get_project(xml)
  show_status_message "Extracting data"
  parser = Hiptest::XMLParser.new(xml, @options)
  show_status_message "Extracting data", :success

  return parser.build_project
end

#write_node_to_file(path, node, context, message) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hiptest-publisher.rb', line 42

def write_node_to_file(path, node, context, message)
  status_message = "#{message}: #{path}"
  begin
    show_status_message status_message
    File.open(path, 'w') do |file|
      file.write(Hiptest::Renderer.render(node, @options.language, context))
    end

    show_status_message status_message, :success
  rescue Exception => err
    show_status_message status_message, :failure
    trace_exception(err) if @options.verbose
  end
end