testrail_rspec_formatter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/testrail_rspec_formatter/client.rb +100 -0
- data/lib/testrail_rspec_formatter/formatter.rb +78 -0
- data/lib/testrail_rspec_formatter/version.rb +3 -0
- data/lib/testrail_rspec_formatter.rb +6 -0
- data/testrail_rspec_formatter.gemspec +35 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c6ed2420e271a13f68503bc3c95a17ad71a3afb
|
4
|
+
data.tar.gz: 6dcfcf9dc87468142dc91209546097e5ea2e536c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5868d6f21d1b2a1ba92b225fb1defa46b3b94c5ed967ef12178ee81e5f95b420d32daae01f82cfb69f012961fd70e8182adc255f1ccaae0ba1d9e01640d48548
|
7
|
+
data.tar.gz: e9a5a560aa363d75f0fe48a0dae8176735158c73084bb5517f781367595312d5361f15a480f3c59850cb1096e7ac4b5cff86a0ddbed747c90a2f45181777962b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ary Borenszweig
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# TestrailRspecFormatter
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/testrail_rspec_formatter`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'testrail_rspec_formatter'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install testrail_rspec_formatter
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/testrail_rspec_formatter.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "testrail_rspec_formatter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# TestRail API binding for Ruby (API v2, available since TestRail 3.0)
|
2
|
+
#
|
3
|
+
# Learn more:
|
4
|
+
#
|
5
|
+
# http://docs.gurock.com/testrail-api2/start
|
6
|
+
# http://docs.gurock.com/testrail-api2/accessing
|
7
|
+
#
|
8
|
+
# Copyright Gurock Software GmbH. See license.md for details.
|
9
|
+
|
10
|
+
require 'net/http'
|
11
|
+
require 'net/https'
|
12
|
+
require 'uri'
|
13
|
+
require 'json'
|
14
|
+
|
15
|
+
module TestrailRspecFormatter
|
16
|
+
class APIClient
|
17
|
+
attr_accessor :user
|
18
|
+
attr_accessor :password
|
19
|
+
|
20
|
+
def initialize(base_url)
|
21
|
+
if !base_url.match(/\/$/)
|
22
|
+
base_url += '/'
|
23
|
+
end
|
24
|
+
@url = base_url + 'index.php?/api/v2/'
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Send Get
|
29
|
+
#
|
30
|
+
# Issues a GET request (read) against the API and returns the result
|
31
|
+
# (as Ruby hash).
|
32
|
+
#
|
33
|
+
# Arguments:
|
34
|
+
#
|
35
|
+
# uri The API method to call including parameters
|
36
|
+
# (e.g. get_case/1)
|
37
|
+
#
|
38
|
+
def send_get(uri)
|
39
|
+
_send_request('GET', uri, nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Send POST
|
44
|
+
#
|
45
|
+
# Issues a POST request (write) against the API and returns the result
|
46
|
+
# (as Ruby hash).
|
47
|
+
#
|
48
|
+
# Arguments:
|
49
|
+
#
|
50
|
+
# uri The API method to call including parameters
|
51
|
+
# (e.g. add_case/1)
|
52
|
+
# data The data to submit as part of the request (as
|
53
|
+
# Ruby hash, strings must be UTF-8 encoded)
|
54
|
+
#
|
55
|
+
def send_post(uri, data)
|
56
|
+
_send_request('POST', uri, data)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def _send_request(method, uri, data)
|
61
|
+
url = URI.parse(@url + uri)
|
62
|
+
if method == 'POST'
|
63
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
64
|
+
request.body = JSON.dump(data)
|
65
|
+
else
|
66
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
67
|
+
end
|
68
|
+
request.basic_auth(@user, @password)
|
69
|
+
request.add_field('Content-Type', 'application/json')
|
70
|
+
|
71
|
+
conn = Net::HTTP.new(url.host, url.port)
|
72
|
+
if url.scheme == 'https'
|
73
|
+
conn.use_ssl = true
|
74
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
75
|
+
end
|
76
|
+
response = conn.request(request)
|
77
|
+
|
78
|
+
if response.body && !response.body.empty?
|
79
|
+
result = JSON.parse(response.body)
|
80
|
+
else
|
81
|
+
result = {}
|
82
|
+
end
|
83
|
+
|
84
|
+
if response.code != '200'
|
85
|
+
if result && result.key?('error')
|
86
|
+
error = '"' + result['error'] + '"'
|
87
|
+
else
|
88
|
+
error = 'No additional error message received'
|
89
|
+
end
|
90
|
+
raise APIError.new('TestRail API returned HTTP %s (%s)' %
|
91
|
+
[response.code, error])
|
92
|
+
end
|
93
|
+
|
94
|
+
result
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class APIError < StandardError
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "rspec/core/formatters/base_text_formatter"
|
3
|
+
|
4
|
+
require "testrail_rspec_formatter/client"
|
5
|
+
require "testrail_rspec_formatter/formatter"
|
6
|
+
|
7
|
+
RSpec.configuration.add_setting :testrail_formatter_options, :default => {}
|
8
|
+
|
9
|
+
module TestrailRspecFormatter
|
10
|
+
class Formatter < ::RSpec::Core::Formatters::BaseTextFormatter
|
11
|
+
PASSED = 1
|
12
|
+
BLOCKED = 2
|
13
|
+
UNTESTED = 3
|
14
|
+
RETEST = 4
|
15
|
+
FAILED = 5
|
16
|
+
|
17
|
+
RSpec::Core::Formatters.register self, :start, :close, :dump_summary, :dump_failures, :dump_pending
|
18
|
+
|
19
|
+
def dump_summary(notification)
|
20
|
+
examples = notification.examples
|
21
|
+
results = []
|
22
|
+
examples.each do |example|
|
23
|
+
next if example.pending?
|
24
|
+
|
25
|
+
testrail_metadata = example.metadata[:testrail]
|
26
|
+
next unless testrail_metadata
|
27
|
+
|
28
|
+
result = {
|
29
|
+
case_id: testrail_metadata,
|
30
|
+
status_id: testrail_status(example),
|
31
|
+
}
|
32
|
+
results << result
|
33
|
+
end
|
34
|
+
|
35
|
+
unless results.empty?
|
36
|
+
post_testrail_results(results)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump_failures(*)
|
41
|
+
# Nothing
|
42
|
+
end
|
43
|
+
|
44
|
+
def dump_pending(*)
|
45
|
+
# Nothing
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def post_testrail_results(results)
|
51
|
+
client = new_testrail_client
|
52
|
+
run_id = testrail_config_value(:run_id, "TESTRAIL_FORMATTER_RUN_ID")
|
53
|
+
|
54
|
+
json = {results: results}
|
55
|
+
client.send_post("add_results_for_cases/#{run_id}", json)
|
56
|
+
end
|
57
|
+
|
58
|
+
def new_testrail_client
|
59
|
+
client = APIClient.new(testrail_config_value(:url, "TESTRAIL_FORMATTER_URL"))
|
60
|
+
client.user = testrail_config_value(:user, "TESTRAIL_FORMATTER_USER")
|
61
|
+
client.password = testrail_config_value(:password, "TESTRAIL_FORMATTER_PASSWORD")
|
62
|
+
client
|
63
|
+
end
|
64
|
+
|
65
|
+
def testrail_config_value(hash_key, env_key)
|
66
|
+
RSpec.configuration.testrail_formatter_options[hash_key] || ENV[env_key] || raise("Missing RSpec.configuration.testrail_formatter_options[#{hash_key.inspect}] or ENV[#{env_key.inspect}]")
|
67
|
+
end
|
68
|
+
|
69
|
+
def testrail_status(example)
|
70
|
+
case example.execution_result.status
|
71
|
+
when :passed
|
72
|
+
PASSED
|
73
|
+
else
|
74
|
+
FAILED
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'testrail_rspec_formatter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "testrail_rspec_formatter"
|
8
|
+
spec.version = TestrailRspecFormatter::VERSION
|
9
|
+
spec.authors = ["Ary Borenszweig"]
|
10
|
+
spec.email = ["aborenszweig@manas.com.ar"]
|
11
|
+
|
12
|
+
spec.summary = "RSpec formatter that sends data to testrail.com"
|
13
|
+
spec.description = "RSpec formatter that sends data to testrail.com"
|
14
|
+
spec.homepage = "https://github.com/manastech/testrail_rspec_formatter"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'rspec', '~> 3.0'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testrail_rspec_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ary Borenszweig
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-04 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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: RSpec formatter that sends data to testrail.com
|
70
|
+
email:
|
71
|
+
- aborenszweig@manas.com.ar
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/testrail_rspec_formatter.rb
|
86
|
+
- lib/testrail_rspec_formatter/client.rb
|
87
|
+
- lib/testrail_rspec_formatter/formatter.rb
|
88
|
+
- lib/testrail_rspec_formatter/version.rb
|
89
|
+
- testrail_rspec_formatter.gemspec
|
90
|
+
homepage: https://github.com/manastech/testrail_rspec_formatter
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.0
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: RSpec formatter that sends data to testrail.com
|
115
|
+
test_files: []
|