hiptest-publisher 1.13.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config/cucumber-groovy.conf +15 -0
  3. data/lib/config/java-junit.conf +6 -0
  4. data/lib/hiptest-publisher.rb +6 -15
  5. data/lib/hiptest-publisher/{diff_displayer.rb → formatters/diff_displayer.rb} +0 -0
  6. data/lib/hiptest-publisher/formatters/reporter.rb +0 -2
  7. data/lib/hiptest-publisher/{actionword_indexer.rb → indexers/actionword_indexer.rb} +8 -1
  8. data/lib/hiptest-publisher/indexers/actionword_uid_indexer.rb +34 -0
  9. data/lib/hiptest-publisher/node_modifiers/actionword_uniq_renamer.rb +39 -0
  10. data/lib/hiptest-publisher/node_modifiers/add_all.rb +23 -0
  11. data/lib/hiptest-publisher/node_modifiers/call_arguments_adder.rb +52 -0
  12. data/lib/hiptest-publisher/{datatable_fixer.rb → node_modifiers/datatable_fixer.rb} +3 -3
  13. data/lib/hiptest-publisher/node_modifiers/gherkin_adder.rb +243 -0
  14. data/lib/hiptest-publisher/node_modifiers/items_orderer.rb +33 -0
  15. data/lib/hiptest-publisher/{parameter_type_adder.rb → node_modifiers/parameter_type_adder.rb} +15 -14
  16. data/lib/hiptest-publisher/{parent_adder.rb → node_modifiers/parent_adder.rb} +4 -4
  17. data/lib/hiptest-publisher/node_modifiers/uid_call_reference_adder.rb +27 -0
  18. data/lib/hiptest-publisher/nodes.rb +49 -4
  19. data/lib/hiptest-publisher/options_parser.rb +8 -1
  20. data/lib/hiptest-publisher/render_context_maker.rb +28 -8
  21. data/lib/hiptest-publisher/signature_differ.rb +17 -7
  22. data/lib/hiptest-publisher/signature_exporter.rb +18 -4
  23. data/lib/hiptest-publisher/xml_parser.rb +24 -1
  24. data/lib/templates/cucumber/groovy/actionwords-library/actionword.hbs +2 -0
  25. data/lib/templates/cucumber/groovy/actionwords-library/libraries.hbs +9 -0
  26. data/lib/templates/cucumber/groovy/actionwords-library/library.hbs +8 -0
  27. data/lib/templates/cucumber/groovy/actionwords-library/uidcall.hbs +1 -0
  28. data/lib/templates/cucumber/groovy/actionwords/actionwords.hbs +1 -1
  29. data/lib/templates/cucumber/groovy/step-definitions/actionword.hbs +1 -1
  30. data/lib/templates/cucumber/groovy/step-definitions/library.hbs +10 -0
  31. data/lib/templates/gherkin/_call.hbs +5 -0
  32. data/lib/templates/gherkin/call.hbs +1 -5
  33. data/lib/templates/gherkin/uidcall.hbs +1 -0
  34. data/lib/templates/java/_item_as_function.hbs +1 -1
  35. data/lib/templates/java/actionwords.hbs +1 -1
  36. data/lib/templates/java/libraries.hbs +9 -0
  37. data/lib/templates/java/library.hbs +7 -0
  38. data/lib/templates/java/uidcall.hbs +1 -0
  39. metadata +24 -9
  40. data/lib/hiptest-publisher/call_arguments_adder.rb +0 -34
  41. data/lib/hiptest-publisher/items_orderer.rb +0 -31
@@ -0,0 +1,33 @@
1
+ require 'hiptest-publisher/nodes'
2
+
3
+ module Hiptest
4
+ module NodeModifiers
5
+ class ItemsOrderer
6
+ def self.add(project, order)
7
+ self.new(project).order_items(order)
8
+ end
9
+
10
+ def initialize(project)
11
+ @project = project
12
+ end
13
+
14
+ def order_items(order)
15
+ if (order == 'order')
16
+ @project.each_sub_nodes(Hiptest::Nodes::Folder) do |folder|
17
+ folder.children[:scenarios].sort_by! {|sc| sc.order_in_parent}
18
+ folder.children[:subfolders].sort_by! {|f| f.order_in_parent}
19
+ end
20
+ end
21
+
22
+ if (order == 'alpha')
23
+ @project.each_sub_nodes(Hiptest::Nodes::Folder) do |folder|
24
+ folder.children[:scenarios].sort_by! {|sc| sc.children[:name] }
25
+ folder.children[:subfolders].sort_by! {|f| f.children[:name] }
26
+ end
27
+
28
+ @project.children[:scenarios].children[:scenarios].sort_by! {|sc| sc.children[:name] }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,14 +1,13 @@
1
1
  require 'hiptest-publisher/nodes_walker'
2
2
  require 'hiptest-publisher/project_grapher'
3
3
 
4
-
5
4
  module Hiptest
6
- module Nodes
5
+ module NodeModifiers
7
6
  class ParameterTypeAdder
8
7
  attr_reader :call_types
9
8
 
10
9
  def self.add(project)
11
- Hiptest::Nodes::ParameterTypeAdder.new.process(project)
10
+ self.new.process(project)
12
11
  end
13
12
 
14
13
  def initialize
@@ -33,15 +32,15 @@ module Hiptest
33
32
 
34
33
  def gather_scenarios_argument_types(project)
35
34
  project.children[:scenarios].children[:scenarios].each do |scenario|
36
- @call_types.add_callable_item(scenario.children[:name], Scenario)
35
+ @call_types.add_callable_item(scenario.children[:name], Hiptest::Nodes::Scenario)
37
36
  add_arguments_from(scenario.children[:datatable])
38
37
  end
39
38
  end
40
39
 
41
40
  def gather_actionwords_default_parameters_types(project)
42
41
  project.children[:actionwords].children[:actionwords].each do |actionword|
43
- @call_types.add_callable_item(actionword.children[:name], Actionword)
44
- actionword.each_sub_nodes(Parameter) do |parameter|
42
+ @call_types.add_callable_item(actionword.children[:name], Hiptest::Nodes::Actionword)
43
+ actionword.each_sub_nodes(Hiptest::Nodes::Parameter) do |parameter|
45
44
  default = parameter.children[:default]
46
45
  next if default.nil?
47
46
  @call_types.add_argument_type(parameter.children[:name], get_type(default))
@@ -50,20 +49,22 @@ module Hiptest
50
49
  end
51
50
 
52
51
  def gather_call_argument_types(node)
53
- node.each_sub_nodes(Call) do |call|
54
- @call_types.add_callable_item(call.children[:actionword], Actionword)
52
+ node.each_sub_nodes(Hiptest::Nodes::Call, Hiptest::Nodes::UIDCall) do |call|
53
+ actionword_name = call.is_a?(Hiptest::Nodes::Call) ? call.children[:actionword] : call.children[:actionword_name]
54
+
55
+ @call_types.add_callable_item(actionword_name, Hiptest::Nodes::Actionword)
55
56
  add_arguments_from(call, node)
56
57
  end
57
58
  end
58
59
 
59
60
  def write_parameter_types_to_item(callable_item)
60
- callable_item.each_sub_nodes(Parameter) do |parameter|
61
+ callable_item.each_sub_nodes(Hiptest::Nodes::Parameter) do |parameter|
61
62
  parameter.children[:type] = @call_types.type_of(callable_item.children[:name], parameter.children[:name], callable_item.class)
62
63
  end
63
64
  end
64
65
 
65
66
  def add_arguments_from(node, context = nil)
66
- node.each_sub_nodes(Argument) do |argument|
67
+ node.each_sub_nodes(Hiptest::Nodes::Argument) do |argument|
67
68
  @call_types.add_argument_type(argument.children[:name], get_type(argument.children[:value], context))
68
69
  end
69
70
  end
@@ -72,10 +73,10 @@ module Hiptest
72
73
 
73
74
  def get_type(value, context = nil)
74
75
  case value
75
- when StringLiteral, Template then :String
76
- when NumericLiteral then value.children[:value].include?(".") ? :float : :int
77
- when BooleanLiteral then :bool
78
- when Variable then get_var_value(value.children[:name], context)
76
+ when Hiptest::Nodes::StringLiteral, Hiptest::Nodes::Template then :String
77
+ when Hiptest::Nodes::NumericLiteral then value.children[:value].to_s.include?(".") ? :float : :int
78
+ when Hiptest::Nodes::BooleanLiteral then :bool
79
+ when Hiptest::Nodes::Variable then get_var_value(value.children[:name], context)
79
80
  else :null
80
81
  end
81
82
  end
@@ -1,17 +1,17 @@
1
1
  require 'hiptest-publisher/nodes_walker'
2
2
 
3
3
  module Hiptest
4
- module Nodes
4
+ module NodeModifiers
5
5
  class ParentAdder
6
6
  def self.add(project)
7
- Hiptest::Nodes::ParentAdder.new.process(project)
7
+ self.new.process(project)
8
8
  end
9
9
 
10
10
  def process(node)
11
- node.each_direct_children {|child|
11
+ node.each_direct_children do |child|
12
12
  child.parent ||= node
13
13
  process(child)
14
- }
14
+ end
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,27 @@
1
+ require 'hiptest-publisher/indexers/actionword_uid_indexer'
2
+ require 'hiptest-publisher/nodes'
3
+
4
+ module Hiptest
5
+ module NodeModifiers
6
+ class UidCallReferencerAdder
7
+ def self.add(project)
8
+ self.new(project).update_uid_calls
9
+ end
10
+
11
+ def initialize(project)
12
+ @project = project
13
+ @indexer = ActionwordUidIndexer.new(project)
14
+ end
15
+
16
+ def update_uid_calls
17
+ @project.each_sub_nodes(Hiptest::Nodes::UIDCall) do |uid_call|
18
+ index = @indexer.get_index(uid_call.children[:uid])
19
+ next if index.nil?
20
+
21
+ uid_call.children[:actionword_name] = index[:actionword].children[:name]
22
+ uid_call.children[:library_name] = index[:library].children[:name] unless index[:library].nil?
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -235,6 +235,26 @@ module Hiptest
235
235
  end
236
236
  end
237
237
 
238
+ class UIDCall < Node
239
+ attr_reader :chunks, :extra_inlined_arguments
240
+ attr_writer :chunks, :extra_inlined_arguments
241
+
242
+ def initialize(uid, arguments = [], annotation = nil)
243
+ super()
244
+ annotation = nil if annotation == ""
245
+
246
+ @children = {
247
+ uid: uid,
248
+ arguments: arguments,
249
+ all_arguments: arguments,
250
+ annotation: annotation
251
+ }
252
+
253
+ @chunks = []
254
+ @extra_inlined_arguments = []
255
+ end
256
+ end
257
+
238
258
  class IfThen < Node
239
259
  def initialize(condition, then_, else_ = [])
240
260
  super()
@@ -325,8 +345,8 @@ module Hiptest
325
345
  end
326
346
 
327
347
  class Actionword < Item
328
- attr_reader :chunks, :extra_inlined_parameters
329
- attr_writer :chunks, :extra_inlined_parameters
348
+ attr_reader :chunks, :extra_inlined_parameters, :uniq_name
349
+ attr_writer :chunks, :extra_inlined_parameters, :uniq_name
330
350
 
331
351
  def initialize(name, tags = [], parameters = [], body = [], uid = nil, description = '')
332
352
  super(name, tags, description, parameters, body)
@@ -334,6 +354,7 @@ module Hiptest
334
354
 
335
355
  @chunks = []
336
356
  @extra_inlined_parameters = []
357
+ @uniq_name = name
337
358
  end
338
359
 
339
360
  def must_be_implemented?
@@ -529,8 +550,27 @@ module Hiptest
529
550
  end
530
551
  end
531
552
 
553
+ class Libraries < Node
554
+ def initialize(libraries = [])
555
+ super()
556
+ @children = {
557
+ libraries: libraries
558
+ }
559
+ end
560
+ end
561
+
562
+ class Library < Node
563
+ def initialize(name = 'default_library', actionwords = [])
564
+ super()
565
+ @children = {
566
+ name: name,
567
+ actionwords: actionwords
568
+ }
569
+ end
570
+ end
571
+
532
572
  class Project < Node
533
- def initialize(name, description = '', test_plan = TestPlan.new, scenarios = Scenarios.new, actionwords = Actionwords.new, tests = Tests.new)
573
+ def initialize(name, description = '', test_plan = TestPlan.new, scenarios = Scenarios.new, actionwords = Actionwords.new, tests = Tests.new, libraries = Libraries.new)
534
574
  super()
535
575
  test_plan.parent = self if test_plan.respond_to?(:parent=)
536
576
  scenarios.parent = self
@@ -542,10 +582,15 @@ module Hiptest
542
582
  test_plan: test_plan,
543
583
  scenarios: scenarios,
544
584
  actionwords: actionwords,
545
- tests: tests
585
+ tests: tests,
586
+ libraries: libraries
546
587
  }
547
588
  end
548
589
 
590
+ def has_libraries?
591
+ !children[:libraries].children[:libraries].empty?
592
+ end
593
+
549
594
  def assign_scenarios_to_folders
550
595
  @children[:scenarios].children[:scenarios].each do |scenario|
551
596
  folder = @children[:test_plan].find_folder_by_uid(scenario.folder_uid)
@@ -228,6 +228,7 @@ class OptionsParser
228
228
  Option.new(nil, 'show-actionwords-renamed', false, nil, "Output signatures of renamed action words", :aw_renamed),
229
229
  Option.new(nil, 'show-actionwords-signature-changed', false, nil, "Output signatures of action words for which signature changed", :aw_signature_changed),
230
230
  Option.new(nil, 'show-actionwords-definition-changed', false, nil, "Output action words for which definition changed", :aw_definition_changed),
231
+ Option.new(nil, 'library-name=LIBRARY_NAME', nil, String, "Use in conjunction with show-actionwords-*: show the diff for the specified library", :library_name),
231
232
  Option.new(nil, 'with-folders', false, nil, "Use folders hierarchy to export files in respective directories", :with_folders),
232
233
  Option.new(nil, 'empty-folders', false, nil, "Export empty folders", :empty_folders),
233
234
  Option.new(nil, 'split-scenarios', false, nil, "Export each scenario in a single file (except for Gherkin based languages)", :split_scenarios),
@@ -485,7 +486,7 @@ class LanguageGroupConfig
485
486
 
486
487
  def nodes(project)
487
488
  case node_name
488
- when :tests, :scenarios, :actionwords
489
+ when :tests, :scenarios, :actionwords, :libraries
489
490
  if splitted_files?
490
491
  project.children[node_name].children[node_name]
491
492
  elsif with_folders?
@@ -493,6 +494,8 @@ class LanguageGroupConfig
493
494
  else
494
495
  [project.children[node_name]]
495
496
  end
497
+ when :library
498
+ [project.children[:libraries]]
496
499
  when :folders
497
500
  get_folder_nodes(project)
498
501
  end
@@ -608,6 +611,10 @@ class LanguageGroupConfig
608
611
  @leafless_export ? :tests : :scenarios
609
612
  elsif self[:node_name] == "actionwords" || self[:group_name] == "actionwords"
610
613
  :actionwords
614
+ elsif self[:node_name] == "libraries" || self[:group_name] == "libraries"
615
+ :libraries
616
+ elsif self[:node_name] == "library" || self[:group_name] == "library"
617
+ :library
611
618
  elsif self[:node_name] == "folders"
612
619
  :folders
613
620
  else
@@ -9,7 +9,7 @@ module Hiptest
9
9
  is_empty?: item.children[:body].empty?,
10
10
  declared_variables: item.declared_variables_names,
11
11
  raw_parameter_names: item.children[:parameters].map {|p| p.children[:name] },
12
- self_name: item.children[:name],
12
+ self_name: item.children[:name]
13
13
  }
14
14
  end
15
15
 
@@ -27,10 +27,20 @@ module Hiptest
27
27
  chunks: aw.chunks || [],
28
28
  extra_inlined_parameters: aw.extra_inlined_parameters || [],
29
29
  has_free_text_parameter?: aw.children[:parameters].select(&:free_text?).count > 0,
30
- has_datatable_parameter?: aw.children[:parameters].select(&:datatable?).count > 0
30
+ has_datatable_parameter?: aw.children[:parameters].select(&:datatable?).count > 0,
31
+ uniq_name: aw.uniq_name,
32
+ has_library?: (aw.parent.is_a? Hiptest::Nodes::Library) ? true : false,
33
+ library_name: aw.parent.nil? ? '' : aw.parent.children[:name]
31
34
  )
32
35
  end
33
36
 
37
+ def walk_actionwords(aws)
38
+ project = aws.parent
39
+ {
40
+ uses_library?: project.nil? ? false : project.has_libraries?
41
+ }
42
+ end
43
+
34
44
  def walk_folder(folder)
35
45
  walk_relative_item(folder).merge(
36
46
  self_name: folder.children[:name],
@@ -45,7 +55,8 @@ module Hiptest
45
55
  walk_item(scenario).merge(walk_relative_item(scenario)).merge(
46
56
  project_name: scenario.parent.parent.children[:name],
47
57
  has_datasets?: has_datasets?(scenario),
48
- has_annotations?: has_annotations?(scenario)
58
+ has_annotations?: has_annotations?(scenario),
59
+ uniq_name: scenario.children[:name]
49
60
  )
50
61
  end
51
62
 
@@ -65,10 +76,6 @@ module Hiptest
65
76
  }
66
77
  end
67
78
 
68
- def walk_actionwords(aws)
69
- {}
70
- end
71
-
72
79
  def walk_test(test)
73
80
  {
74
81
  has_description?: !test.children[:description].nil? && !test.children[:description].empty?,
@@ -78,7 +85,7 @@ module Hiptest
78
85
  is_empty?: test.children[:body].empty?,
79
86
  has_datasets?: false,
80
87
  project_name: test.parent.parent.children[:name],
81
- self_name: test.children[:name],
88
+ self_name: test.children[:name]
82
89
  }
83
90
  end
84
91
 
@@ -101,6 +108,13 @@ module Hiptest
101
108
  }
102
109
  end
103
110
 
111
+ def walk_uidcall(uidcall)
112
+ {
113
+ has_library?: !uidcall.children[:library_name].nil?,
114
+ chunks: uidcall.chunks || []
115
+ }
116
+ end
117
+
104
118
  def walk_ifthen(it)
105
119
  {
106
120
  has_else?: !it.children[:else].empty?
@@ -137,6 +151,12 @@ module Hiptest
137
151
  }
138
152
  end
139
153
 
154
+ def walk_libraries(libraries)
155
+ {
156
+ library_names: libraries.children[:libraries].map {|lib| lib.children[:name]}
157
+ }
158
+ end
159
+
140
160
  private
141
161
 
142
162
  def has_step?(item)
@@ -1,7 +1,7 @@
1
1
  module Hiptest
2
2
  class SignatureDiffer
3
- def self.diff(old, current)
4
- SignatureDiffer.new(old, current).compute_diff
3
+ def self.diff(old, current, library_name: nil)
4
+ SignatureDiffer.new(old, current).compute_diff(library_name)
5
5
  end
6
6
 
7
7
  def initialize(old, current)
@@ -9,9 +9,14 @@ module Hiptest
9
9
  @current = current
10
10
  end
11
11
 
12
- def compute_diff
13
- @old_uid = map_by_uid(@old)
14
- @current_uid = map_by_uid(@current)
12
+ def compute_diff(library_name = nil)
13
+ if library_name.nil?
14
+ @old_uid = map_by_uid(@old)
15
+ @current_uid = map_by_uid(@current)
16
+ else
17
+ @old_uid = map_by_uid(get_library_actionwords(@old, library_name))
18
+ @current_uid = map_by_uid(get_library_actionwords(@current, library_name))
19
+ end
15
20
 
16
21
  compute_created
17
22
  compute_deleted
@@ -88,8 +93,13 @@ module Hiptest
88
93
  end.compact
89
94
  end
90
95
 
91
- def map_by_uid(actionwords)
92
- Hash[actionwords.collect { |aw| [aw['uid'], aw] }]
96
+ def get_library_actionwords(data, library_name)
97
+ library = data.select {|item| item['type'] == 'library' && item['name'] == library_name}.first
98
+ library.nil? ? [] : library['actionwords']
99
+ end
100
+
101
+ def map_by_uid(items)
102
+ Hash[items.reject {|item| item['type'] == 'library'}.collect { |aw| [aw['uid'], aw] }]
93
103
  end
94
104
  end
95
105
  end
@@ -5,14 +5,30 @@ module Hiptest
5
5
  class SignatureExporter
6
6
  def self.export_actionwords(project, export_nodes = false)
7
7
  exporter = SignatureExporter.new
8
- exporter.export_actionwords(project.children[:actionwords], export_nodes)
8
+
9
+ [
10
+ exporter.export_actionwords(project.children[:actionwords], export_nodes),
11
+ exporter.export_libraries(project.children[:libraries], export_nodes)
12
+ ].flatten
9
13
  end
10
14
 
11
15
  def export_actionwords(aws, export_nodes = false)
12
16
  aws.children[:actionwords].map {|aw| export_actionword(aw, export_nodes)}
13
17
  end
14
18
 
15
- def export_item(item, export_node = false)
19
+ def export_libraries(libraries, export_nodes = false)
20
+ libraries.children[:libraries].map {|lib| export_library(lib, export_nodes)}
21
+ end
22
+
23
+ def export_library(library, export_nodes = false)
24
+ {
25
+ 'name' => library.children[:name],
26
+ 'type' => 'library',
27
+ 'actionwords' => library.children[:actionwords].map {|aw| export_actionword(aw, export_nodes) }
28
+ }
29
+ end
30
+
31
+ def export_actionword(item, export_node = false)
16
32
  hash = {
17
33
  'name' => item.children[:name],
18
34
  'uid' => item.children[:uid],
@@ -22,8 +38,6 @@ module Hiptest
22
38
  hash['node'] = item if export_node
23
39
  hash
24
40
  end
25
- alias :export_actionword :export_item
26
- alias :export_scenario :export_item
27
41
 
28
42
  def export_parameters(item)
29
43
  item.children[:parameters].map {|p| export_parameter(p)}