hiptest-publisher 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6041db11a53b2b03c059cbf5c218ff27c1bed910
4
- data.tar.gz: f85c857da7a25003978d8472426d618011374ad3
3
+ metadata.gz: d7e6e951a54117005ef23edde89a7b774c0e0406
4
+ data.tar.gz: 8ac2f19e6510ee971d2dcbeb3d3fb4944e97e8d8
5
5
  SHA512:
6
- metadata.gz: 059501363e3923261d567275b66a15f30ecd741d9ef057bd1faf9d4eddf10ff57b89384a66d88ef77dce1947217d9a3b75d0de92f8173b4843434b4010f2970e
7
- data.tar.gz: 5515d70df09c1f7c89c3aa040f999abfc251055bf8959838f336aff94683b396ebd36628082cbbdf237f9cc6c2639a62547b0c933fe8dfac82e10d29aa1e2251
6
+ metadata.gz: 8ecb02311bb95c630d339d286f664b6cfe373f038a2cabfd8637e41176a167b479ee9316f917fd75d5521853b2440e4affe8d162341584dc2851bd9f6e0407ad
7
+ data.tar.gz: fc29b7ef057e6b543bd122e1606d1210c638a6068559a7bf494a71a43446e5c9a5196b0f95991bee35acbb2f4ac2d6a36439cbd1a061f15adf6a652268a52420
data/README.md CHANGED
@@ -34,7 +34,10 @@ This will create a Ruby tests suite. For the moment, we support the following la
34
34
 
35
35
  - Ruby (rspec / minitest)
36
36
  - Python (unittest)
37
- - Java (JUnit)
37
+ - Java (JUnit / TestNg)
38
+ - Robot Framework
39
+ - Selenium IDE
40
+ - Javascript (qUnit / Jasmine)
38
41
 
39
42
  You can specify the output language and framework in the command line, for example:
40
43
 
@@ -42,6 +45,7 @@ You can specify the output language and framework in the command line, for examp
42
45
  hiptest-publisher --token=<YOUR TOKEN> --language=ruby --framework=minitest
43
46
  ```
44
47
 
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).
45
49
 
46
50
  For more information on the available options, use the following command:
47
51
 
@@ -8,4 +8,4 @@ end
8
8
 
9
9
  require 'hiptest-publisher'
10
10
 
11
- Hiptest::Publisher.new(ARGV).export
11
+ Hiptest::Publisher.new(ARGV).run
@@ -1,4 +1,5 @@
1
1
  require 'colorize'
2
+ require 'yaml'
2
3
 
3
4
  require 'hiptest-publisher/string'
4
5
  require 'hiptest-publisher/utils'
@@ -7,12 +8,16 @@ require 'hiptest-publisher/xml_parser'
7
8
  require 'hiptest-publisher/parent_adder'
8
9
  require 'hiptest-publisher/parameter_type_adder'
9
10
  require 'hiptest-publisher/call_arguments_adder'
11
+ require 'hiptest-publisher/signature_exporter'
12
+ require 'hiptest-publisher/signature_differ'
10
13
 
11
14
  module Hiptest
12
15
  class Publisher
13
16
  def initialize(args)
14
17
  @options = OptionsParser.parse(args)
18
+ end
15
19
 
20
+ def run
16
21
  unless @options.push.nil? || @options.push.empty?
17
22
  post_results
18
23
  return
@@ -22,6 +27,18 @@ module Hiptest
22
27
  return if xml.nil?
23
28
 
24
29
  @project = get_project(xml)
30
+
31
+ if @options.actionwords_signature
32
+ export_actionword_signature
33
+ return
34
+ end
35
+
36
+ if @options.actionwords_diff || @options.aw_deleted|| @options.aw_created|| @options.aw_renamed|| @options.aw_signature_changed
37
+ show_actionwords_diff
38
+ return
39
+ end
40
+
41
+ export
25
42
  end
26
43
 
27
44
  def fetch_xml_file
@@ -44,12 +61,12 @@ module Hiptest
44
61
  return parser.build_project
45
62
  end
46
63
 
47
- def write_node_to_file(path, node, context, message)
64
+ def write_to_file(path, message)
48
65
  status_message = "#{message}: #{path}"
49
66
  begin
50
67
  show_status_message status_message
51
68
  File.open(path, 'w') do |file|
52
- file.write(Hiptest::Renderer.render(node, @options.language, context))
69
+ file.write(yield)
53
70
  end
54
71
 
55
72
  show_status_message status_message, :success
@@ -59,6 +76,12 @@ module Hiptest
59
76
  end
60
77
  end
61
78
 
79
+ def write_node_to_file(path, node, context, message)
80
+ write_to_file(path, message) do
81
+ Hiptest::Renderer.render(node, @options.language, context)
82
+ end
83
+ end
84
+
62
85
  def export_tests
63
86
  if @options.split_scenarios
64
87
  @project.children[:tests].children[:tests].each do |test|
@@ -108,6 +131,94 @@ module Hiptest
108
131
  @language_config.actionword_render_context,
109
132
  "Exporting actionwords"
110
133
  )
134
+ export_actionword_signature
135
+ end
136
+
137
+ def export_actionword_signature
138
+ write_to_file(
139
+ "#{@options.output_directory}/actionwords_signature.yaml",
140
+ "Exporting actionword signature"
141
+ ) { Hiptest::SignatureExporter.export_actionwords(@project).to_yaml }
142
+ end
143
+
144
+ def show_actionwords_diff
145
+ begin
146
+ show_status_message("Loading previous definition")
147
+ old = YAML.load_file("#{@options.output_directory}/actionwords_signature.yaml")
148
+ show_status_message("Loading previous definition", :success)
149
+ rescue Exception => err
150
+ show_status_message("Loading previous definition", :failure)
151
+ trace_exception(err) if @options.verbose
152
+ end
153
+
154
+ @language_config = LanguageConfigParser.new(@options)
155
+ Hiptest::Nodes::ParentAdder.add(@project)
156
+ Hiptest::Nodes::ParameterTypeAdder.add(@project)
157
+ Hiptest::DefaultArgumentAdder.add(@project)
158
+
159
+ current = Hiptest::SignatureExporter.export_actionwords(@project, true)
160
+ diff = Hiptest::SignatureDiffer.diff( old, current)
161
+
162
+ if @options.aw_deleted
163
+ return if diff[:deleted].nil?
164
+
165
+ diff[:deleted].map {|deleted|
166
+ puts @language_config.name_action_word(deleted[:name])
167
+ }
168
+ return
169
+ end
170
+
171
+ if @options.aw_created
172
+ return if diff[:created].nil?
173
+ diff[:created].map {|created|
174
+ puts Hiptest::Renderer.render(created[:node], @options.language, @language_config.actionword_render_context)
175
+ puts ""
176
+ }
177
+ return
178
+ end
179
+
180
+ if @options.aw_renamed
181
+ return if diff[:renamed].nil?
182
+
183
+ diff[:renamed].map {|renamed|
184
+ puts "#{@language_config.name_action_word(renamed[:name])}\t#{@language_config.name_action_word(renamed[:new_name])}"
185
+ }
186
+ return
187
+ end
188
+
189
+ if @options.aw_signature_changed
190
+ return if diff[:signature_changed].nil?
191
+
192
+ diff[:signature_changed].map {|signature_changed|
193
+ puts Hiptest::Renderer.render(signature_changed[:node], @options.language, @language_config.actionword_render_context)
194
+ puts ""
195
+ }
196
+ return
197
+ end
198
+
199
+ unless diff[:deleted].nil?
200
+ puts "#{diff[:deleted].length} action words deleted:"
201
+ puts diff[:deleted].map {|d| "- #{d[:name]}"}.join("\n")
202
+ puts ""
203
+ end
204
+
205
+ unless diff[:created].nil?
206
+ puts "#{diff[:created].length} action words created:"
207
+ puts diff[:created].map {|c| "- #{c[:name]}"}.join("\n")
208
+ puts ""
209
+ end
210
+
211
+ unless diff[:renamed].nil?
212
+ puts "#{diff[:renamed].length} action words renamed:"
213
+ puts diff[:renamed].map {|r| "- #{r[:name]} => #{r[:new_name]}"}.join("\n")
214
+ puts ""
215
+ end
216
+
217
+ unless diff[:signature_changed].nil?
218
+ puts "#{diff[:signature_changed].length} action words which signature changed:"
219
+ puts diff[:signature_changed].map {|c| "- #{c[:name]}"}.join("\n")
220
+ puts ""
221
+ end
111
222
  end
112
223
 
113
224
  def export
@@ -241,6 +241,11 @@ module Hiptest
241
241
  end
242
242
 
243
243
  class Actionword < Item
244
+ def initialize(name, tags = [], parameters = [], body = [], uid = nil)
245
+ super(name, tags, parameters, body)
246
+ @children[:uid] = uid
247
+ end
248
+
244
249
  def must_be_implemented?
245
250
  @children[:body].empty? || @children[:body].map {|step| step.class}.compact.include?(Hiptest::Nodes::Step)
246
251
  end
@@ -82,6 +82,12 @@ class OptionsParser
82
82
  Option.new(nil, 'scenario-tags=TAGS', '', String, "Filter scenarios by tags", :filter_tags),
83
83
  Option.new(nil, 'tests-only', false, nil, "Export only the tests", :tests_only),
84
84
  Option.new(nil, 'actionwords-only', false, nil, "Export only the actionwords", :actionwords_only),
85
+ Option.new(nil, 'actionwords-signature', false, nil, "Export actionword signature", :actionwords_signature),
86
+ Option.new(nil, 'show-actionwords-diff', false, nil, "Show actionwords diff since last update (summary)", :actionwords_diff),
87
+ Option.new(nil, 'show-actionwords-deleted', false, nil, "Output signature of deleted action words", :aw_deleted),
88
+ Option.new(nil, 'show-actionwords-created', false, nil, "Output code for new action words", :aw_created),
89
+ Option.new(nil, 'show-actionwords-renamed', false, nil, "Output signatures of renamed action words", :aw_renamed),
90
+ Option.new(nil, 'show-actionwords-signature-changed', false, nil, "Output signatures of action words for which signature changed", :aw_signature_changed),
85
91
  Option.new(nil, 'split-scenarios', false, nil, "Export each scenario in a single file", :split_scenarios),
86
92
  Option.new(nil, 'leafless-export', false, nil, "Use only last level action word", :leafless_export),
87
93
  Option.new('s', 'site=SITE', 'https://hiptest.net', String, "Site to fetch from", :site),
@@ -210,6 +216,10 @@ class LanguageConfigParser
210
216
  make_context('actionwords')
211
217
  end
212
218
 
219
+ def name_action_word(name)
220
+ name.send(@config['actionwords']['naming_convention'])
221
+ end
222
+
213
223
  private
214
224
  def make_context group
215
225
  context = {
@@ -0,0 +1,64 @@
1
+ module Hiptest
2
+ class SignatureDiffer
3
+ def self.diff(old, current)
4
+ SignatureDiffer.new(old, current).compute_diff
5
+ end
6
+
7
+ def initialize(old, current)
8
+ @old = old
9
+ @current = current
10
+ end
11
+
12
+ def compute_diff
13
+ @old_uid = map_by_uid(@old)
14
+ @current_uid = map_by_uid(@current)
15
+
16
+ compute_created
17
+ compute_deleted
18
+ compute_renamed
19
+ compute_signature_changed
20
+
21
+ diff = {}
22
+ diff[:created] = @created unless @created.empty?
23
+ diff[:deleted] = @deleted unless @deleted.empty?
24
+ diff[:renamed] = @renamed unless @renamed.empty?
25
+ diff[:signature_changed] = @signature_changed unless @signature_changed.empty?
26
+
27
+ diff
28
+ end
29
+
30
+ private
31
+
32
+ def compute_created
33
+ @created_uids = @current_uid.keys - @old_uid.keys
34
+ @created = @created_uids.map {|uid| {name: @current_uid[uid]['name'], node: @current_uid[uid]['node']}}
35
+ end
36
+
37
+ def compute_deleted
38
+ @deleted_uids = @old_uid.keys - @current_uid.keys
39
+ @deleted = @deleted_uids.map {|uid| {name: @old_uid[uid]['name']}}
40
+ end
41
+
42
+ def compute_renamed
43
+ @renamed = @current_uid.map do |uid, aw|
44
+ next if @created_uids.include?(uid) || @deleted_uids.include?(uid)
45
+ next if @old_uid[uid]['name'] == aw['name']
46
+
47
+ {name: @old_uid[uid]['name'], new_name: aw['name'], node: aw['node']}
48
+ end.compact
49
+ end
50
+
51
+ def compute_signature_changed
52
+ @signature_changed = @current_uid.map do |uid, aw|
53
+ next if @created_uids.include?(uid) || @deleted_uids.include?(uid)
54
+ next if @old_uid[uid]['parameters'] == aw['parameters']
55
+
56
+ {name: aw['name'], node: aw['node']}
57
+ end.compact
58
+ end
59
+
60
+ def map_by_uid(actionwords)
61
+ Hash[actionwords.collect { |aw| [aw['uid'], aw] }]
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,36 @@
1
+ require 'yaml'
2
+
3
+ module Hiptest
4
+ class SignatureExporter
5
+ def self.export_actionwords(project, export_nodes = false)
6
+ exporter = SignatureExporter.new
7
+ exporter.export_actionwords(project.children[:actionwords], export_nodes)
8
+ end
9
+
10
+ def export_actionwords(aws, export_nodes = false)
11
+ aws.children[:actionwords].map {|aw| export_actionword(aw, export_nodes)}
12
+ end
13
+
14
+ def export_item(item, export_node = false)
15
+ hash = {
16
+ 'name' => item.children[:name],
17
+ 'uid' => item.children[:uid],
18
+ 'parameters' => export_parameters(item)
19
+ }
20
+ hash['node'] = item if export_node
21
+ hash
22
+ end
23
+ alias :export_actionword :export_item
24
+ alias :export_scenario :export_item
25
+
26
+ def export_parameters(item)
27
+ item.children[:parameters].map {|p| export_parameter(p)}
28
+ end
29
+
30
+ def export_parameter(parameter)
31
+ {
32
+ 'name' => parameter.children[:name]
33
+ }
34
+ end
35
+ end
36
+ end
@@ -183,9 +183,18 @@ module Hiptest
183
183
  css_first_content(actionword, '> name'),
184
184
  build_tags(actionword),
185
185
  build_parameters(actionword),
186
- build_steps(actionword))
186
+ build_steps(actionword),
187
+ css_first_content(actionword, '> uid'))
188
+ end
189
+
190
+ def build_actionwordSnapshot(actionword)
191
+ Hiptest::Nodes::Actionword.new(
192
+ css_first_content(actionword, '> name'),
193
+ build_tags(actionword),
194
+ build_parameters(actionword),
195
+ build_steps(actionword),
196
+ css_first_content(actionword, '> actionwordUid'))
187
197
  end
188
- alias :build_actionwordSnapshot :build_actionword
189
198
 
190
199
  def build_scenario(scenario)
191
200
  Hiptest::Nodes::Scenario.new(
@@ -5,7 +5,7 @@ class_name_convention = 'camelize'
5
5
  indentation = " "
6
6
  call_prefix = 'actionwords'
7
7
 
8
-
9
8
  [actionwords]
10
9
  filename = 'Actionwords.java'
11
10
  indentation = " "
11
+ naming_convention = 'camelize_lower'
@@ -1,4 +1,4 @@
1
1
  var Actionwords = {{#curly}}{{#indent}}{{#join rendered_children.actionwords ","}}
2
2
  {{{this}}}{{/join}}
3
3
  {{/indent}}
4
- {{/curly}}
4
+ {{/curly}};
@@ -5,3 +5,4 @@ call_prefix = 'actionwords'
5
5
 
6
6
  [actionwords]
7
7
  filename = 'actionwords.js'
8
+ naming_convention = 'camelize_lower'
@@ -5,3 +5,4 @@ call_prefix = 'actionwords'
5
5
 
6
6
  [actionwords]
7
7
  filename = 'actionwords.js'
8
+ naming_convention = 'camelize_lower'
@@ -7,3 +7,4 @@ indentation = " "
7
7
  [actionwords]
8
8
  filename = 'actionwords.py'
9
9
  indentation = " "
10
+ naming_convention = 'underscore'
@@ -6,3 +6,4 @@ indentation = "\t"
6
6
  [actionwords]
7
7
  filename = 'keywords.txt'
8
8
  indentation = "\t"
9
+ naming_convention = 'underscore'
@@ -4,3 +4,4 @@ scenario_filename = '%s_test.rb'
4
4
 
5
5
  [actionwords]
6
6
  filename = 'actionwords.rb'
7
+ naming_convention = 'underscore'
@@ -4,3 +4,4 @@ scenario_filename = '%s_spec.rb'
4
4
 
5
5
  [actionwords]
6
6
  filename = 'actionwords.rb'
7
+ naming_convention = 'underscore'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiptest-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiptest R&D
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -253,6 +253,8 @@ files:
253
253
  - lib/hiptest-publisher/parent_adder.rb
254
254
  - lib/hiptest-publisher/render_context_maker.rb
255
255
  - lib/hiptest-publisher/renderer.rb
256
+ - lib/hiptest-publisher/signature_differ.rb
257
+ - lib/hiptest-publisher/signature_exporter.rb
256
258
  - lib/hiptest-publisher/string.rb
257
259
  - lib/hiptest-publisher/utils.rb
258
260
  - lib/hiptest-publisher/xml_parser.rb