hiptest-publisher 0.5.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -5
  3. data/bin/hiptest-publisher +7 -0
  4. data/lib/config/cucumber-folders_as_features.conf +18 -0
  5. data/lib/config/cucumber.conf +18 -0
  6. data/lib/{templates/java/output_config → config/java.conf} +6 -4
  7. data/lib/{templates/javascript/jasmine/output_config → config/javascript-jasmine.conf} +0 -0
  8. data/lib/{templates/javascript/output_config → config/javascript.conf} +1 -1
  9. data/lib/{templates/python/output_config → config/python.conf} +3 -2
  10. data/lib/{templates/robotframework/output_config → config/robotframework.conf} +4 -3
  11. data/lib/{templates/ruby/minitest/output_config → config/ruby-minitest.conf} +0 -0
  12. data/lib/{templates/ruby/output_config → config/ruby.conf} +1 -1
  13. data/lib/{templates/seleniumide/output_config → config/seleniumide.conf} +4 -4
  14. data/lib/hiptest-publisher.rb +96 -76
  15. data/lib/hiptest-publisher/cli_options_checker.rb +107 -0
  16. data/lib/hiptest-publisher/handlebars_helper.rb +1 -1
  17. data/lib/hiptest-publisher/nodes.rb +39 -11
  18. data/lib/hiptest-publisher/nodes_walker.rb +2 -2
  19. data/lib/hiptest-publisher/options_parser.rb +304 -45
  20. data/lib/hiptest-publisher/parent_adder.rb +2 -2
  21. data/lib/hiptest-publisher/renderer.rb +7 -58
  22. data/lib/hiptest-publisher/utils.rb +5 -1
  23. data/lib/hiptest-publisher/xml_parser.rb +2 -1
  24. data/lib/templates/cucumber/folders_as_features/folder.hbs +4 -0
  25. data/lib/templates/cucumber/folders_as_features/single_scenario.hbs +14 -0
  26. data/lib/templates/java/dataset.hbs +1 -1
  27. data/lib/templates/java/scenarios.hbs +3 -3
  28. data/lib/templates/java/single_scenario.hbs +3 -3
  29. data/lib/templates/java/single_test.hbs +3 -3
  30. data/lib/templates/java/testng/dataset.hbs +1 -1
  31. data/lib/templates/java/testng/single_scenario.hbs +3 -3
  32. data/lib/templates/java/testng/single_test.hbs +3 -3
  33. data/lib/templates/java/tests.hbs +3 -3
  34. metadata +15 -11
  35. data/lib/templates/cucumber/output_config +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5cfb12dc26314eb322e9eb69ce43c2af565c65f
4
- data.tar.gz: 8579672e7b62bee13628e143d4e649016a16080c
3
+ metadata.gz: f43b16fba8918586730a65e4312b062c36b0b68d
4
+ data.tar.gz: 996e1d9199c1e7163557a5625dad39f6d5a375d7
5
5
  SHA512:
6
- metadata.gz: a8d78d15ea41f418f2b724249b3ff3e255415b4e14732c750cc43f95e8e00add8190980702817a472254abf00058c903b89ccddd9c5a57a4ea00e1b0b4f08427
7
- data.tar.gz: 8a15a2c537d4a082dfdc7e47f5c05734e4666f204040da0de8d1e19195abdef677f11e5119ea3ce327e0c3580ea5790c77203335baee023406ce24c3a4202ab8
6
+ metadata.gz: 79fb761dc2208ec15cccc08020853418088972797be6934cf96a2dea547ee35dc846a72eb614ad1b341ceb6d798c3ecb815bf05cf68d4d8118177400232155c3
7
+ data.tar.gz: adca0ee51d099c0c2664aaf50b94c3531d44f549dbba800253ac893b0b46df94a8bfa35491f765b166e63f16714b79b7670cdb10efaa64605b6fafc242317755
data/README.md CHANGED
@@ -33,6 +33,7 @@ hiptest-publisher --token=<YOUR TOKEN>
33
33
  This will create a Ruby tests suite. For the moment, we support the following languages and frameworks:
34
34
 
35
35
  - Ruby (rspec / minitest)
36
+ - Cucumber Ruby
36
37
  - Python (unittest)
37
38
  - Java (JUnit / TestNg)
38
39
  - Robot Framework
@@ -45,7 +46,19 @@ You can specify the output language and framework in the command line, for examp
45
46
  hiptest-publisher --token=<YOUR TOKEN> --language=ruby --framework=minitest
46
47
  ```
47
48
 
48
- When publishing, you'll notice that a file called ``actionwords_signature.yaml``. Store this file in your code repository, it will be used to [handle updates of the action word](docs/upgrading_actionwords.md).
49
+ When publishing, you'll notice a file called ``actionwords_signature.yaml``. Store this file in your code repository, it will be used to [handle updates of the action word](docs/upgrading_actionwords.md).
50
+
51
+ Exporting a test run
52
+ --------------------
53
+
54
+ You can generate the test suite from a test run of your project by specifying option `--test-run-id=<xxx>` when calling `hiptest-publisher`. You can find the test run id in the address bar of your browser. If your browser address is `http://hiptest.net/app#/projects/1234/testRuns/6941`, then your test run id is `6941`. You can generate your tests from your test with this command line:
55
+
56
+ ```shell
57
+ hiptest-publisher --token=<YOUR TOKEN> --test-run-id=6941
58
+ ```
59
+
60
+ Available options
61
+ -----------------
49
62
 
50
63
  For more information on the available options, use the following command:
51
64
 
@@ -56,18 +69,29 @@ hiptest-publisher --help
56
69
  You could obtain for example:
57
70
 
58
71
  ```shell
72
+ Exports tests from Hiptest for automation.
73
+
59
74
  Specific options:
60
75
  -t, --token=TOKEN Secret token (available in your project settings)
61
76
  -l, --language=LANG Target language (default: ruby)
62
77
  -f, --framework=FRAMEWORK Test framework to use
63
78
  -o, --output-directory=PATH Output directory (default: .)
64
- -c, --config-file=PATH Configuration file (default: config)
79
+ -c, --config-file=PATH Configuration file
65
80
  --overriden-templates=PATH Folder for overriden templates
66
81
  --test-run-id=ID Export data from a test run
67
82
  --scenario-ids=IDS Filter scenarios by ids
68
83
  --scenario-tags=TAGS Filter scenarios by tags
69
- --tests-only Export only the tests (default: false)
70
- --actionwords-only Export only the actionwords (default: false)
84
+ --only=CATEGORIES Restrict export to given file categories (--only=list to list them)
85
+ --tests-only (deprecated) alias for --only=tests (default: false)
86
+ --actionwords-only (deprecated) alias for --only=actionwords (default: false)
87
+ --actionwords-signature Export actionwords signature (default: false)
88
+ --show-actionwords-diff Show actionwords diff since last update (summary) (default: false)
89
+ --show-actionwords-deleted Output signature of deleted action words (default: false)
90
+ --show-actionwords-created Output code for new action words (default: false)
91
+ --show-actionwords-renamed Output signatures of renamed action words (default: false)
92
+ --show-actionwords-signature-changed
93
+ Output signatures of action words for which signature changed (default: false)
94
+ --with-folders Use folders hierarchy to export files in respective directories, to be used with --split-scenarios (default: false)
71
95
  --split-scenarios Export each scenario in a single file (default: false)
72
96
  --leafless-export Use only last level action word (default: false)
73
97
  -s, --site=SITE Site to fetch from (default: https://hiptest.net)
@@ -102,10 +126,12 @@ output_directory = '<YOUR OUTPUT DIRECTORY>'
102
126
  package = 'com.youcompany'
103
127
  ```
104
128
 
129
+ Note that options from command line arguments override options from config file.
130
+
105
131
  Posting results to Hiptest
106
132
  --------------------------
107
133
 
108
- You can use the options --push to push the results to Hiptest. For this, you first need to generate the test code from a Test run by specifying option ``--test_run_id=<xxx>`` during code generation (or add it to the configuration file).
134
+ You can use the options --push to push the results back to Hiptest. For this, you first need to generate the test code from a Test run by specifying option ``--test-run-id=<xxx>`` during code generation (or add it to the configuration file).
109
135
  The tests must then generate a test report that is supported by Hiptest. Currently three types of test results are handled:
110
136
  - tap (Test Anything Protocol)
111
137
  - jUnit XML style
@@ -17,6 +17,13 @@ begin
17
17
  rescue LoadError
18
18
  end
19
19
 
20
+ # Ensure ruby version >= 2
21
+ if RUBY_VERSION.to_i < 2
22
+ STDERR.puts "Error: you are using #{RUBY_ENGINE} #{RUBY_VERSION}."
23
+ STDERR.puts "hiptest-publisher requires Ruby version >= 2.0.0."
24
+ exit 1
25
+ end
26
+
20
27
  require 'hiptest-publisher'
21
28
  begin
22
29
  require 'pry' # only available in development
@@ -0,0 +1,18 @@
1
+ [_common]
2
+ language = cucumber
3
+ indentation = ' '
4
+ fallback_template = 'empty'
5
+
6
+ [features]
7
+ node_name = folders
8
+ scenario_filename = '%s.feature'
9
+
10
+ [step_definitions]
11
+ node_name = actionwords
12
+ filename = 'step_definitions.rb'
13
+ naming_convention = 'underscore'
14
+
15
+ [actionwords]
16
+ language = ruby
17
+ filename = 'actionwords.rb'
18
+ naming_convention = 'underscore'
@@ -0,0 +1,18 @@
1
+ [_common]
2
+ language = cucumber
3
+ indentation = ' '
4
+ fallback_template = 'empty'
5
+
6
+ [features]
7
+ node_name = tests
8
+ scenario_filename = '%s.feature'
9
+
10
+ [step_definitions]
11
+ node_name = actionwords
12
+ filename = 'step_definitions.rb'
13
+ naming_convention = 'underscore'
14
+
15
+ [actionwords]
16
+ language = ruby
17
+ filename = 'actionwords.rb'
18
+ naming_convention = 'underscore'
@@ -1,11 +1,13 @@
1
+ [_common]
2
+ package = 'com.example'
3
+ indentation = ' '
4
+ filename_convention = 'camelize'
5
+ naming_convention = 'camelize_lower'
6
+
1
7
  [tests]
2
8
  filename = 'ProjectTest.java'
3
9
  scenario_filename = '%sTest.java'
4
- class_name_convention = 'camelize'
5
- indentation = " "
6
10
  call_prefix = 'actionwords'
7
11
 
8
12
  [actionwords]
9
13
  filename = 'Actionwords.java'
10
- indentation = " "
11
- naming_convention = 'camelize_lower'
@@ -5,4 +5,4 @@ call_prefix = 'actionwords'
5
5
 
6
6
  [actionwords]
7
7
  filename = 'actionwords.js'
8
- naming_convention = 'camelize_lower'
8
+ naming_convention = 'camelize_lower'
@@ -1,10 +1,11 @@
1
+ [_common]
2
+ indentation = " "
3
+
1
4
  [tests]
2
5
  filename = 'test_project.py'
3
6
  scenario_filename = 'test_%s.py'
4
7
  call_prefix = 'actionwords'
5
- indentation = " "
6
8
 
7
9
  [actionwords]
8
10
  filename = 'actionwords.py'
9
- indentation = " "
10
11
  naming_convention = 'underscore'
@@ -1,9 +1,10 @@
1
+ [_common]
2
+ indentation = "\t"
3
+
1
4
  [tests]
2
5
  filename = 'project.txt'
3
6
  scenario_filename = 'test_%s.txt'
4
- indentation = "\t"
5
7
 
6
8
  [actionwords]
7
9
  filename = 'keywords.txt'
8
- indentation = "\t"
9
- naming_convention = 'underscore'
10
+ naming_convention = 'underscore'
@@ -4,4 +4,4 @@ scenario_filename = '%s_spec.rb'
4
4
 
5
5
  [actionwords]
6
6
  filename = 'actionwords.rb'
7
- naming_convention = 'underscore'
7
+ naming_convention = 'underscore'
@@ -1,11 +1,11 @@
1
+ [_common]
2
+ indentation = " "
3
+ fallback_template = 'empty'
4
+
1
5
  [tests]
2
6
  filename = 'project.html'
3
7
  scenario_filename = '%s.html'
4
8
  call_prefix = ''
5
- indentation = " "
6
- fallback_template = 'empty'
7
9
 
8
10
  [actionwords]
9
11
  filename = 'actionwords.html'
10
- indentation = " "
11
- fallback_template = 'empty'
@@ -2,6 +2,7 @@ require 'colorize'
2
2
  require 'yaml'
3
3
 
4
4
  require 'hiptest-publisher/formatters/reporter'
5
+ require 'hiptest-publisher/cli_options_checker'
5
6
  require 'hiptest-publisher/string'
6
7
  require 'hiptest-publisher/utils'
7
8
  require 'hiptest-publisher/options_parser'
@@ -16,13 +17,36 @@ module Hiptest
16
17
  class Publisher
17
18
  attr_reader :reporter
18
19
 
19
- def initialize(args, listeners: nil)
20
+ def initialize(args, listeners: nil, exit_on_bad_arguments: true)
20
21
  @reporter = Reporter.new(listeners)
21
- @options = OptionsParser.parse(args, reporter)
22
+ @cli_options = OptionsParser.parse(args, reporter)
23
+ # pass false to prevent hiptest-publisher from exiting, useful when used embedded
24
+ @exit_on_bad_arguments = exit_on_bad_arguments
25
+ end
26
+
27
+ def normalize_cli_options!
28
+ modified_cli_options = @cli_options.clone
29
+ if @cli_options.actionwords_only
30
+ modified_cli_options.only = 'actionwords'
31
+ elsif @cli_options.tests_only
32
+ modified_cli_options.only = 'tests'
33
+ end
34
+ @cli_options = modified_cli_options
22
35
  end
23
36
 
24
37
  def run
25
- unless @options.push.nil? || @options.push.empty?
38
+ normalize_cli_options!
39
+ if CliOptionsChecker.new(@cli_options, reporter).bad_arguments?
40
+ exit 1 if @exit_on_bad_arguments
41
+ return
42
+ end
43
+
44
+ if @cli_options.only == 'list'
45
+ print_categories
46
+ return
47
+ end
48
+
49
+ unless @cli_options.push.nil? || @cli_options.push.empty?
26
50
  post_results
27
51
  return
28
52
  end
@@ -32,12 +56,12 @@ module Hiptest
32
56
 
33
57
  @project = get_project(xml)
34
58
 
35
- if @options.actionwords_signature
59
+ if @cli_options.actionwords_signature
36
60
  export_actionword_signature
37
61
  return
38
62
  end
39
63
 
40
- if @options.actionwords_diff || @options.aw_deleted|| @options.aw_created|| @options.aw_renamed|| @options.aw_signature_changed
64
+ if @cli_options.actionwords_diff || @cli_options.aw_deleted|| @cli_options.aw_created|| @cli_options.aw_renamed|| @cli_options.aw_signature_changed
41
65
  show_actionwords_diff
42
66
  return
43
67
  end
@@ -47,7 +71,7 @@ module Hiptest
47
71
 
48
72
  def fetch_xml_file
49
73
  show_status_message "Fetching data from Hiptest"
50
- xml = fetch_project_export(@options)
74
+ xml = fetch_project_export(@cli_options)
51
75
  show_status_message "Fetching data from Hiptest", :success
52
76
 
53
77
  return xml
@@ -69,6 +93,7 @@ module Hiptest
69
93
  status_message = "#{message}: #{path}"
70
94
  begin
71
95
  show_status_message status_message
96
+ mkdirs_for(path)
72
97
  File.open(path, 'w') do |file|
73
98
  file.write(yield)
74
99
  end
@@ -80,71 +105,38 @@ module Hiptest
80
105
  end
81
106
  end
82
107
 
108
+ def mkdirs_for(path)
109
+ unless Dir.exists?(File.dirname(path))
110
+ FileUtils.mkpath(File.dirname(path))
111
+ end
112
+ end
113
+
83
114
  def add_listener(listener)
84
115
  reporter.add_listener(listener)
85
116
  end
86
117
 
87
118
  def write_node_to_file(path, node, context, message)
88
119
  write_to_file(path, message) do
89
- Hiptest::Renderer.render(node, @options.language, context)
90
- end
91
- end
92
-
93
- def export_tests
94
- if @options.split_scenarios
95
- @project.children[:tests].children[:tests].each do |test|
96
- context = @language_config.tests_render_context
97
- context[:test_file_name] = @language_config.scenario_output_file(test.children[:name])
98
-
99
- write_node_to_file(
100
- @language_config.scenario_output_dir(test.children[:name]),
101
- test,
102
- context,
103
- "Exporting test \"#{test.children[:name]}\"")
104
- end
105
- else
106
- write_node_to_file(
107
- @language_config.tests_output_dir,
108
- @project.children[:tests],
109
- @language_config.tests_render_context,
110
- "Exporting tests")
120
+ Hiptest::Renderer.render(node, context)
111
121
  end
112
122
  end
113
123
 
114
- def export_scenarios
115
- if @options.split_scenarios
116
- @project.children[:scenarios].children[:scenarios].each do |scenario|
117
- context = @language_config.tests_render_context
118
- context[:test_file_name] = @language_config.scenario_output_file(scenario.children[:name])
119
-
124
+ def export_files
125
+ @language_config.language_group_configs.each do |language_group_config|
126
+ language_group_config.each_node_rendering_context(@project) do |node_rendering_context|
120
127
  write_node_to_file(
121
- @language_config.scenario_output_dir(scenario.children[:name]),
122
- scenario,
123
- context,
124
- "Exporting scenario \"#{scenario.children[:name]}\"")
128
+ node_rendering_context.path,
129
+ node_rendering_context.node,
130
+ node_rendering_context,
131
+ "Exporting #{node_rendering_context.description}",
132
+ )
125
133
  end
126
- else
127
- write_node_to_file(
128
- @language_config.tests_output_dir,
129
- @project.children[:scenarios],
130
- @language_config.tests_render_context,
131
- "Exporting scenarios")
132
134
  end
133
135
  end
134
136
 
135
- def export_actionwords
136
- write_node_to_file(
137
- @language_config.aw_output_dir,
138
- @project.children[:actionwords],
139
- @language_config.actionword_render_context,
140
- "Exporting actionwords"
141
- )
142
- export_actionword_signature
143
- end
144
-
145
137
  def export_actionword_signature
146
138
  write_to_file(
147
- "#{@options.output_directory}/actionwords_signature.yaml",
139
+ "#{@cli_options.output_directory}/actionwords_signature.yaml",
148
140
  "Exporting actionword signature"
149
141
  ) { Hiptest::SignatureExporter.export_actionwords(@project).to_yaml }
150
142
  end
@@ -152,22 +144,23 @@ module Hiptest
152
144
  def show_actionwords_diff
153
145
  begin
154
146
  show_status_message("Loading previous definition")
155
- old = YAML.load_file("#{@options.output_directory}/actionwords_signature.yaml")
147
+ old = YAML.load_file("#{@cli_options.output_directory}/actionwords_signature.yaml")
156
148
  show_status_message("Loading previous definition", :success)
157
149
  rescue Exception => err
158
150
  show_status_message("Loading previous definition", :failure)
159
151
  reporter.dump_error(err)
160
152
  end
161
153
 
162
- @language_config = LanguageConfigParser.new(@options)
154
+ @language_config = LanguageConfigParser.new(@cli_options)
163
155
  Hiptest::Nodes::ParentAdder.add(@project)
164
156
  Hiptest::Nodes::ParameterTypeAdder.add(@project)
165
157
  Hiptest::DefaultArgumentAdder.add(@project)
158
+ Hiptest::GherkinAdder.add(@project)
166
159
 
167
160
  current = Hiptest::SignatureExporter.export_actionwords(@project, true)
168
161
  diff = Hiptest::SignatureDiffer.diff( old, current)
169
162
 
170
- if @options.aw_deleted
163
+ if @cli_options.aw_deleted
171
164
  return if diff[:deleted].nil?
172
165
 
173
166
  diff[:deleted].map {|deleted|
@@ -176,16 +169,22 @@ module Hiptest
176
169
  return
177
170
  end
178
171
 
179
- if @options.aw_created
172
+ if @cli_options.aw_created
180
173
  return if diff[:created].nil?
181
- diff[:created].map {|created|
182
- puts Hiptest::Renderer.render(created[:node], @options.language, @language_config.actionword_render_context)
183
- puts ""
184
- }
174
+
175
+ @language_config.language_group_configs.select { |language_group_config|
176
+ language_group_config[:group_name] == "actionwords"
177
+ }.each do |language_group_config|
178
+ diff[:created].each do |created|
179
+ node_rendering_context = language_group_config.build_node_rendering_context(created[:node])
180
+ puts node_rendering_context[:node].render(node_rendering_context)
181
+ puts ""
182
+ end
183
+ end
185
184
  return
186
185
  end
187
186
 
188
- if @options.aw_renamed
187
+ if @cli_options.aw_renamed
189
188
  return if diff[:renamed].nil?
190
189
 
191
190
  diff[:renamed].map {|renamed|
@@ -194,13 +193,18 @@ module Hiptest
194
193
  return
195
194
  end
196
195
 
197
- if @options.aw_signature_changed
196
+ if @cli_options.aw_signature_changed
198
197
  return if diff[:signature_changed].nil?
199
198
 
200
- diff[:signature_changed].map {|signature_changed|
201
- puts Hiptest::Renderer.render(signature_changed[:node], @options.language, @language_config.actionword_render_context)
202
- puts ""
203
- }
199
+ @language_config.language_group_configs.select { |language_group_config|
200
+ language_group_config[:group_name] == "actionwords"
201
+ }.each do |language_group_config|
202
+ diff[:signature_changed].each do |signature_changed|
203
+ node_rendering_context = language_group_config.build_node_rendering_context(signature_changed[:node])
204
+ puts signature_changed[:node].render(node_rendering_context)
205
+ puts ""
206
+ end
207
+ end
204
208
  return
205
209
  end
206
210
 
@@ -237,25 +241,41 @@ module Hiptest
237
241
  def export
238
242
  return if @project.nil?
239
243
 
240
- @language_config = LanguageConfigParser.new(@options)
244
+ @language_config = LanguageConfigParser.new(@cli_options)
241
245
  Hiptest::Nodes::ParentAdder.add(@project)
242
246
  Hiptest::Nodes::ParameterTypeAdder.add(@project)
243
247
  Hiptest::DefaultArgumentAdder.add(@project)
244
248
  Hiptest::GherkinAdder.add(@project)
245
249
 
246
- unless @options.actionwords_only
247
- @options.leafless_export ? export_tests : export_scenarios
248
- end
250
+ export_files
251
+ export_actionword_signature if @language_config.include_group?("actionwords")
252
+ end
249
253
 
250
- export_actionwords unless @options.tests_only
254
+ def print_categories
255
+ language_config = LanguageConfigParser.new(@cli_options)
256
+ group_names = language_config.group_names
257
+ puts "For language #{@cli_options.language}, available file groups are"
258
+ group_names.each do |group_name|
259
+ puts " - #{group_name}"
260
+ end
261
+ puts [
262
+ "",
263
+ "Usage examples:",
264
+ "",
265
+ "To export only #{group_names.first} files:",
266
+ " hiptest-publisher --language=#{@cli_options.language} --only=#{group_names.first}",
267
+ "",
268
+ "To export both #{group_names.first} and #{group_names[1]} files:",
269
+ " hiptest-publisher --language=#{@cli_options.language} --only=#{group_names.take(2).join(",")}"
270
+ ].join("\n")
251
271
  end
252
272
 
253
273
  def post_results
254
- status_message = "Posting #{@options.push} to #{@options.site}"
274
+ status_message = "Posting #{@cli_options.push} to #{@cli_options.site}"
255
275
  show_status_message(status_message)
256
276
 
257
277
  begin
258
- push_results(@options)
278
+ push_results(@cli_options)
259
279
  show_status_message(status_message, :success)
260
280
  rescue Exception => err
261
281
  show_status_message(status_message, :failure)