itriagetestrail 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f35d2994320ffa218fcd8ab70a15b9b97e23b07a
4
- data.tar.gz: 7448966bf55811e48f275701d95f6bdbefc7e1c1
3
+ metadata.gz: 10cdea2dd4ae8d6f5dbd2cbe96e9083d90b556aa
4
+ data.tar.gz: 8a6bf7878edd7504570caafbf707f6f2ae49720b
5
5
  SHA512:
6
- metadata.gz: a4242607687c8b7d51d025810e66fc7a9cf67f9b8dc84d4f8b7504a53ebcbef9d9aae8dc1b78f4a0378a5d6ebf10c33f127867c2f61f7a9204991636f91dc42d
7
- data.tar.gz: 70e37c17bee8cb1f4ba95ac4d28d0eb13c8177e04a20b17f242dc49b4f71947b2177f7d2a6d3e5060bbe390cf79371ef1353d67d5e80332e05cb65aba58d9997
6
+ metadata.gz: 18fc8c673d326c649658fd91a87424131100fef5373f4b740a8698dc43207664be64701c0acf26bbdcdc111e2a4b4fb9623d199ecf3496dbd932886cd231200e
7
+ data.tar.gz: d33b1178702724ba819ecc293a85e86687550b470a43307b3d140d01aa62665e3fc7d2b9501de97334b63ed5c5b38d494e9bf6fc81f3d0b5efd56b5eab4c3e2d
@@ -37,6 +37,22 @@ module Itriagetestrail
37
37
  attr_reader :results
38
38
  attr_reader :external_results
39
39
 
40
+ def _time_zone
41
+ @time_zone = if @testrail_config[:tzinfoTimeZone].nil? || @testrail_config[:tzinfoTimeZone].empty?
42
+ TZInfo::Timezone.get('UTC')
43
+ else
44
+ TZInfo::Timezone.get(@testrail_config[:tzinfoTimeZone])
45
+ end
46
+ end
47
+
48
+ def _execute
49
+ @execute = if @testrail_config[:user].nil? || @testrail_config[:user].empty?
50
+ false
51
+ else
52
+ true
53
+ end
54
+ end
55
+
40
56
  def initialize
41
57
  @setup = false
42
58
  config
@@ -55,17 +71,9 @@ module Itriagetestrail
55
71
  @app_version = @testrail_config[:appVersion]
56
72
  @suite_name = @testrail_config[:suiteName]
57
73
 
58
- @time_zone = if @testrail_config[:tzinfoTimeZone].nil? || @testrail_config[:tzinfoTimeZone].empty?
59
- TZInfo::Timezone.get('UTC')
60
- else
61
- TZInfo::Timezone.get(@testrail_config[:tzinfoTimeZone])
62
- end
74
+ _time_zone
63
75
 
64
- @execute = if @testrail_config[:user].nil? || @testrail_config[:user].empty?
65
- false
66
- else
67
- true
68
- end
76
+ _execute
69
77
 
70
78
  clear_results
71
79
  @submitted = { results: [] }
@@ -146,12 +154,8 @@ module Itriagetestrail
146
154
 
147
155
  reset_milestone(@milestone_name)
148
156
 
149
- if !configuration_ids.empty? && false # disable configurations for now
150
- add_testrail_plan if @plan_id == 0
151
- add_plan_entry if @run_id == 0
152
- else
153
- add_testrail_run if @run_id == 0
154
- end
157
+ # TODO: Look into configuration_ids to add a plan
158
+ add_testrail_run if @run_id.zero?
155
159
 
156
160
  @pool = Pool.new(1)
157
161
 
@@ -3,27 +3,32 @@
3
3
  require 'itriagetestrail'
4
4
  module Itriagetestrail
5
5
  class TRCucumber13 < TestRailInterface
6
+ def scenario_title_and_external_id(scenario)
7
+ if scenario.class.to_s == 'Cucumber::Ast::OutlineTable::ExampleRow'
8
+ scenario_cell_id = []
9
+ scenario.name.split('|')[1..50].each { |cell| scenario_cell_id << cell.gsub(/[\| "]/, '') }
10
+ @scenario_title = "#{scenario.scenario_outline.title}, Example: #{scenario_cell_id}"
11
+ @external_id = "#{scenario.scenario_outline.feature.name};#{@scenario_title}"[0, 249]
12
+ @scenario_steps = scenario.scenario_outline.raw_steps.select { 'name' }.collect(&:name).join("\n")
13
+ else
14
+ # identifiers: scenario.feature.name, scenario.name
15
+ @external_id = "#{scenario.feature.title};#{scenario.title}"
16
+ @scenario_title = scenario.title
17
+ @scenario_steps = scenario.steps.select { 'name' }.collect(&:name).join("\n")
18
+ end
19
+ end
20
+
6
21
  def record_result(scenario)
7
22
  return if execute == false
8
23
  begin
9
- if scenario.class.to_s == 'Cucumber::Ast::OutlineTable::ExampleRow'
10
- scenario_cell_id = []
11
- scenario.name.split('|')[1..50].each { |cell| scenario_cell_id << cell.gsub(/[\| "]/, '') }
12
- @scenario_title = "#{scenario.scenario_outline.title}, Example: #{scenario_cell_id}"
13
- @external_id = "#{scenario.scenario_outline.feature.name};#{@scenario_title}"[0, 249]
14
- @scenario_steps = scenario.scenario_outline.raw_steps.select { 'name' }.collect(&:name).join("\n")
15
- else
16
- # identifiers: scenario.feature.name, scenario.name
17
- @external_id = "#{scenario.feature.title};#{scenario.title}"
18
- @scenario_title = scenario.title
19
- @scenario_steps = scenario.steps.select { 'name' }.collect(&:name).join("\n")
20
- end
24
+ scenario_title_and_external_id(scenario)
21
25
 
22
26
  if scenario.passed?
23
27
  store_result(@scenario_title, @external_id, @scenario_steps, 1, '')
24
28
  else
25
29
  store_result(@scenario_title, @external_id, @scenario_steps,
26
- (ENV['RERUN'] ? 5 : 4).to_s.to_i, "#{scenario.exception.class}\n#{scenario.exception}\n#{scenario.exception.backtrace}")
30
+ (ENV['RERUN'] ? 5 : 4).to_s.to_i, "#{scenario.exception.class}\n" \
31
+ "#{scenario.exception}\n#{scenario.exception.backtrace}")
27
32
  end
28
33
  rescue StandardError => exception
29
34
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
@@ -31,11 +36,10 @@ module Itriagetestrail
31
36
  end
32
37
 
33
38
  def shutdown
34
- if execute
35
- sleep 3 # testrail service rate limit precaution
36
- send_results_to_testrail
37
- super
38
- end
39
+ break unless execute
40
+ sleep 3 # testrail service rate limit precaution
41
+ send_results_to_testrail
42
+ super
39
43
  end
40
44
  end
41
45
  end
@@ -3,17 +3,21 @@
3
3
  require 'itriagetestrail'
4
4
  module Itriagetestrail
5
5
  class TRCucumber20 < TestRailInterface
6
+ def scenario_title_and_external_id(scenario)
7
+ if scenario.class.to_s == 'Cucumber::RunningTestCase::ScenarioOutlineExample'
8
+ scenario.cell_values.each { |cell| cell.gsub!(/\s+/, '') }
9
+ @scenario_title = "#{scenario.name.match(/\b.*Example/)}: #{scenario.cell_values}"
10
+ @external_id = "#{scenario.feature.short_name}\;#{@scenario_title}"[0, 249]
11
+ else
12
+ @external_id = "#{scenario.feature.short_name}\;#{scenario.name}"
13
+ @scenario_title = scenario.name
14
+ end
15
+ end
16
+
6
17
  def record_result(scenario)
7
18
  return if execute == false
8
19
  begin
9
- if scenario.class.to_s == 'Cucumber::RunningTestCase::ScenarioOutlineExample'
10
- scenario.cell_values.each { |cell| cell.gsub!(/\s+/, '') }
11
- @scenario_title = "#{scenario.name.match(/\b.*Example/)}: #{scenario.cell_values}"
12
- @external_id = "#{scenario.feature.short_name}\;#{@scenario_title}"[0, 249]
13
- else
14
- @external_id = "#{scenario.feature.short_name}\;#{scenario.name}"
15
- @scenario_title = scenario.name
16
- end
20
+ scenario_title_and_external_id(scenario)
17
21
 
18
22
  @scenario_steps = scenario.test_steps.select { 'name' }.collect(&:name).join("\n")
19
23
 
@@ -21,7 +25,8 @@ module Itriagetestrail
21
25
  store_result(@scenario_title, @external_id, @scenario_steps, 1, '')
22
26
  else
23
27
  store_result(@scenario_title, @external_id, @scenario_steps,
24
- (ENV['RERUN'] ? 5 : 4).to_s.to_i, "#{scenario.exception.class}\n#{scenario.exception}\n#{scenario.exception.backtrace}")
28
+ (ENV['RERUN'] ? 5 : 4).to_s.to_i, "#{scenario.exception.class}\n" \
29
+ "#{scenario.exception}\n#{scenario.exception.backtrace}")
25
30
  end
26
31
  rescue StandardError => exception
27
32
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
@@ -29,11 +34,10 @@ module Itriagetestrail
29
34
  end
30
35
 
31
36
  def shutdown
32
- if execute
33
- sleep 3 # testrail service rate limit precaution
34
- send_results_to_testrail
35
- super
36
- end
37
+ break unless execute
38
+ sleep 3 # testrail service rate limit precaution
39
+ send_results_to_testrail
40
+ super
37
41
  end
38
42
  end
39
43
  end
@@ -3,27 +3,30 @@
3
3
  require 'itriagetestrail'
4
4
  module Itriagetestrail
5
5
  class TRCucumber30 < TestRailInterface
6
+ def scenario_title_and_external_id(scenario)
7
+ if scenario.class.to_s == 'Cucumber::RunningTestCase::ScenarioOutlineExample'
8
+ # Remove spaces within cells to match our Cucumber 1.3 implementation
9
+ scenario.cell_values.each { |cell| cell.gsub!(/\s+/, '') }
10
+ @scenario_title = "#{scenario.name.match(/\b.*Example/)}: #{scenario.cell_values}"
11
+ @external_id = "#{scenario.feature.short_name}\;#{@scenario_title}"[0, 249]
12
+ else
13
+ @external_id = "#{scenario.feature.short_name}\;#{scenario.name}"
14
+ @scenario_title = scenario.name
15
+ end
16
+ end
17
+
6
18
  def record_result(scenario)
7
19
  return if execute == false
8
20
  begin
9
- if scenario.class.to_s == 'Cucumber::RunningTestCase::ScenarioOutlineExample'
10
-
11
- # Remove spaces within cells to match our Cucumber 1.3 implementation
12
- scenario.cell_values.each { |cell| cell.gsub!(/\s+/, '') }
13
- @scenario_title = "#{scenario.name.match(/\b.*Example/)}: #{scenario.cell_values}"
14
- @external_id = "#{scenario.feature.short_name}\;#{@scenario_title}"[0, 249]
15
- else
16
- @external_id = "#{scenario.feature.short_name}\;#{scenario.name}"
17
- @scenario_title = scenario.name
18
- end
19
-
21
+ scenario_title_and_external_id(scenario)
20
22
  @scenario_steps = scenario.test_steps.collect(&:text).join("\n")
21
23
 
22
24
  if scenario.passed?
23
25
  store_result(@scenario_title, @external_id, @scenario_steps, 1, '')
24
26
  else
25
27
  store_result(@scenario_title, @external_id, @scenario_steps,
26
- (ENV['RERUN'] ? 5 : 4).to_s.to_i, "#{scenario.exception.class}\n#{scenario.exception}\n#{scenario.exception.backtrace}")
28
+ (ENV['RERUN'] ? 5 : 4).to_s.to_i, "#{scenario.exception.class}" \
29
+ "\n#{scenario.exception}\n#{scenario.exception.backtrace}")
27
30
  end
28
31
  rescue StandardError => exception
29
32
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
@@ -31,11 +34,10 @@ module Itriagetestrail
31
34
  end
32
35
 
33
36
  def shutdown
34
- if execute
35
- sleep 3 # testrail service rate limit precaution
36
- send_results_to_testrail
37
- super
38
- end
37
+ break unless execute
38
+ sleep 3 # testrail service rate limit precaution
39
+ send_results_to_testrail
40
+ super
39
41
  end
40
42
  end
41
43
  end
@@ -20,11 +20,10 @@ module Itriagetestrail
20
20
  end
21
21
 
22
22
  def shutdown
23
- if execute
24
- sleep 3 # testrail service rate limit precaution
25
- send_results_to_testrail
26
- super
27
- end
23
+ break unless execute
24
+ sleep 3 # testrail service rate limit precaution
25
+ send_results_to_testrail
26
+ super
28
27
  end
29
28
  end
30
29
  end
@@ -74,7 +74,24 @@ module TestRail
74
74
  conn
75
75
  end
76
76
 
77
- private
77
+ def _parse_result(response)
78
+ if response.body && !response.body.empty?
79
+ JSON.parse(response.body)
80
+ else
81
+ {}
82
+ end
83
+ end
84
+
85
+ def _error_check(response, result)
86
+ break if response.code == '200'
87
+ error = if result&.key?('error')
88
+ '"' + result['error'] + '"'
89
+ else
90
+ 'No additional error message received'
91
+ end
92
+ raise APIError, format('TestRail API returned HTTP %<response_code>s\n%<error>s',
93
+ response_code: response.code, error: error)
94
+ end
78
95
 
79
96
  def _send_request(method, uri, data)
80
97
  url = URI.parse(@url + uri)
@@ -97,7 +114,8 @@ module TestRail
97
114
  sleep(response.header['retry-after'].to_i)
98
115
  elsif response.code == '500'
99
116
  puts response.to_s
100
- # this might require different handling for 500 'Deadlock found when trying to get lock; try restarting transaction'
117
+ # this might require different handling for 500 'Deadlock found when
118
+ # trying to get lock; try restarting transaction'
101
119
  sleep(2)
102
120
  else
103
121
  break
@@ -105,20 +123,9 @@ module TestRail
105
123
  retry_count += 1
106
124
  end
107
125
 
108
- result = if response.body && !response.body.empty?
109
- JSON.parse(response.body)
110
- else
111
- {}
112
- end
113
-
114
- if response.code != '200'
115
- error = if result&.key?('error')
116
- '"' + result['error'] + '"'
117
- else
118
- 'No additional error message received'
119
- end
120
- raise APIError, format('TestRail API returned HTTP %s (%s)', response.code, error)
121
- end
126
+ result = _parse_result(response)
127
+
128
+ _error_check(response, result)
122
129
 
123
130
  result
124
131
  end
@@ -4,24 +4,28 @@ require 'tzinfo'
4
4
 
5
5
  module Itriagetestrail
6
6
  module Milestones
7
+ def normalize_origin
8
+ case @testrail_config[:origin]
9
+ when 'prd', 'production', 'origin/production'
10
+ 'Production'
11
+ when 'stg', 'staging', 'origin/staging'
12
+ 'Staging'
13
+ when 'dev', 'development', 'origin/development'
14
+ 'Development'
15
+ when 'local', ''
16
+ 'Local'
17
+ when 'master', 'origin/master'
18
+ 'Master'
19
+ else
20
+ 'Dev Branch'
21
+ end
22
+ end
23
+
7
24
  # Establish the milestone name based on origin passed in,
8
25
  # usually origin represents a branch or environment
9
26
  def normalize_milestone
10
27
  if @testrail_config[:milestone].nil? || @testrail_config[:milestone].empty?
11
- case @testrail_config[:origin]
12
- when 'prd', 'production', 'origin/production'
13
- 'Production'
14
- when 'stg', 'staging', 'origin/staging'
15
- 'Staging'
16
- when 'dev', 'development', 'origin/development'
17
- 'Development'
18
- when 'local', ''
19
- 'Local'
20
- when 'master', 'origin/master'
21
- 'Master'
22
- else
23
- 'Dev Branch'
24
- end
28
+ normalize_origin
25
29
  else
26
30
  @testrail_config[:milestone]
27
31
  end
@@ -113,19 +117,19 @@ module Itriagetestrail
113
117
  def rename_milestone(id, new_name)
114
118
  # TODO: rename milestone with previous_milestone
115
119
  body = { name: new_name }
116
- res = @client.send_post("update_milestone/#{id}", body)['id']
120
+ @client.send_post("update_milestone/#{id}", body)['id']
117
121
  end
118
122
 
119
123
  # this archives a milestone at the turn of a quarter and creates a new one in its place
120
124
  def reset_milestone(milestone_name)
121
125
  runs = milestone_runs(milestone_name)
122
- unless runs.empty?
123
- last_run_time = Time.at(runs.last['completed_on'])
124
- if last_run_time < milestone_period_start
125
- rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
126
- @milestone_id = fetch_milestone(@milestone_name)
127
- end
128
- end
126
+ break if runs.empty?
127
+ last_run_time = Time.at(runs.last['completed_on'])
128
+
129
+ # if last run time is smaller than period start, do below
130
+ break unless last_run_time < milestone_period_start
131
+ rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
132
+ @milestone_id = fetch_milestone(@milestone_name)
129
133
  end
130
134
  end
131
135
  end
@@ -51,13 +51,19 @@ module Itriagetestrail
51
51
  end
52
52
 
53
53
  def app_version_label
54
- ''
55
- "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
54
+ if @app_version.nil? || @app_version == ''
55
+ ''
56
+ else
57
+ "App Version:#{@app_version}"
58
+ end
56
59
  end
57
60
 
58
61
  def jenkins_build_label
59
- ''
60
- " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
62
+ if @jenkins_build .nil? || @jenkins_build == ''
63
+ ''
64
+ else
65
+ " Jenkins Build:#{@jenkins_build}"
66
+ end
61
67
  end
62
68
 
63
69
  def time_zone_label
@@ -29,12 +29,12 @@ module Itriagetestrail
29
29
  @configuration_ids = []
30
30
 
31
31
  # evaluate @testrail_comfig
32
- @configuration_ids << config_id('Browser', @testrail_config[:config][:browser]) unless @testrail_config[:config][:browser].nil?
33
- @configuration_ids << config_id('Browser Version', @testrail_config[:config][:browserVersion]) unless @testrail_config[:config][:browserVersion].nil?
34
- @configuration_ids << config_id('Platform', @testrail_config[:config][:platform]) unless @testrail_config[:config][:platform].nil?
35
- @configuration_ids << config_id('Android Version', @testrail_config[:config][:android]) unless @testrail_config[:config][:android].nil?
36
- @configuration_ids << config_id('Android Device', @testrail_config[:config][:androidDevice]) unless @testrail_config[:config][:androidDevice].nil?
37
- @configuration_ids << config_id('IOS Version', @testrail_config[:config][:ios]) unless @testrail_config[:config][:ios].nil?
32
+ append_configuration_ids('Browser', @testrail_config[:config][:browser])
33
+ append_configuration_ids('Browser Version', @testrail_config[:config][:browserVersion])
34
+ append_configuration_ids('Platform', @testrail_config[:config][:platform])
35
+ append_configuration_ids('Android Version', @testrail_config[:config][:android])
36
+ append_configuration_ids('Android Device', @testrail_config[:config][:androidDevice])
37
+ append_configuration_ids('IOS Version', @testrail_config[:config][:ios])
38
38
 
39
39
  # remove the nils
40
40
  @configuration_ids.compact!
@@ -42,6 +42,10 @@ module Itriagetestrail
42
42
  @configuration_ids
43
43
  end
44
44
 
45
+ def append_configuration_ids(topic, configuration)
46
+ @configuration_ids << config_id(topic, configuration) unless configuration.nil?
47
+ end
48
+
45
49
  def add_testrail_plan
46
50
  body = {
47
51
  name: test_name,
@@ -9,7 +9,7 @@ module Itriagetestrail
9
9
 
10
10
  begin
11
11
  send = { results: @results[:results] }
12
- res = @client.send_post("add_results_for_cases/#{@run_id}", send)
12
+ @client.send_post("add_results_for_cases/#{@run_id}", send)
13
13
  clear_results
14
14
  rescue StandardError => e
15
15
  raise e
@@ -35,7 +35,7 @@ module Itriagetestrail
35
35
  milestone_id: @milestone_id
36
36
  }
37
37
 
38
- unless @testrail_config[:include_all] || true
38
+ unless @testrail_config[:include_all] == 'true'
39
39
  body[:include_all] = false
40
40
  body[:case_ids] = @test_case_ids
41
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Itriagetestrail
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itriagetestrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - a801069