testrail_rspec_formatter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -7
- data/lib/testrail_rspec_formatter/client.rb +8 -4
- data/lib/testrail_rspec_formatter/formatter.rb +52 -10
- data/lib/testrail_rspec_formatter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4673b0d7956f86f4ab15a919497f4b363b8d3b
|
4
|
+
data.tar.gz: cf3cf82f5ca169f1cf1c6035849fadfe31b5b3ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2448d88a23d8279dcdfbf4560472a5266164e657f225acb31378b140cdfba35fefbf120f26f6960491851215cc747f334dc97a9dd957a5ab04d25c10c5260d60
|
7
|
+
data.tar.gz: 83d567833ad7c1f6ccf5675e681db0884538c2b89c3fe5955d4401669f8ef36d0eabda9163e9babac995a927b2c4bf50d7aa0df31865cd3c9086e33c253cfad6
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# TestrailRspecFormatter
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
An RSpec formatter that sends results to [TestRail](http://www.gurock.com/testrail/)
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,62 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
After specs run the formatter will mark test cases of a test run as either passed, failed or retest,
|
24
|
+
depending on whether a spec passed, failed or is pending. Specs are associated with TestRail test cases
|
25
|
+
by adding a tag with the name `testrail` to them:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
describe "som test" do
|
29
|
+
id "some spec", testrail: 1234 do # 1234 is the id of a test case
|
30
|
+
# ...
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
The formatter must be configured with a run name inside a project id. If a run with that name doesn't exist
|
36
|
+
it is created.
|
37
|
+
|
38
|
+
The recommended way to use this formatter is to set the run name to a project's version or tag, and only
|
39
|
+
run it on release or deploy versions (using the disabeld configuration option).
|
40
|
+
|
41
|
+
### Configuration
|
42
|
+
|
43
|
+
In addition to the configuration specified below, the formatter is only ran when passed to rspec
|
44
|
+
via a `--formatter` argument (which can be in the `.rspec` file):
|
45
|
+
|
46
|
+
```
|
47
|
+
rspec spec --format TestrailRspecFormatter::Formatter
|
48
|
+
```
|
49
|
+
|
50
|
+
To have it ran in addition to the default progress (dots) formatter, execute:
|
51
|
+
|
52
|
+
```
|
53
|
+
rspec spec --format progress --format TestrailRspecFormatter::Formatter
|
54
|
+
```
|
55
|
+
|
56
|
+
Configure it via `ENV` variables or `RSpec.configure` (or with a mix of them).
|
57
|
+
|
58
|
+
### Via ENV
|
59
|
+
|
60
|
+
* TESTRAIL_FORMATTER_PROJECT_ID: (required) the id of the TestRail project
|
61
|
+
* TESTRAIL_FORMATTER_RUN_NAME: (required) the name of the run to target
|
62
|
+
* TESTRAIL_FORMATTER_URL: (required) the URL to target (`"https://your-user.testrail.com"``)
|
63
|
+
* TESTRAIL_FORMATTER_USER: (required) your TestRail user
|
64
|
+
* TESTRAIL_FORMATTER_PASSWORD: (required) your TestRail password (not recommended) or API key (recommended)
|
65
|
+
* TESTRAIL_FORMATTER_DISABLED: (optional) set to 1 to disable the formatter
|
66
|
+
|
67
|
+
### Via `RSpec.configure`
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
RSpec.configure do |config|
|
71
|
+
config.testrail_formatter_options[:project_id] = ... # (required) the id of the TestRail project
|
72
|
+
config.testrail_formatter_options[:run_name] = ... # (required) the name of the run to target
|
73
|
+
config.testrail_formatter_options[:url] = ... # (required) the URL to target (`"https://your-user.testrail.com"``)
|
74
|
+
config.testrail_formatter_options[:user] = ... # (required) your TestRail user
|
75
|
+
config.testrail_formatter_options[:password] = ... # (required) your TestRail password (not recommended) or API key (recommended)
|
76
|
+
config.testrail_formatter_options[:disabled] = ... # (optional) set to true to disable the formatter
|
77
|
+
end
|
78
|
+
```
|
26
79
|
|
27
80
|
## Development
|
28
81
|
|
@@ -32,10 +85,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
85
|
|
33
86
|
## Contributing
|
34
87
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/manastech/testrail_rspec_formatter.
|
37
89
|
|
38
90
|
## License
|
39
91
|
|
40
92
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
@@ -14,6 +14,7 @@ require 'json'
|
|
14
14
|
|
15
15
|
module TestrailRspecFormatter
|
16
16
|
class APIClient
|
17
|
+
attr_accessor :base_url
|
17
18
|
attr_accessor :user
|
18
19
|
attr_accessor :password
|
19
20
|
|
@@ -21,6 +22,7 @@ module TestrailRspecFormatter
|
|
21
22
|
if !base_url.match(/\/$/)
|
22
23
|
base_url += '/'
|
23
24
|
end
|
25
|
+
@base_url = base_url
|
24
26
|
@url = base_url + 'index.php?/api/v2/'
|
25
27
|
end
|
26
28
|
|
@@ -35,7 +37,7 @@ module TestrailRspecFormatter
|
|
35
37
|
# uri The API method to call including parameters
|
36
38
|
# (e.g. get_case/1)
|
37
39
|
#
|
38
|
-
def
|
40
|
+
def get(uri)
|
39
41
|
_send_request('GET', uri, nil)
|
40
42
|
end
|
41
43
|
|
@@ -52,7 +54,7 @@ module TestrailRspecFormatter
|
|
52
54
|
# data The data to submit as part of the request (as
|
53
55
|
# Ruby hash, strings must be UTF-8 encoded)
|
54
56
|
#
|
55
|
-
def
|
57
|
+
def post(uri, data)
|
56
58
|
_send_request('POST', uri, data)
|
57
59
|
end
|
58
60
|
|
@@ -87,8 +89,9 @@ module TestrailRspecFormatter
|
|
87
89
|
else
|
88
90
|
error = 'No additional error message received'
|
89
91
|
end
|
90
|
-
|
91
|
-
|
92
|
+
ex = APIError.new('TestRail API returned HTTP %s (%s)' % [response.code, error])
|
93
|
+
ex.code = response.code.to_i
|
94
|
+
raise
|
92
95
|
end
|
93
96
|
|
94
97
|
result
|
@@ -96,5 +99,6 @@ module TestrailRspecFormatter
|
|
96
99
|
end
|
97
100
|
|
98
101
|
class APIError < StandardError
|
102
|
+
attr_accessor :code
|
99
103
|
end
|
100
104
|
end
|
@@ -17,11 +17,17 @@ module TestrailRspecFormatter
|
|
17
17
|
RSpec::Core::Formatters.register self, :start, :close, :dump_summary, :dump_failures, :dump_pending
|
18
18
|
|
19
19
|
def dump_summary(notification)
|
20
|
+
disabled = testrail_config_value(:disabled, "TESTRAIL_FORMATTER_DISABLED", false)
|
21
|
+
if disabled == "1" || disabled == true
|
22
|
+
testrail_log "skipped because it was disabled"
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
testrail_log "starting..."
|
27
|
+
|
20
28
|
examples = notification.examples
|
21
29
|
results = []
|
22
30
|
examples.each do |example|
|
23
|
-
next if example.pending?
|
24
|
-
|
25
31
|
testrail_metadata = example.metadata[:testrail]
|
26
32
|
next unless testrail_metadata
|
27
33
|
|
@@ -32,9 +38,13 @@ module TestrailRspecFormatter
|
|
32
38
|
results << result
|
33
39
|
end
|
34
40
|
|
35
|
-
|
41
|
+
if results.empty?
|
42
|
+
testrail_log "no test cases found (no spec had a testrail tag)"
|
43
|
+
else
|
36
44
|
post_testrail_results(results)
|
37
45
|
end
|
46
|
+
ensure
|
47
|
+
testrail_log "finished"
|
38
48
|
end
|
39
49
|
|
40
50
|
def dump_failures(*)
|
@@ -49,10 +59,32 @@ module TestrailRspecFormatter
|
|
49
59
|
|
50
60
|
def post_testrail_results(results)
|
51
61
|
client = new_testrail_client
|
52
|
-
run_id = testrail_config_value(:run_id, "TESTRAIL_FORMATTER_RUN_ID")
|
53
62
|
|
54
|
-
|
55
|
-
|
63
|
+
project_id = testrail_config_value(:project_id, "TESTRAIL_FORMATTER_PROJECT_ID")
|
64
|
+
run_name = testrail_config_value(:run_name, "TESTRAIL_FORMATTER_RUN_NAME")
|
65
|
+
|
66
|
+
testrail_log "target url is: #{client.base_url}"
|
67
|
+
|
68
|
+
runs = client.get("get_runs/#{project_id}")
|
69
|
+
run = runs.find { |run| run["name"] == run_name }
|
70
|
+
if run
|
71
|
+
run_id = run["id"]
|
72
|
+
testrail_log "found run with name #{run_name.inspect}, id is #{run["id"]}"
|
73
|
+
else
|
74
|
+
testrail_log "no run found with name #{run_name.inspect}, creating one..."
|
75
|
+
case_ids = results.map { |result| result[:case_id] }
|
76
|
+
run = client.post("add_run/#{project_id}", {
|
77
|
+
name: run_name,
|
78
|
+
include_all: false,
|
79
|
+
case_ids: case_ids,
|
80
|
+
})
|
81
|
+
run_id = run["id"]
|
82
|
+
testrail_log "created run with id #{run["id"]}"
|
83
|
+
end
|
84
|
+
|
85
|
+
testrail_log "sending results for #{results.size} test case#{results.size == 1 ? "" : "s"}..."
|
86
|
+
|
87
|
+
client.post("add_results_for_cases/#{run_id}", {results: results})
|
56
88
|
end
|
57
89
|
|
58
90
|
def new_testrail_client
|
@@ -62,17 +94,27 @@ module TestrailRspecFormatter
|
|
62
94
|
client
|
63
95
|
end
|
64
96
|
|
65
|
-
def testrail_config_value(hash_key, env_key)
|
66
|
-
|
97
|
+
def testrail_config_value(hash_key, env_key, default = nil)
|
98
|
+
value = RSpec.configuration.testrail_formatter_options[hash_key] || ENV[env_key]
|
99
|
+
if !value && default == nil
|
100
|
+
raise("Missing RSpec.configuration.testrail_formatter_options[#{hash_key.inspect}] or ENV[#{env_key.inspect}]")
|
101
|
+
end
|
102
|
+
value || default
|
67
103
|
end
|
68
104
|
|
69
105
|
def testrail_status(example)
|
70
|
-
case
|
71
|
-
when
|
106
|
+
case
|
107
|
+
when example.pending?
|
108
|
+
RETEST
|
109
|
+
when example.execution_result.status == :passed
|
72
110
|
PASSED
|
73
111
|
else
|
74
112
|
FAILED
|
75
113
|
end
|
76
114
|
end
|
115
|
+
|
116
|
+
def testrail_log(message)
|
117
|
+
output.puts "TestRail: #{message}"
|
118
|
+
end
|
77
119
|
end
|
78
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testrail_rspec_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ary Borenszweig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|