onlyoffice_testrail_wrapper 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onlyoffice_testrail_wrapper/helpers/rspec_helper.rb +2 -0
  3. data/lib/onlyoffice_testrail_wrapper/helpers/ruby_helper.rb +2 -0
  4. data/lib/onlyoffice_testrail_wrapper/helpers/string_helper.rb +4 -0
  5. data/lib/onlyoffice_testrail_wrapper/mock/rspec_example_mock.rb +8 -3
  6. data/lib/onlyoffice_testrail_wrapper/testrail/requests_helper.rb +52 -0
  7. data/lib/onlyoffice_testrail_wrapper/testrail.rb +29 -70
  8. data/lib/onlyoffice_testrail_wrapper/testrail_api_object.rb +26 -0
  9. data/lib/onlyoffice_testrail_wrapper/testrail_case.rb +12 -6
  10. data/lib/onlyoffice_testrail_wrapper/testrail_helper/example_failed_got_expected_exception.rb +26 -0
  11. data/lib/onlyoffice_testrail_wrapper/testrail_helper/example_lpv_exception.rb +20 -0
  12. data/lib/onlyoffice_testrail_wrapper/testrail_helper/example_service_unavailable_exception.rb +20 -0
  13. data/lib/onlyoffice_testrail_wrapper/testrail_helper.rb +28 -51
  14. data/lib/onlyoffice_testrail_wrapper/testrail_milestone.rb +22 -4
  15. data/lib/onlyoffice_testrail_wrapper/testrail_plan.rb +10 -4
  16. data/lib/onlyoffice_testrail_wrapper/testrail_plan_entry.rb +3 -1
  17. data/lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb +23 -4
  18. data/lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb +14 -11
  19. data/lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_runs_methods.rb +9 -6
  20. data/lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_suite_methods.rb +9 -7
  21. data/lib/onlyoffice_testrail_wrapper/testrail_project.rb +7 -6
  22. data/lib/onlyoffice_testrail_wrapper/testrail_result.rb +2 -1
  23. data/lib/onlyoffice_testrail_wrapper/testrail_run.rb +12 -7
  24. data/lib/onlyoffice_testrail_wrapper/testrail_section.rb +14 -8
  25. data/lib/onlyoffice_testrail_wrapper/testrail_suite.rb +19 -11
  26. data/lib/onlyoffice_testrail_wrapper/testrail_test.rb +19 -7
  27. data/lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb +4 -2
  28. data/lib/onlyoffice_testrail_wrapper/version.rb +1 -1
  29. data/lib/onlyoffice_testrail_wrapper.rb +1 -1
  30. metadata +17 -131
  31. data/lib/onlyoffice_testrail_wrapper/helpers/hash_helper.rb +0 -21
  32. data/lib/onlyoffice_testrail_wrapper/testrail_helper/testrail_status_helper.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19634fbfe2b46911fd5e1f2cb47fd4d832bb0daea5ef9696ee1b8af9c3437b6e
4
- data.tar.gz: 3fb395f8bf1ae4f6358de89f79c2fa84aab9841981c7708c3e1c2238606683cc
3
+ metadata.gz: 28a07c822b81f13247f293f80bbf56d168dbac499ef4db825e15ce5d1eaea9f7
4
+ data.tar.gz: 21517abd525275abe30d8c669009e3291b88bea94925746baf4e07bdc2d24717
5
5
  SHA512:
6
- metadata.gz: a4adc0fea2c094fa440e75af45428e11d3c5e719ebe2b0bf1448fc827ae26d70dcac81ac6bbc0b70941a2bc2ac647415f711efa2b02648d294167261863d9960
7
- data.tar.gz: b84ee3c105b0266d153dd095f27303af39620d75342018c71eaab625d10d533496628e0b9801ecfb9589b5b680cdb5a82253764162cbe34390c38ec2603fc823
6
+ metadata.gz: efbd5f01fb0cd7b6e5c0b44a213798117baa87ea844bf5928eba793f0364f6b7b317f3c013b6b7ef1c687f4b9963f33214e72f60a05530ea79bffe72eb0611a6
7
+ data.tar.gz: 4e207968afb4e535077cb46f431ff12666d078aa8247b23b0ab8fc70e8b4072856c80e7e498727965d3ebff06585f43ccfd4fbc0027a55428ffa0f3dea46a1d8
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'onlyoffice_file_helper'
4
+
3
5
  module OnlyofficeTestrailWrapper
4
6
  # Methods to some rspec methods
5
7
  module RspecHelper
@@ -3,6 +3,8 @@
3
3
  module OnlyofficeTestrailWrapper
4
4
  # Methods to work with ruby
5
5
  module RubyHelper
6
+ # Check if current process run in debug mode
7
+ # @return [Boolean] true if in debug mode, false otherwise
6
8
  def debug?
7
9
  ENV['RUBYLIB'].to_s.include?('ruby-debug')
8
10
  end
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlyofficeTestrailWrapper
4
+ # Helper for working with strings
4
5
  class StringHelper
5
6
  class << self
7
+ # Check if string is have spaces in begin or end and remove them
8
+ # @param [String] string to check
9
+ # @return [String] string without spaces in begin or end
6
10
  def warnstrip!(string)
7
11
  warn "Beginning or end of string has spaces! In: #{string}" unless string == string.strip
8
12
  string.strip
@@ -5,8 +5,13 @@ module OnlyofficeTestrailWrapper
5
5
  class RspecExceptionMock
6
6
  attr_accessor :backtrace
7
7
 
8
- def initialize
9
- @backtrace = %w[TestBackTraceLine1 TestBackTraceLine2]
8
+ def initialize(backtrace = %w[TestBackTraceLine1 TestBackTraceLine2])
9
+ @backtrace = backtrace
10
+ end
11
+
12
+ # @return [String] string version of exception
13
+ def to_s
14
+ @backtrace
10
15
  end
11
16
  end
12
17
 
@@ -31,7 +36,7 @@ module OnlyofficeTestrailWrapper
31
36
  def initialize(description: 'MockDescription',
32
37
  exception: RspecExceptionMock.new)
33
38
  @exception = exception
34
- @metadata = { execution_result: RspecExceptionResultMock.new }
39
+ @metadata = { execution_result: RspecExceptionResultMock.new, absolute_file_path: __FILE__ }
35
40
  @pending = false
36
41
  @description = description
37
42
  @section = ''
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTestrailWrapper
4
+ # Module for working with requests
5
+ module RequestsHelper
6
+ # Send request to Testrail
7
+ # @param [URI] uri uri to send request
8
+ # @param [Net::HTTP::Get, Net::HTTP::Post] request request to send
9
+ # @return [Net::HTTPResponse] response from Testrail
10
+ def send_request(uri, request)
11
+ request.basic_auth admin_user, admin_pass
12
+ request.delete 'content-type'
13
+ request.add_field 'content-type', 'application/json'
14
+ is_ssl = (uri.scheme == 'https')
15
+ @connection ||= Net::HTTP.start(uri.host, uri.port, use_ssl: is_ssl)
16
+ @connection.start unless @connection.started?
17
+ attempts = 0
18
+ begin
19
+ response = @connection.request(request)
20
+ rescue Timeout::Error
21
+ attempts += 1
22
+ retry if attempts < 3
23
+ raise 'Timeout error after 3 attempts'
24
+ end
25
+ response
26
+ end
27
+
28
+ # Perform http get on address
29
+ # @param [String] request_url to perform http get
30
+ # @return [Hash] Json with result data in hash form
31
+ def http_get(request_url)
32
+ uri = URI get_testrail_address + request_url
33
+ request = Net::HTTP::Get.new uri.request_uri
34
+ response = send_request(uri, request)
35
+ JSON.parse response.body
36
+ end
37
+
38
+ # Perform http post on address
39
+ # @param [String] request_url to perform http get
40
+ # @param [Hash] data_hash headers to add to post query
41
+ # @return [Hash] Json with result data in hash form
42
+ def http_post(request_url, data_hash = {})
43
+ uri = URI get_testrail_address + request_url
44
+ request = Net::HTTP::Post.new uri.request_uri
45
+ request.body = data_hash.to_json
46
+ response = send_request(uri, request)
47
+ return if response.body == ''
48
+
49
+ JSON.parse response.body
50
+ end
51
+ end
52
+ end
@@ -7,6 +7,7 @@ require 'net/http'
7
7
  require 'json'
8
8
  require 'yaml'
9
9
  require_relative 'testrail_project'
10
+ require_relative 'testrail/requests_helper'
10
11
 
11
12
  module OnlyofficeTestrailWrapper
12
13
  # Main class for working with testrail
@@ -20,7 +21,8 @@ module OnlyofficeTestrailWrapper
20
21
  # current_test.add_result(Testrail2::TEST_RESULT_OK, 'description','version')
21
22
  # incomplete_test = test_run_from_api.get_incomplete_tests()
22
23
  # end1
23
- class Testrail2
24
+ class Testrail2 < TestrailApiObject
25
+ extend RequestsHelper
24
26
  # @return [String] address of testrail
25
27
  @testrail_url = nil
26
28
  # @return [String] login for admin user
@@ -28,13 +30,6 @@ module OnlyofficeTestrailWrapper
28
30
  # @return [String] password for admin user
29
31
  @admin_pass = nil
30
32
 
31
- # @return [Hash] project information
32
- attr_accessor :projects_names
33
-
34
- def initialize
35
- @projects_names = {}
36
- end
37
-
38
33
  class << self
39
34
  attr_accessor :testrail_url
40
35
  # Attribute to write admin_user
@@ -46,9 +41,9 @@ module OnlyofficeTestrailWrapper
46
41
  CONFIG_LOCATION = "#{Dir.home}/.gem-onlyoffice_testrail_wrapper/config.yml"
47
42
 
48
43
  def read_keys
49
- @testrail_url = ENV['TESTRAIL_URL']
50
- @admin_user = ENV['TESTRAIL_USER']
51
- @admin_pass = ENV['TESTRAIL_PASSWORD']
44
+ @testrail_url = ENV.fetch('TESTRAIL_URL', 'http://unknown.url')
45
+ @admin_user = ENV.fetch('TESTRAIL_USER', nil)
46
+ @admin_pass = ENV.fetch('TESTRAIL_PASSWORD', nil)
52
47
  return unless @admin_user.nil? && @admin_pass.nil?
53
48
 
54
49
  begin
@@ -62,12 +57,12 @@ module OnlyofficeTestrailWrapper
62
57
  end
63
58
 
64
59
  def admin_user
65
- read_keys
60
+ read_keys unless @admin_user
66
61
  @admin_user
67
62
  end
68
63
 
69
64
  def admin_pass
70
- read_keys
65
+ read_keys unless @admin_pass
71
66
  @admin_pass
72
67
  end
73
68
 
@@ -75,30 +70,6 @@ module OnlyofficeTestrailWrapper
75
70
  read_keys unless testrail_url
76
71
  testrail_url
77
72
  end
78
-
79
- # Perform http get on address
80
- # @param [String] request_url to perform http get
81
- # @return [Hash] Json with result data in hash form
82
- def http_get(request_url)
83
- uri = URI get_testrail_address + request_url
84
- request = Net::HTTP::Get.new uri.request_uri
85
- response = send_request(uri, request)
86
- JSON.parse response.body
87
- end
88
-
89
- # Perform http post on address
90
- # @param [String] request_url to perform http get
91
- # @param [Hash] data_hash headers to add to post query
92
- # @return [Hash] Json with result data in hash form
93
- def http_post(request_url, data_hash = {})
94
- uri = URI get_testrail_address + request_url
95
- request = Net::HTTP::Post.new uri.request_uri
96
- request.body = data_hash.to_json
97
- response = send_request(uri, request)
98
- return if response.body == ''
99
-
100
- JSON.parse response.body
101
- end
102
73
  end
103
74
 
104
75
  # region PROJECT
@@ -115,19 +86,22 @@ module OnlyofficeTestrailWrapper
115
86
  end
116
87
 
117
88
  # Get all projects on testrail
118
- # @return [Array, ProjectTestrail] array of projects
89
+ # @return [Array<TestrailProject>] array of projects data
119
90
  def get_projects
120
- projects = Testrail2.http_get 'index.php?/api/v2/get_projects'
121
- @projects_names = HashHelper.get_hash_from_array_with_two_parameters(projects, 'name', 'id') if @projects_names.empty?
91
+ projects = []
92
+ Testrail2.http_get('index.php?/api/v2/get_projects').each do |project|
93
+ projects << TestrailProject.new.init_from_hash(project)
94
+ end
122
95
  projects
123
96
  end
124
97
 
125
98
  def create_new_project(name, announcement = '', show_announcement = true)
126
- new_project = HashHelper.parse_to_class_variable(Testrail2.http_post('index.php?/api/v2/add_project', name: StringHelper.warnstrip!(name.to_s), announcement: announcement,
127
- show_announcement: show_announcement), TestrailProject)
99
+ new_project = TestrailProject.new.init_from_hash(Testrail2.http_post('index.php?/api/v2/add_project',
100
+ name: StringHelper.warnstrip!(name.to_s),
101
+ announcement: announcement,
102
+ show_announcement: show_announcement))
128
103
  OnlyofficeLoggerHelper.log "Created new project: #{new_project.name}"
129
- new_project.instance_variable_set('@testrail', self)
130
- @projects_names[new_project.name] = new_project.id
104
+ new_project.instance_variable_set(:@testrail, self)
131
105
  new_project
132
106
  end
133
107
 
@@ -142,15 +116,22 @@ module OnlyofficeTestrailWrapper
142
116
  # Get all projects on testrail
143
117
  # @return [Array, ProjectTestrail] array of projects
144
118
  def get_project_by_id(id)
145
- project = HashHelper.parse_to_class_variable(Testrail2.http_get("index.php?/api/v2/get_project/#{id}"), TestrailProject)
119
+ project = TestrailProject.new.init_from_hash(Testrail2.http_get("index.php?/api/v2/get_project/#{id}"))
146
120
  OnlyofficeLoggerHelper.log("Initialized project: #{project.name}")
147
- project.instance_variable_set('@testrail', self)
121
+ project.instance_variable_set(:@testrail, self)
148
122
  project
149
123
  end
150
124
 
125
+ # Get Testrail project by it's name
126
+ # @param [String] name name of project
127
+ # @return [TestrailProject, nil] project with this name or nil if not found
151
128
  def get_project_by_name(name)
152
- get_projects if @projects_names.empty?
153
- @projects_names[StringHelper.warnstrip!(name.to_s)].nil? ? nil : get_project_by_id(@projects_names[StringHelper.warnstrip!(name.to_s)])
129
+ projects = get_projects
130
+ project_name = StringHelper.warnstrip!(name.to_s)
131
+ project = projects.find { |current_project| current_project.name == project_name }
132
+ return nil unless project
133
+
134
+ project
154
135
  end
155
136
 
156
137
  # Check if Testrail connection is available
@@ -161,27 +142,5 @@ module OnlyofficeTestrailWrapper
161
142
  rescue StandardError
162
143
  false
163
144
  end
164
-
165
- # endregion
166
-
167
- def self.send_request(uri, request)
168
- request.basic_auth admin_user, admin_pass
169
- request.delete 'content-type'
170
- request.add_field 'content-type', 'application/json'
171
- is_ssl = (uri.scheme == 'https')
172
- Net::HTTP.start(uri.host, uri.port, use_ssl: is_ssl) do |http|
173
- attempts = 0
174
- begin
175
- response = http.request(request)
176
- rescue Timeout::Error
177
- attempts += 1
178
- retry if attempts < 3
179
- raise 'Timeout error after 3 attempts'
180
- rescue StandardError => e
181
- raise e
182
- end
183
- return response
184
- end
185
- end
186
145
  end
187
146
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTestrailWrapper
4
+ # Base class for all Testrail API objects
5
+ class TestrailApiObject
6
+ # Fill object data from hash with data
7
+ # @param [Hash] hash with data
8
+ # @return
9
+ def init_from_hash(hash)
10
+ hash.each { |key, value| instance_variable_set("@#{key}", value) }
11
+ self
12
+ end
13
+
14
+ # Generate hash wih pars of name:id
15
+ # @param [Array<Hash>] array of raw data
16
+ # @param [String, Symbol] name_key how name key is called in hash
17
+ # @return [Hash] result hash data
18
+ def name_id_pairs(array, name_key = 'name')
19
+ raise 'First argument must be Array!' unless array.is_a?(Array)
20
+
21
+ result_hash = {}
22
+ array.reverse_each { |element| result_hash[element[name_key]] = element['id'] }
23
+ result_hash
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,7 @@
3
3
  module OnlyofficeTestrailWrapper
4
4
  # @author Roman.Zagudaev
5
5
  # Class for description of test case
6
- class TestrailCase
6
+ class TestrailCase < TestrailApiObject
7
7
  # @return [Integer] Id of test case
8
8
  attr_accessor :id
9
9
  # @return [String] title of test case
@@ -25,6 +25,7 @@ module OnlyofficeTestrailWrapper
25
25
  # @param [Integer] id Id of test case
26
26
  # @return [TestCaseTestrail] new test case
27
27
  def initialize(title = nil, type_id = 3, priority_id = 4, custom_steps = nil, id = nil)
28
+ super()
28
29
  @id = id
29
30
  @title = title
30
31
  @type_id = type_id
@@ -35,8 +36,11 @@ module OnlyofficeTestrailWrapper
35
36
  def update(title = @title, type_id = @type_id, priority_id = @priority_id, custom_steps = @custom_steps)
36
37
  @section.cases_names.delete @title
37
38
  @section.cases_names[StringHelper.warnstrip!(title.to_s)] = @id
38
- HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/update_case/#{@id}", title: title, type_id: type_id,
39
- priority_id: priority_id, custom_steps: custom_steps), TestrailCase)
39
+ TestrailCase.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/update_case/#{@id}",
40
+ title: title,
41
+ type_id: type_id,
42
+ priority_id: priority_id,
43
+ custom_steps: custom_steps))
40
44
  end
41
45
 
42
46
  def delete
@@ -47,13 +51,15 @@ module OnlyofficeTestrailWrapper
47
51
 
48
52
  def get_results(run_id)
49
53
  case_results = Testrail2.http_get "index.php?/api/v2/get_results_for_case/#{run_id}/#{@id}"
50
- case_results.each_with_index { |test_case, index| case_results[index] = HashHelper.parse_to_class_variable(test_case, TestrailResult) }
54
+ case_results.each_with_index { |test_case, index| case_results[index] = TestrailResult.new.init_from_hash(test_case) }
51
55
  case_results
52
56
  end
53
57
 
54
58
  def add_result(run_id, result, comment = '', custom_fields = {}, version = '')
55
- response = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/add_result_for_case/#{run_id}/#{@id}", { status_id: TestrailResult::RESULT_STATUSES[result],
56
- comment: comment, version: version }.merge(custom_fields)), TestrailResult)
59
+ response = TestrailResult.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_result_for_case/#{run_id}/#{@id}",
60
+ { status_id: TestrailResult::RESULT_STATUSES[result],
61
+ comment: comment,
62
+ version: version }.merge(custom_fields)))
57
63
  OnlyofficeLoggerHelper.log "Set test case result: #{result}. URL: #{Testrail2.get_testrail_address}index.php?/tests/view/#{response.test_id}", output_colors[result]
58
64
  response
59
65
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTestrailWrapper
4
+ # Class for exception then result contains `got` and `expected`
5
+ class ExampleFailedGotExpectedException
6
+ def initialize(example)
7
+ @example = example
8
+ end
9
+
10
+ # @return [Symbol] result of this exception
11
+ def result
12
+ :failed
13
+ end
14
+
15
+ # @return [String] comment for this exception
16
+ def comment
17
+ return @comment if @comment
18
+
19
+ failed_line = RspecHelper.find_failed_line(@example)
20
+ @comment = "\n#{@example.exception
21
+ .to_s
22
+ .gsub('got:', "got:\n")
23
+ .gsub('expected:', "expected:\n")}\nIn line:\n#{failed_line}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTestrailWrapper
4
+ # Class for example with LPV exception
5
+ class ExampleLPVException
6
+ def initialize(example)
7
+ @example = example
8
+ end
9
+
10
+ # @return [Symbol] result of this exception
11
+ def result
12
+ :lpv
13
+ end
14
+
15
+ # @return [String] comment for this exception
16
+ def comment
17
+ "\n#{@example.exception}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTestrailWrapper
4
+ # Class for example with exception `Service Unavailable`
5
+ class ExampleServiceUnavailableException
6
+ def initialize(example)
7
+ @example = example
8
+ end
9
+
10
+ # @return [Symbol] result of this exception
11
+ def result
12
+ :service_unavailable
13
+ end
14
+
15
+ # @return [String] comment for this exception
16
+ def comment
17
+ "\n#{@example.exception}"
18
+ end
19
+ end
20
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'onlyoffice_bugzilla_helper'
4
4
  require_relative 'testrail_helper/testrail_helper_rspec_metadata'
5
- require_relative 'testrail_helper/testrail_status_helper'
5
+ require_relative 'testrail_helper/example_failed_got_expected_exception'
6
+ require_relative 'testrail_helper/example_lpv_exception'
7
+ require_relative 'testrail_helper/example_service_unavailable_exception'
6
8
  require_relative 'testrail'
7
9
  require_relative 'helpers/ruby_helper'
8
10
  require_relative 'helpers/system_helper'
@@ -12,9 +14,8 @@ module OnlyofficeTestrailWrapper
12
14
  class TestrailHelper
13
15
  include RubyHelper
14
16
  include TestrailHelperRspecMetadata
15
- include TestrailStatusHelper
16
17
  attr_reader :project, :plan, :suite, :run
17
- attr_accessor :add_all_suites, :ignore_parameters, :suites_to_add, :search_plan_by_substring, :in_debug, :version
18
+ attr_accessor :add_all_suites, :suites_to_add, :in_debug, :version
18
19
 
19
20
  def initialize(project_name, suite_name = nil, plan_name = nil, run_name = nil)
20
21
  @in_debug = debug?
@@ -23,7 +24,7 @@ module OnlyofficeTestrailWrapper
23
24
  rescue Errno::ENOENT
24
25
  @bugzilla_helper = nil
25
26
  end
26
- if @in_debug
27
+ if skip_testrail_connection?
27
28
  OnlyofficeLoggerHelper.log 'Do not initialize Testrail, because spec run in debug'
28
29
  @run = TestrailRun.new
29
30
  return
@@ -31,11 +32,10 @@ module OnlyofficeTestrailWrapper
31
32
  OnlyofficeLoggerHelper.log 'Begin initializing Testrail...'
32
33
  @suites_to_add = []
33
34
  @add_all_suites = true
34
- @search_plan_by_substring = false
35
35
  yield(self) if block_given?
36
36
  @project = Testrail2.new.project project_name.to_s.dup
37
37
  if plan_name
38
- @plan = @project.get_plan_by_name(search_plan_by_substring ? get_plan_name_by_substring(plan_name.to_s) : plan_name.to_s)
38
+ @plan = @project.get_plan_by_name(plan_name.to_s)
39
39
  @plan ||= @project.create_new_plan(plan_name, suites_to_add_hash(@add_all_suites ? all_suites_names : @suites_to_add))
40
40
  end
41
41
  return if suite_name.nil?
@@ -71,10 +71,7 @@ module OnlyofficeTestrailWrapper
71
71
  end
72
72
  exception = example.exception
73
73
  custom_fields = init_custom_fields(example)
74
- if @ignore_parameters && (ignored_hash = ignore_case?(example.metadata))
75
- comment += "\nTest ignored by #{ignored_hash}"
76
- result = :blocked
77
- elsif example.pending
74
+ if example.pending
78
75
  result, comment, bug_id = parse_pending_comment(example.execution_result.pending_message)
79
76
  if example.exception.to_s == 'Expected example to fail since it is pending, but it passed.'
80
77
  result = :failed
@@ -84,18 +81,20 @@ module OnlyofficeTestrailWrapper
84
81
  example.add_custom_exception(comment) if result == :failed
85
82
  result = :lpv if comment.downcase.include?('limited program version')
86
83
  elsif exception.to_s.include?('got:') || exception.to_s.include?('expected:')
87
- result = :failed
88
- failed_line = RspecHelper.find_failed_line(example)
89
- comment += "\n#{exception.to_s.gsub('got:', "got:\n").gsub('expected:', "expected:\n")}\nIn line:\n#{failed_line}"
84
+ testrail_exception = ExampleFailedGotExpectedException.new(example)
85
+ result = testrail_exception.result
86
+ comment += testrail_exception.comment
90
87
  elsif exception.to_s.include?('to return') || exception.to_s.include?('expected')
91
88
  result = :failed
92
89
  comment += "\n#{exception.to_s.gsub('to return ', "to return:\n").gsub(', got ', "\ngot:\n")}"
93
90
  elsif exception.to_s.include?('Service Unavailable')
94
- result = :service_unavailable
95
- comment += "\n#{exception}"
91
+ testrail_exception = ExampleServiceUnavailableException.new(example)
92
+ result = testrail_exception.result
93
+ comment += testrail_exception.comment
96
94
  elsif exception.to_s.include?('Limited program version')
97
- result = :lpv
98
- comment += "\n#{exception}"
95
+ testrail_exception = ExampleLPVException.new(exception)
96
+ result = testrail_exception.result
97
+ comment += testrail_exception.comment
99
98
  elsif exception.nil?
100
99
  result = if @last_case == example.description
101
100
  :passed_2
@@ -114,29 +113,8 @@ module OnlyofficeTestrailWrapper
114
113
  @suite.section(section_name).case(example.description).add_result @run.id, result, comment, custom_fields
115
114
  end
116
115
 
117
- def add_result_by_case_name(name, result, comment = 'ok', section_name = 'All Test Cases')
118
- @suite.section(section_name).case(name.to_s).add_result(@run.id, result, comment)
119
- end
120
-
121
116
  def get_incomplete_tests
122
- @run.get_tests.map { |test| test['title'] if test['status_id'] == 3 || test['status_id'] == 4 }.compact
123
- end
124
-
125
- # @param [Array] result. Example: [:retest, :passed]
126
- def get_tests_by_result(result)
127
- check_status_exist(result)
128
- result = [result] unless result.is_a?(Array)
129
- @run.get_tests.map { |test| test['title'] if result.include?(TestrailResult::RESULT_STATUSES.key(test['status_id'])) }.compact
130
- end
131
-
132
- def delete_plan(plan_name)
133
- @project.plan(get_plan_name_by_substring(plan_name.to_s)).delete
134
- end
135
-
136
- def mark_rest_environment_dependencies(supported_test_list, status_to_mark = :lpv)
137
- get_incomplete_tests.each do |current_test|
138
- add_result_by_case_name(current_test, status_to_mark, 'Not supported on this test environment') unless supported_test_list.include?(current_test)
139
- end
117
+ @run.get_tests.filter_map { |test| test['title'] if test['status_id'] == 3 || test['status_id'] == 4 }
140
118
  end
141
119
 
142
120
  private
@@ -147,11 +125,6 @@ module OnlyofficeTestrailWrapper
147
125
  OnlyofficeLoggerHelper.log("Initialized run: #{@run.name}")
148
126
  end
149
127
 
150
- def get_plan_name_by_substring(string)
151
- @project.get_plans.each { |plan| return plan['name'] if plan['name'].include?(string) }
152
- string
153
- end
154
-
155
128
  def all_suites_names
156
129
  @suites ? (return @suites) : @suites = []
157
130
  @project.get_suites
@@ -159,15 +132,19 @@ module OnlyofficeTestrailWrapper
159
132
  @suites.sort!
160
133
  end
161
134
 
162
- def ignore_case?(example_metadata)
163
- raise 'Ignore parameters must be Hash!!' unless @ignore_parameters.instance_of?(Hash)
164
-
165
- @ignore_parameters.each { |key, value| return { key => value } if example_metadata[key] == value }
166
- false
167
- end
168
-
169
135
  def suites_to_add_hash(suites_names)
170
136
  suites_names.map { |suite| all_suites_names.include?(suite) ? { 'suite_id' => @project.suites_names[suite] } : { 'suite_id' => @project.create_new_suite(suite).id } }
171
137
  end
138
+
139
+ # Check if we should skip connecting to testrail
140
+ # In debug mode (except when `TESTRAIL_IN_DEBUG` env is set)
141
+ # we do not do that for easy debugging E2E tests
142
+ # @return [Boolean]
143
+ def skip_testrail_connection?
144
+ return false unless @in_debug
145
+ return false if ENV['TESTRAIL_IN_DEBUG']
146
+
147
+ true
148
+ end
172
149
  end
173
150
  end
@@ -1,21 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlyofficeTestrailWrapper
4
- class TestrailMilestone
5
- attr_accessor :id, :name, :description, :is_completed
4
+ # Class for describing milestone data
5
+ class TestrailMilestone < TestrailApiObject
6
+ # @return [Integer] id of milestone
7
+ attr_accessor :id
8
+ # @return [String] name of milestone
9
+ attr_accessor :name
10
+ # @return [String] description of milestone
11
+ attr_accessor :description
12
+ # @return [Boolean] is this milestone completed
13
+ attr_accessor :is_completed
6
14
 
7
15
  def initialize(name = '', description = '', is_completed = false, id = nil)
16
+ super()
8
17
  @id = id.to_i
9
18
  @name = name
10
19
  @description = description
11
20
  @is_completed = is_completed
12
21
  end
13
22
 
23
+ # Update current milestone
24
+ # @param [Boolean] is_completed is milestone should be completed
25
+ # @param [String] name new name of milestone
26
+ # @param [String] description new description of milestone
27
+ # @return [TestrailMilestone] updated milestone data
14
28
  def update(is_completed = false, name = @name, description = @description)
15
- HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/update_milestone/#{@id}", name: name, description: description,
16
- is_completed: is_completed), TestrailMilestone)
29
+ TestrailMilestone.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/update_milestone/#{@id}",
30
+ name: name,
31
+ description: description,
32
+ is_completed: is_completed))
17
33
  end
18
34
 
35
+ # Delete current milestone
36
+ # @return [Hash] result of http request
19
37
  def delete
20
38
  Testrail2.http_post "index.php?/api/v2/delete_milestone/#{@id}", {}
21
39
  end