cucumber-performance-generator 0.0.2 → 0.0.3

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: 1990a57ac18ce1535cccf5693fb57565a06d4aad
4
- data.tar.gz: 9f1f508fd5186c834fce699fab2cd0735bf18115
3
+ metadata.gz: 9dda1580907bf1af524c86537d88bba456c2ea21
4
+ data.tar.gz: b9314f332ed6299d6bf73357cfa7a79d3c3e62e7
5
5
  SHA512:
6
- metadata.gz: 9e17f72e49e609e340f522a50fd289f163e85b5caddb148886cfc89cb659f97a358ced01e0ff21b293ccabb8ba40dd1b30dccdecf37f28e1851a1eaf0350468d
7
- data.tar.gz: e1170b3522170d0ab3cd3495953aa9ed84c58bcdacb4e234bffc45a798c2db68d0db0c84e0fc328fbe58335f39a476eff02411ef81612553c0ba99c79bb84f04
6
+ metadata.gz: db44c8205309622bca53d12c960e483dc0d2a731b00be1da554abf194779027999695acb24937edaf2793b803eb524e6b85ad8fa612b373033c51760bbfee839
7
+ data.tar.gz: cfa0ecd04a78738ce4430df76b1a64866751fb82c50468ce1daaaff5ccdb9b02b98dd4ab9eae1c819b55911c6f9e6587aa35f1d5beff92a5ad0ebede66a46a79
@@ -60,6 +60,67 @@ def recursive_list_variable(variable, prev = '')
60
60
  end
61
61
 
62
62
 
63
+
64
+
65
+ #####
66
+ ## Function: recursive_escape_hasharray
67
+ ## Inputs: variable (any Hash/Array/nil) prev (string of current path)
68
+ ## Outputs: Flat hash (key = path, value = value)
69
+ ## Description: This function creates a flat hash of the object so it can be
70
+ ## easily used to paramterise the performance script.
71
+ ## This is a recursive function.
72
+ #####
73
+ def recursive_escape_hasharray(variable, char='"')
74
+
75
+ # create the hash
76
+
77
+ data = variable
78
+
79
+ ## If the variable is an array we need to use .each_with_index.
80
+ if (variable.kind_of?(Array)) then
81
+
82
+ # Loop through the items of the array
83
+ variable.each_with_index do |value, key|
84
+
85
+ # If the child is either an Array or Hash then it needs to be put
86
+ # back into this function.
87
+ if ((variable[key].kind_of?(Array)) || (variable[key].kind_of?(Hash))) then
88
+ data[key] = recursive_escape_hasharray(variable[key])
89
+ elsif (variable[key].kind_of?(String))
90
+ data[key] = value.gsub(/#{char}/, '\\' + char)
91
+ else
92
+ data[key] = value
93
+ end
94
+ end
95
+
96
+ # The same code as above, but instead needs to use .each
97
+ elsif (variable.kind_of?(Hash)) then
98
+
99
+ # Loop through the items of the array
100
+ variable.each do |key, value|
101
+
102
+ # If the child is either an Array or Hash then it needs to be put
103
+ # back into this function.
104
+ if ((variable[key].kind_of?(Array)) || (variable[key].kind_of?(Hash))) then
105
+ data[key] = recursive_escape_hasharray(variable[key])
106
+ elsif (variable[key].kind_of?(String))
107
+ data[key] = value.gsub(/#{char}/, '\\' + char)
108
+ else
109
+ data[key] = value
110
+ end
111
+
112
+ end
113
+ # If it is nil, then we need to return a hash still, this will be reworked in the future
114
+ end
115
+
116
+ # Return data hash
117
+ return data
118
+ end
119
+
120
+
121
+
122
+
123
+
63
124
  #####
64
125
  ## Function: generate_performance_test_script
65
126
  ## Inputs: scenario object (this contains data about the scenario. i.e. name)
@@ -99,10 +160,12 @@ def generate_performance_test_script(scenario)
99
160
  end
100
161
 
101
162
 
163
+
164
+
102
165
  # Lets create the basic structure of the file
103
166
  file_structure = %{
104
167
 
105
- # Scenario Name: #{scenario.name}
168
+ # Scenario Name: #{scenario.name}
106
169
 
107
170
  class #{scenario_name}
108
171
 
@@ -121,20 +184,14 @@ def generate_performance_test_script(scenario)
121
184
  @curl.follow_location = true
122
185
  @curl.enable_cookies = true
123
186
 
124
- #v_action end
125
- end
126
187
 
127
- def v_end()
128
-
129
- #v_end end
130
- end
131
-
132
- end
133
188
 
134
189
  }
135
190
 
191
+ write_line_to_performance_test_file(perf_file_name, file_structure, true)
192
+
136
193
  # Lets write that to a file
137
- File.open(perf_file_name, 'w') { |file| file.write(file_structure) }
194
+ #File.open(perf_file_name, 'w') { |file| file.write(file_structure) }
138
195
 
139
196
  end
140
197
 
@@ -169,7 +226,10 @@ def generate_performance_test_script(scenario)
169
226
  # the variable $function_call_data contains the data that is returned
170
227
  # from each function. However this data is nested in a hash.
171
228
  # We need to get a flat structure.
172
- value_list = recursive_list_variable($function_call_data[i2])
229
+
230
+ temp_function_call_data = recursive_escape_hasharray($function_call_data[i2])
231
+
232
+ value_list = recursive_list_variable(temp_function_call_data)
173
233
  # Loop through the flat structure results to do a replace
174
234
  # on the value with a variable
175
235
  value_list.each do |data_key, data_value|
@@ -198,7 +258,9 @@ def generate_performance_test_script(scenario)
198
258
  # the variable $function_call_data contains the data that is returned
199
259
  # from each function. However this data is nested in a hash.
200
260
  # We need to get a flat structure.
201
- value_list = recursive_list_variable($function_call_data[i2])
261
+
262
+ temp_function_call_data = recursive_escape_hasharray($function_call_data[i2])
263
+ value_list = recursive_list_variable(temp_function_call_data)
202
264
  # Loop through the flat structure results to do a replace
203
265
  # on the value with a variable
204
266
  value_list.each do |data_key, data_value|
@@ -212,8 +274,10 @@ def generate_performance_test_script(scenario)
212
274
  func_value = func_value.gsub(/\=\>"#{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}\}"/is, '=>"#{' + "genData#{i2}" + data_key + '}"}')
213
275
  func_value = func_value.gsub(/\["#{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}"\]/is, '["#{' + "genData#{i2}" + data_key + '}"]')
214
276
 
277
+ func_value = func_value.gsub(/ #{data_value.to_s.gsub('(', '\(').gsub(')', '\)')},/is, " genData#{i2}" + data_key + ',')
278
+ func_value = func_value.gsub(/ #{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}\)/is, " genData#{i2}" + data_key + ')')
279
+ func_value = func_value.gsub(/ #{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}\]/is, " genData#{i2}" + data_key + ']')
215
280
 
216
- func_value = func_value.gsub(/ #{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}/is, " genData#{i2}" + data_key)
217
281
  func_value = func_value.gsub(/#{data_value.to_s.gsub('(', '\(').gsub(')', '\)')},/is, "genData#{i2}" + data_key + ',')
218
282
  func_value = func_value.gsub(/\=\>#{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}\}/is, '=>' + "genData#{i2}" + data_key + '}')
219
283
  func_value = func_value.gsub(/\[#{data_value.to_s.gsub('(', '\(').gsub(')', '\)')}\]/is, '[' + "genData#{i2}" + data_key + ']')
@@ -247,11 +311,11 @@ def generate_performance_test_script(scenario)
247
311
 
248
312
  end
249
313
 
250
-
314
+ $transaction_count += 1
251
315
  # We are going to put transactions in based on the step being executed
252
316
  v_action_text = %{
253
317
 
254
- trans_time = start_traction("#{step_name}")
318
+ trans_time#{$transaction_count} = start_traction("#{step_name}")
255
319
  }
256
320
 
257
321
  write_line_to_performance_test_file(perf_file_name, v_action_text, true)
@@ -407,6 +471,7 @@ def generate_performance_test_script(scenario)
407
471
  response = http_get(@curl, data, "#{request_url}")
408
472
  }
409
473
 
474
+
410
475
  end
411
476
 
412
477
  # write the http (get or post) call
@@ -436,7 +501,7 @@ def generate_performance_test_script(scenario)
436
501
 
437
502
  # End the transaction
438
503
  v_action_text = %{
439
- end_traction("#{step_name}", trans_time)
504
+ end_traction("#{step_name}", trans_time#{$transaction_count})
440
505
  }
441
506
 
442
507
  write_line_to_performance_test_file(perf_file_name, v_action_text, true)
@@ -491,6 +556,8 @@ def decode_value(variable_item)
491
556
  end
492
557
 
493
558
 
559
+
560
+
494
561
  #####
495
562
  ## Function: write_line_to_performance_test_file
496
563
  ## Inputs: perf_file_name (String) v_action_text (String)
@@ -499,17 +566,15 @@ end
499
566
  #####
500
567
  def write_line_to_performance_test_file(perf_file_name, v_action_text, doublespace = false)
501
568
 
502
- # Open the file to read
503
- file_text = File.read(File.expand_path(perf_file_name).to_s)
504
- # get the text of the file and add the new code to the end of #v_action end
505
- if doublespace == true then
506
- file_text_mod = file_text.gsub('#v_action end', ' ' + v_action_text.strip + "\n\n" + '#v_action temp end')
507
- else
508
- file_text_mod = file_text.gsub('#v_action end', ' ' + v_action_text.strip + "\n" + '#v_action temp end')
569
+ $performance_file_lines = $performance_file_lines + ' ' + v_action_text.strip + "\n"
570
+
571
+ if (doublespace == true) then
572
+ $performance_file_lines = $performance_file_lines + "\n"
573
+
509
574
  end
510
- # Add the v#_action_end text back it. Doing this with the temp stops a recursive command
511
- file_text_mod = file_text_mod.gsub('#v_action temp end', '#v_action end')
512
- # Write it back to the file
513
- open(perf_file_name, 'w') { |file| file.puts(File.expand_path(file_text_mod).to_s) }
514
575
 
515
576
  end
577
+
578
+ def write_performance_file(perf_file_name)
579
+ open(File.expand_path(perf_file_name).to_s, 'w') { |file| file.puts($performance_file_lines) }
580
+ end
@@ -1,16 +1,23 @@
1
1
 
2
2
  Before do | scenario |
3
3
 
4
- $step = 0
4
+ if (!ENV['GENERATE_PERFORMANCE_SCRIPT'].nil?) then
5
+
6
+ $step = 0
7
+
8
+ $function_call_name = []
9
+ $function_call_data = []
10
+ $function_call_arguments = []
11
+ $function_call_start = 0
5
12
 
6
- $function_call_name = []
7
- $function_call_data = []
8
- $function_call_arguments = []
9
- $function_call_start = 0
13
+ $file_not_created = true
10
14
 
11
- $file_not_created = true
15
+ $performance_file_lines = ''
12
16
 
13
- page.driver.clear_network_traffic
17
+ $transaction_count = 0
18
+
19
+ page.driver.clear_network_traffic
20
+ end
14
21
 
15
22
  end
16
23
 
@@ -19,3 +26,34 @@ AfterStep do | scenario |
19
26
  generate_performance_test_script(scenario)
20
27
  end
21
28
  end
29
+
30
+
31
+ After do |scenario|
32
+
33
+ if (!ENV['GENERATE_PERFORMANCE_SCRIPT'].nil?) then
34
+
35
+ if ($performance_file_lines != '') then
36
+
37
+ scenario_name = scenario.name.gsub('(','').gsub(')', '').gsub(/ /, '_').capitalize
38
+
39
+ perf_file_name = 'performanceTests/' + scenario_name.downcase + '.rb'
40
+
41
+
42
+ file_structure_end = %{
43
+ end
44
+
45
+ def v_end()
46
+
47
+ #v_end end
48
+ end
49
+
50
+ end
51
+
52
+ }
53
+
54
+ write_line_to_performance_test_file(perf_file_name, file_structure_end, true)
55
+ write_performance_file(perf_file_name)
56
+ end
57
+ end
58
+
59
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-performance-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: poltergeist