testrail-rspec 0.1.0
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 +7 -0
- data/lib/testrail-rspec/api-client.rb +106 -0
- data/lib/testrail-rspec/update-testrails.rb +72 -0
- data/lib/testrail-rspec/version.rb +3 -0
- data/lib/testrail-rspec.rb +3 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9e16041a770eed00286369886e6109acccab1ead3a44cfdb1078cd1605920368
|
4
|
+
data.tar.gz: 1f0d38bcce60ef9c7e092db496cd37873824073465baeba07759df968f01904a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7deaa1684832970b626fc5622dcb69950ae6d219cf169897ccba4e2486edf3d6eb5761507e0eec54d3d227158cf7110b207a26bab1e60466688eeaf56995cd67
|
7
|
+
data.tar.gz: df634941c512d418c3c07a8fa20b38386a3fe048c0645552a2a3aa476435cfad93221b30cd33f67c6615e8baf6b9dfb6500be0f28b95a5ce057ec13f9166d07c
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# TestRail API binding for Ruby (API v2, available since TestRail 3.0)
|
3
|
+
#
|
4
|
+
# Learn more:
|
5
|
+
#
|
6
|
+
# http://docs.gurock.com/testrail-api2/start
|
7
|
+
# http://docs.gurock.com/testrail-api2/accessing
|
8
|
+
#
|
9
|
+
# Copyright Gurock Software GmbH. See license.md for details.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'net/http'
|
13
|
+
require 'net/https'
|
14
|
+
require 'uri'
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
module TestRail
|
18
|
+
class APIClient
|
19
|
+
@url = ''
|
20
|
+
@user = ''
|
21
|
+
@password = ''
|
22
|
+
|
23
|
+
attr_accessor :user
|
24
|
+
attr_accessor :password
|
25
|
+
|
26
|
+
def initialize(base_url)
|
27
|
+
if !base_url.match(/\/$/)
|
28
|
+
base_url += '/'
|
29
|
+
end
|
30
|
+
@url = base_url + 'index.php?/api/v2/'
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Send Get
|
35
|
+
#
|
36
|
+
# Issues a GET request (read) against the API and returns the result
|
37
|
+
# (as Ruby hash).
|
38
|
+
#
|
39
|
+
# Arguments:
|
40
|
+
#
|
41
|
+
# uri The API method to call including parameters
|
42
|
+
# (e.g. get_case/1)
|
43
|
+
#
|
44
|
+
def send_get(uri)
|
45
|
+
_send_request('GET', uri, nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Send POST
|
50
|
+
#
|
51
|
+
# Issues a POST request (write) against the API and returns the result
|
52
|
+
# (as Ruby hash).
|
53
|
+
#
|
54
|
+
# Arguments:
|
55
|
+
#
|
56
|
+
# uri The API method to call including parameters
|
57
|
+
# (e.g. add_case/1)
|
58
|
+
# data The data to submit as part of the request (as
|
59
|
+
# Ruby hash, strings must be UTF-8 encoded)
|
60
|
+
#
|
61
|
+
def send_post(uri, data)
|
62
|
+
_send_request('POST', uri, data)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def _send_request(method, uri, data)
|
67
|
+
url = URI.parse(@url + uri)
|
68
|
+
if method == 'POST'
|
69
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
70
|
+
request.body = JSON.dump(data)
|
71
|
+
else
|
72
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
73
|
+
end
|
74
|
+
request.basic_auth(@user, @password)
|
75
|
+
request.add_field('Content-Type', 'application/json')
|
76
|
+
|
77
|
+
conn = Net::HTTP.new(url.host, url.port)
|
78
|
+
if url.scheme == 'https'
|
79
|
+
conn.use_ssl = true
|
80
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
81
|
+
end
|
82
|
+
response = conn.request(request)
|
83
|
+
|
84
|
+
if response.body && !response.body.empty?
|
85
|
+
result = JSON.parse(response.body)
|
86
|
+
else
|
87
|
+
result = {}
|
88
|
+
end
|
89
|
+
|
90
|
+
if response.code != '200'
|
91
|
+
if result && result.key?('error')
|
92
|
+
error = '"' + result['error'] + '"'
|
93
|
+
else
|
94
|
+
error = 'No additional error message received'
|
95
|
+
end
|
96
|
+
raise APIError.new('TestRail API returned HTTP %s (%s)' %
|
97
|
+
[response.code, error])
|
98
|
+
end
|
99
|
+
|
100
|
+
result
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class APIError < StandardError
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative 'api-client'
|
2
|
+
|
3
|
+
module TestrailRSpec
|
4
|
+
class UpdateTestRails
|
5
|
+
attr_accessor :client
|
6
|
+
|
7
|
+
def initialize(scenario)
|
8
|
+
@scenario = scenario
|
9
|
+
|
10
|
+
if File.exist? './testrail_config.yml'
|
11
|
+
@config = YAML.load_file("./testrail_config.yml")['testrail']
|
12
|
+
raise 'TestRail configuration file not loaded successfully' if @config.nil?
|
13
|
+
else
|
14
|
+
raise 'TestRail configuration file is required'
|
15
|
+
end
|
16
|
+
|
17
|
+
setup_testrail_client
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload_result
|
21
|
+
|
22
|
+
response = {}
|
23
|
+
case_id = @scenario.metadata[:description].split(' ').first.scan(/\d+/).first rescue nil
|
24
|
+
|
25
|
+
status_id = get_status_id 'passed'.to_sym if @scenario.exception == nil
|
26
|
+
status_id = get_status_id 'failed'.to_sym if @scenario.exception != nil
|
27
|
+
run_id = @config['run_id']
|
28
|
+
|
29
|
+
if case_id && run_id
|
30
|
+
response = client.send_post(
|
31
|
+
"add_result_for_case/#{run_id}/#{case_id}",
|
32
|
+
{ status_id: status_id }
|
33
|
+
)
|
34
|
+
else
|
35
|
+
raise 'unable to get case id or run id'
|
36
|
+
end
|
37
|
+
|
38
|
+
response
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_status_ids
|
42
|
+
client.send_get('get_statuses')
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def setup_testrail_client
|
48
|
+
@client = TestRail::APIClient.new(@config['url'])
|
49
|
+
@client.user = @config['user']
|
50
|
+
@client.password = @config['password']
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_status_id(status)
|
54
|
+
case status
|
55
|
+
when :passed
|
56
|
+
1
|
57
|
+
when :blocked
|
58
|
+
2
|
59
|
+
when :untested
|
60
|
+
3
|
61
|
+
when :retest
|
62
|
+
4
|
63
|
+
when :failed
|
64
|
+
5
|
65
|
+
when :undefined
|
66
|
+
raise 'missing step definition'
|
67
|
+
else
|
68
|
+
raise 'unexpected scenario status passed'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testrail-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prashanth Sams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- sams.prashanth@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/testrail-rspec.rb
|
21
|
+
- lib/testrail-rspec/api-client.rb
|
22
|
+
- lib/testrail-rspec/update-testrails.rb
|
23
|
+
- lib/testrail-rspec/version.rb
|
24
|
+
homepage:
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata:
|
28
|
+
documentation_uri: https://www.rubydoc.info/github/prashanth-sams/testrail-rspec/master
|
29
|
+
source_code_uri: https://github.com/prashanth-sams/testrail-rspec
|
30
|
+
bug_tracker_uri: https://github.com/prashanth-sams/testrail-rspec/issues
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.0.4
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Sync Rspec test results with your testrail suite
|
50
|
+
test_files: []
|