tagrail 0.0.1
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/tagrail.rb +56 -0
- data/lib/tagrail/client.rb +119 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39edd848f1d75d598d9adba6d167740ce89f25e4
|
4
|
+
data.tar.gz: fcefa7a55c19a9c34d55643dd896183a951f39ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02ed3697fc939a4a511877eaea72b079b5fbd6d2a9016738d51102ee35dae1bc1501005a09727aa6e3e327c9b5403fcff2798c1a32bbe01bc6448789326edc2d
|
7
|
+
data.tar.gz: 2534b83ed4a3ed2ed7ac6e0d35e7caf7229048b03a140ff13383e786c09c6f1d53aac703f187f359acadf63eb3d7bf677524c49a5cd04e466fbdc667142c6604
|
data/lib/tagrail.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/core/formatters/base_text_formatter'
|
3
|
+
require_relative './tagrail/client'
|
4
|
+
|
5
|
+
RSpec.configuration.add_setting :testrail_formatter_options, :default => {}
|
6
|
+
|
7
|
+
class Tagrail < RSpec::Core::Formatters::BaseTextFormatter
|
8
|
+
|
9
|
+
RSpec::Core::Formatters.register self, :start, :close, :dump_summary
|
10
|
+
|
11
|
+
def initialize(output)
|
12
|
+
@options = {}
|
13
|
+
super(output)
|
14
|
+
end
|
15
|
+
|
16
|
+
def start(notification)
|
17
|
+
@run_name = start_timestamp
|
18
|
+
|
19
|
+
puts "TestRail Exporter [INFO] Executing #{notification.count} tests. Loaded in #{notification.load_time}"
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def dump_summary(notification)
|
25
|
+
@options = RSpec.configuration.testrail_formatter_options
|
26
|
+
@client = Testrail::Client.new(@options)
|
27
|
+
@run = @client.add_run(@options[:project_id], @options[:suite_id], @run_name)
|
28
|
+
|
29
|
+
notification.examples.each do |example|
|
30
|
+
case_id = example.metadata[:test_id]
|
31
|
+
|
32
|
+
result = { status_id: Testrail::STATUS[example.execution_result.status] }
|
33
|
+
exception = example.execution_result.exception
|
34
|
+
|
35
|
+
#if a test returns an exception, the exception will be included
|
36
|
+
#as a result comment in testrail
|
37
|
+
if !exception.nil?
|
38
|
+
result.merge!({ comment: "Error: #{exception} #{exception.backtrace.join('\n')}"})
|
39
|
+
end
|
40
|
+
|
41
|
+
@client.add_result_for_case(@run['id'], case_id, result)
|
42
|
+
end
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def close(null_notification)
|
47
|
+
puts "TestRail Exporter [INFO] Closing..."
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def start_timestamp
|
54
|
+
Time.at((Time.now.to_i.to_s[0..7] + "00").to_i).strftime('%d %b %Y %R %Z')
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Testrail
|
7
|
+
|
8
|
+
STATUS = {
|
9
|
+
passed: 1,
|
10
|
+
failed: 5,
|
11
|
+
skipped: 7,
|
12
|
+
pending: 6
|
13
|
+
}
|
14
|
+
|
15
|
+
class Client
|
16
|
+
|
17
|
+
def initialize(args)
|
18
|
+
@projects = nil
|
19
|
+
@sections = Hash.new
|
20
|
+
@suite = Hash.new
|
21
|
+
@suites = []
|
22
|
+
|
23
|
+
@client = APIClient.new args[:url]
|
24
|
+
%w(user password project_id).each do |key|
|
25
|
+
raise Exception.new("TestRail configuration key :#{key} not set. Cannot continue without it.") if args[key.intern].nil?
|
26
|
+
@client.send "#{key}=", args[key.intern] if %w(user password).include? key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_run(project_id, suite_id, run_name)
|
31
|
+
@client.send_post("add_run/#{project_id}", { suite_id: suite_id,
|
32
|
+
name: run_name })
|
33
|
+
end
|
34
|
+
|
35
|
+
#cases
|
36
|
+
def get_case(case_id)
|
37
|
+
@client.send_get("get_case/#{case_id}")
|
38
|
+
end
|
39
|
+
|
40
|
+
#results
|
41
|
+
def add_result_for_case(run_id, case_id, result)
|
42
|
+
@client.send_post("add_result_for_case/#{run_id}/#{case_id}", result)
|
43
|
+
end
|
44
|
+
|
45
|
+
#projects
|
46
|
+
def get_project(project_id)
|
47
|
+
@client.send_get("get_project/#{project_id}")
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class APIClient
|
53
|
+
@url = ''
|
54
|
+
@user = ''
|
55
|
+
@password = ''
|
56
|
+
|
57
|
+
attr_accessor :user
|
58
|
+
attr_accessor :password
|
59
|
+
|
60
|
+
def initialize(base_url)
|
61
|
+
if !base_url.match(/\/$/)
|
62
|
+
base_url += '/'
|
63
|
+
end
|
64
|
+
@url = base_url + 'index.php?/api/v2/'
|
65
|
+
end
|
66
|
+
|
67
|
+
def send_get(uri)
|
68
|
+
_send_request('GET', uri, nil)
|
69
|
+
end
|
70
|
+
|
71
|
+
def send_post(uri, data)
|
72
|
+
_send_request('POST', uri, data)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def _send_request(method, uri, data)
|
77
|
+
url = URI.parse(@url + uri)
|
78
|
+
if method == 'POST'
|
79
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
80
|
+
request.body = JSON.dump(data)
|
81
|
+
else
|
82
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
83
|
+
end
|
84
|
+
request.basic_auth(@user, @password)
|
85
|
+
request.add_field('Content-Type', 'application/json')
|
86
|
+
|
87
|
+
conn = Net::HTTP.new(url.host, url.port)
|
88
|
+
if url.scheme == 'https'
|
89
|
+
conn.use_ssl = true
|
90
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
91
|
+
end
|
92
|
+
response = conn.request(request)
|
93
|
+
|
94
|
+
if response.body && !response.body.empty?
|
95
|
+
begin
|
96
|
+
result = JSON.parse(response.body)
|
97
|
+
rescue JSON::ParserError => e
|
98
|
+
raise APIError.new "TestRail API request (#{request.method} #{url}) failed\n#{e.class}: #{e.message}"
|
99
|
+
end
|
100
|
+
else
|
101
|
+
result = {}
|
102
|
+
end
|
103
|
+
|
104
|
+
if response.code != '200'
|
105
|
+
if result && result.key?('error')
|
106
|
+
error = '"' + result['error'] + '"'
|
107
|
+
else
|
108
|
+
error = 'No additional error message received'
|
109
|
+
end
|
110
|
+
raise APIError.new "TestRail API returned HTTP #{response.code} (#{error})"
|
111
|
+
end
|
112
|
+
|
113
|
+
result
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class APIError < StandardError
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tagrail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Guanzon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubytree
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Another RSpec formatter for Testrail
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/tagrail.rb
|
76
|
+
- lib/tagrail/client.rb
|
77
|
+
homepage: https://github.com/cguanzon/tagrail
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.14
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Put Test Id's in tags an go
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|