onlyoffice_tcm_helper 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5314bcff82aacd110912a3f45496c8e0a5f0933e01f2b7355e3ba19cceecf5f9
4
+ data.tar.gz: af52601a9fb478d7c666b77dbf7b09dfcdb3ccbf56ea4f4bd8dfd5c83c053372
5
+ SHA512:
6
+ metadata.gz: eb18c3a30ad1f24711c834a8cd8134db353f1aa7e8635323ca3c476500559b27a9e2e26d5165c20bbed8113a2b9ec92f777f04cb29e42f82fc3b41dda81fdb5d
7
+ data.tar.gz: 75ec1b4918b802443c454f1802593ef86c21fe66d076b03b1e731598c8b11727ad42aeb9c67fdc9560d34059bb79e4d23b382e72be9c016d798ee86ba11191b8
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onlyoffice_tcm_helper/helpers/rspec_helper'
4
+ require 'onlyoffice_tcm_helper/helpers/time_helper'
5
+ require 'onlyoffice_tcm_helper/version'
6
+ require 'rspec'
7
+ require 'socket'
8
+ require 'json'
9
+
10
+ # namespace for gem
11
+ module OnlyofficeTcmHelper
12
+ # Class for generate data for result by RSpec::Core::Example
13
+ class TcmHelper
14
+ include TimeHelper
15
+ include RspecHelper
16
+ # @return [Symbol] one of status: passed, passed_2, failed, aborted, pending, service_unavailable, lpv
17
+ attr_accessor :status
18
+ # @return [String] name of case(or name of result_set)
19
+ attr_reader :case_name
20
+ # @return [RSpec::Core::Example] example - is a returned object in "after" block
21
+ attr_reader :example
22
+ # @return [String] is a comment for result, like a error, link to bug, etc
23
+ attr_reader :comment
24
+ # @return [String] is a name of product
25
+ attr_reader :product_name
26
+ # @return [String] is a name of plan
27
+ attr_reader :plan_name
28
+ # @return [String] is a name of suite(ore run)
29
+ attr_reader :suite_name
30
+ # @return [String] is a name last case, who result has generated
31
+ attr_reader :last_case
32
+ # @return [Hash] is a result message.
33
+ attr_accessor :result_message
34
+
35
+ def initialize(params = {})
36
+ @product_name = params[:product_name]
37
+ @plan_name = params[:plan_name]
38
+ @suite_name = params[:suite_name]
39
+ end
40
+
41
+ # @param [RSpec::Core::Example] example - is a returned object in "after" block
42
+ # @return [TcmHelper] is object
43
+ def parse(example)
44
+ @case_name = example.metadata[:description]
45
+ get_status_and_comment(example)
46
+ @result_message = get_message_and_custom_fields(example)
47
+ self
48
+ end
49
+
50
+ # Get message and custom fields from example
51
+ # @param [Object] example to get
52
+ # @return [String] json data
53
+ def get_message_and_custom_fields(example)
54
+ custom_fields = {}
55
+ custom_fields[:subdescriber] = [
56
+ { title: 'elapsed', value: example_time_in_seconds(example) },
57
+ { title: 'custom_host', value: Socket.gethostname }
58
+ ]
59
+ custom_fields[:describer] = [{ title: 'comment', value: @comment }]
60
+ custom_fields.to_json
61
+ end
62
+
63
+ # @param [RSpec::Core::Example] example - is a returned object in "after" block
64
+ # @return [Symbol] is a symbolic name of test status
65
+ def get_status_and_comment(example)
66
+ @status = if result_is_failed?(example)
67
+ comment = "\n#{example.exception.to_s
68
+ .gsub('got:', "got:\n")
69
+ .gsub('expected:', "expected:\n")
70
+ .gsub('to return ', "to return:\n")}\n"\
71
+ "In line:\n#{RspecHelper.find_failed_line(example)}"
72
+ @comment = comment
73
+ :failed
74
+ elsif example.pending?
75
+ @comment = example.execution_result.pending_message
76
+ :pending
77
+ elsif result_is_passed?(example)
78
+ @comment = "\nOk"
79
+ :passed
80
+ elsif result_is_passed2?(example)
81
+ @comment = "\nPassed 2"
82
+ :passed_2
83
+ elsif result_is_service_unavailable?(example)
84
+ @comment = "\n#{example.exception}"
85
+ :service_unavailable
86
+ elsif result_is_lpv?(example)
87
+ @comment = "\n#{example.exception}"
88
+ :lpv
89
+ else
90
+ @comment = "\n#{example.exception}"
91
+ :aborted
92
+ end
93
+ @last_case = @case_name
94
+ end
95
+
96
+ def result_is_passed?(example)
97
+ example.exception.nil? && @last_case != example.description
98
+ end
99
+
100
+ def result_is_passed2?(example)
101
+ example.exception.nil? && @last_case == example.description
102
+ end
103
+
104
+ def result_is_failed?(example)
105
+ # return true if example.metadata[:execution_result].pending_fixed
106
+ ['got:', 'expected:', 'to return'].map do |current_error|
107
+ return true if example.exception.to_s.include?(current_error)
108
+ end
109
+ false
110
+ end
111
+
112
+ def result_is_service_unavailable?(example)
113
+ example.exception.to_s.include?('Service Unavailable')
114
+ end
115
+
116
+ def result_is_lpv?(example)
117
+ example.exception.to_s.include?('Limited program version')
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onlyoffice_file_helper'
4
+ # namespace
5
+ module OnlyofficeTcmHelper
6
+ # module with methods for parsing test results
7
+ module RspecHelper
8
+ # This method is based on
9
+ # https://github.com/rspec/rspec-core/blob/v3.3.0/lib/rspec/core/formatters/exception_presenter.rb#L130
10
+ # It extracted exact line of code from failed exception
11
+ # @param [RSpec::Core::Example] example
12
+ # @return [String] line value
13
+ def self.find_failed_line(example)
14
+ example_path = example.metadata[:absolute_file_path].downcase
15
+ dirty_line = example.exception.backtrace.find do |line|
16
+ next unless (line_path = line[/(.+?):(\d+)(|:\d+)/, 1])
17
+
18
+ File.expand_path(line_path).casecmp(example_path).zero?
19
+ end
20
+ line_number = dirty_line[/:\d*:/].delete(':').to_i
21
+ OnlyofficeFileHelper::FileHelper.read_array_from_file(example.metadata[:absolute_file_path])[line_number - 1]
22
+ rescue StandardError => e
23
+ "Cannot find failed line because of exception: #{e}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # namespace
4
+ module OnlyofficeTcmHelper
5
+ # it is helper for work with time class
6
+ module TimeHelper
7
+ # Example time in seconds
8
+ # @param [Object] example with data
9
+ # @return [String] time in seconds
10
+ def example_time_in_seconds(example)
11
+ execution_time = (Time.now - example.metadata[:execution_result].started_at).to_i
12
+ execution_time = 1 if execution_time.zero? # Testrail cannot receive 0 as elapsed time
13
+ "#{execution_time}s"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sub_elements/executing_result'
4
+ # class is describe object like RSpec::Core::Example
5
+ class PseudoExample
6
+ attr_reader :description, :execution_result
7
+
8
+ def initialize(description = 'Check something', started_at = Time.now)
9
+ @description = description
10
+ @execution_result = ExecutingResult.new(started_at)
11
+ end
12
+
13
+ # @return [Hash] metadata of class
14
+ def metadata
15
+ {
16
+ description: @description,
17
+ execution_result: @execution_result,
18
+ absolute_file_path: __FILE__
19
+ }
20
+ end
21
+
22
+ # @return [nil] non-existing exception
23
+ def exception; end
24
+
25
+ # @return [false] is example pending
26
+ def pending?
27
+ false
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class is describe object like RSpec::Core::Example with error in no expected code
4
+ class PseudoExampleAborted < PseudoExample
5
+ # @return [String] exception string
6
+ def exception
7
+ "undefined local variable or method `tasdasdrue' "\
8
+ 'for #<RSpec::ExampleGroups::OnlyofficeTcmHelper::'\
9
+ 'StatusChecks:0x000000020b8400>'
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'pseudo_example_failed/mock_failed_exception'
4
+
5
+ # class is describe object like RSpec::Core::Example with error in expected code
6
+ class PseudoExampleFailed < PseudoExample
7
+ def initialize(description = 'Check something',
8
+ exception_with_failed_lines: false)
9
+ @exception_with_failed_lines = exception_with_failed_lines
10
+ super(description)
11
+ end
12
+
13
+ # @return [Hash] metadata of class
14
+ def metadata
15
+ {
16
+ description: 'Test for create failed status result',
17
+ execution_result: ExecutingResult.new,
18
+ absolute_file_path: "#{Dir.pwd}/spec/onlyoffice_tcm_helper_spec.rb"
19
+ }
20
+ end
21
+
22
+ # @return [Object] exception data
23
+ def exception
24
+ return MockFailedException.new if @exception_with_failed_lines
25
+
26
+ 'expected: falsey value
27
+ got: true'
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Mock class to check exception
4
+ class MockFailedException
5
+ # @return [String] string representation
6
+ def to_s
7
+ 'expected: falsey value
8
+ got: true'
9
+ end
10
+
11
+ # @return [Array<String>] list of backtrace
12
+ def backtrace
13
+ ['trace_without_line',
14
+ "#{Dir.pwd}/spec/onlyoffice_tcm_helper_spec.rb:3:in `get_status_and_comment",
15
+ "#{Dir.pwd}/spec/onlyoffice_tcm_helper_spec.rb:4:in `parse"]
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class is describe object like RSpec::Core::Example with special tag
4
+ class PseudoExampleLPV < PseudoExample
5
+ # @return [String] exception string
6
+ def exception
7
+ 'Limited program version'
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class is describe object like RSpec::Core::Example with no error
4
+ class PseudoExamplePassed < PseudoExample; end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sub_elements/executing_result_pending'
4
+
5
+ # class is describe object like RSpec::Core::Example with pending result
6
+ class PseudoExamplePending < PseudoExample
7
+ def initialize(description)
8
+ super(description)
9
+ @execution_result = ExecutingResultPending.new
10
+ end
11
+
12
+ def pending?
13
+ true
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class is describe object like RSpec::Core::Example with special tag
4
+ class PseudoExampleServiceUnavailable < PseudoExample
5
+ # @return [String] exception string
6
+ def exception
7
+ 'Service Unavailable: 503'
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class is describe same RSpec::Core::Example::ExecutingResult with no errors
4
+ class ExecutingResult
5
+ attr_reader :started_at
6
+
7
+ def initialize(started_at = Time.now)
8
+ @started_at = started_at
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # class is describe same RSpec::Core::Example::ExecutingResult with pending status
4
+ class ExecutingResultPending
5
+ attr_reader :started_at, :pending_message
6
+
7
+ def initialize
8
+ @started_at = Time.now
9
+ @pending_message = 'Pending exception'
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTcmHelper
4
+ # @return [String] gem name
5
+ NAME = 'onlyoffice_tcm_helper'
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeTcmHelper
4
+ # @return [String] version of gem
5
+ VERSION = '0.2.0'
6
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onlyoffice_tcm_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - ONLYOFFICE
8
+ - Dmitry Rotaty
9
+ - Pavel Lobashov
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2021-01-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: onlyoffice_file_helper
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: overcommit
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '13'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '13'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop-performance
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop-rake
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rubocop-rspec
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '2'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '2'
127
+ - !ruby/object:Gem::Dependency
128
+ name: simplecov
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: yard
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 0.9.20
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 0.9.20
161
+ description: It is helper for work with tcm systems, used in QA
162
+ email:
163
+ - shockwavenn@gmail.com
164
+ executables: []
165
+ extensions: []
166
+ extra_rdoc_files: []
167
+ files:
168
+ - lib/onlyoffice_tcm_helper.rb
169
+ - lib/onlyoffice_tcm_helper/helpers/rspec_helper.rb
170
+ - lib/onlyoffice_tcm_helper/helpers/time_helper.rb
171
+ - lib/onlyoffice_tcm_helper/models/pseudo_example.rb
172
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_aborted.rb
173
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_failed.rb
174
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_failed/mock_failed_exception.rb
175
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_lpv.rb
176
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_passed.rb
177
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_pending.rb
178
+ - lib/onlyoffice_tcm_helper/models/pseudo_example_service_unavailable.rb
179
+ - lib/onlyoffice_tcm_helper/models/sub_elements/executing_result.rb
180
+ - lib/onlyoffice_tcm_helper/models/sub_elements/executing_result_pending.rb
181
+ - lib/onlyoffice_tcm_helper/name.rb
182
+ - lib/onlyoffice_tcm_helper/version.rb
183
+ homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_tcm_helper
184
+ licenses:
185
+ - AGPL-3.0
186
+ metadata:
187
+ bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_tcm_helper/issues
188
+ changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_tcm_helper/blob/master/CHANGELOG.md
189
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_tcm_helper
190
+ homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_tcm_helper
191
+ source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_tcm_helper
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '2.5'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubygems_version: 3.1.4
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: It is helper for work with tcm systems
211
+ test_files: []