resttestrail 0.0.2
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/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +4 -0
- data/integration_spec/resttestrail.rb +41 -0
- data/lib/resttestrail.rb +4 -0
- data/lib/resttestrail/client.rb +73 -0
- data/lib/resttestrail/config.rb +13 -0
- data/lib/resttestrail/requests.rb +56 -0
- data/lib/resttestrail/testrailerror.rb +9 -0
- data/lib/resttestrail/version.rb +3 -0
- data/resttestrail.gemspec +26 -0
- data/spec/lib/resttestrail/client_spec.rb +81 -0
- data/spec/lib/resttestrail/config_spec.rb +24 -0
- data/spec/lib/resttestrail/requests_spec.rb +56 -0
- data/spec/lib/resttestrail/testrailerror_spec.rb +13 -0
- data/spec/spec_helper.rb +89 -0
- metadata +124 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f0d69d88007a70879759606026185899e0547088
|
|
4
|
+
data.tar.gz: b176b4847a4e1805864dc96667226c1a768da821
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bd0a3359e2d8085e19b39138cd190398b7a7b49f713361cdac6ba14b06187d3ca93fafc9c0c24d48ebd7077d9da3b14149a7c7f8e6fab48cf96b948d903cbccf
|
|
7
|
+
data.tar.gz: 41fa4518deb99c0c251043788026827a069bcc6419a9cd28ab8f0769887120858740f5c3eb7cdde2d789573958dee8b1133c0537ba3383531651b1df4c1392ad
|
data/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Syed Hussain
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Resttestrail
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'resttestrail'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install resttestrail
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/resttestrail/fork )
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "./lib/resttestrail/version"
|
|
4
|
+
require "./lib/resttestrail/testrailerror"
|
|
5
|
+
require "./lib/resttestrail/config"
|
|
6
|
+
require "./lib/resttestrail/client"
|
|
7
|
+
require 'pry'
|
|
8
|
+
|
|
9
|
+
module Resttestrail
|
|
10
|
+
# Your code goes here...
|
|
11
|
+
Resttestrail.config.host = "testrail-app1.snc1"
|
|
12
|
+
Resttestrail.config.port = 80
|
|
13
|
+
Resttestrail.config.project_id = 26
|
|
14
|
+
Resttestrail.config.username = "bizops-testeng1@groupon.com"
|
|
15
|
+
Resttestrail.config.password = "password"
|
|
16
|
+
suite_id = 1261
|
|
17
|
+
test_case_id = 197611
|
|
18
|
+
|
|
19
|
+
puts "host = #{Resttestrail.config.host}, port = #{Resttestrail.config.port}"
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
client = Resttestrail::Client.instance
|
|
23
|
+
run_id = client.add_run("an amazing run #{Time.new.strftime("%H_%M_%S_%N")}", suite_id)
|
|
24
|
+
puts "run id = #{run_id}"
|
|
25
|
+
|
|
26
|
+
run_test_case_id = client.add_result_for_case(run_id, test_case_id, Resttestrail::Requests::TEST_STATUS_PASSED, 24, nil)
|
|
27
|
+
puts "new test_case_id = #{run_test_case_id}"
|
|
28
|
+
|
|
29
|
+
new_run = client.get_run(run_id)
|
|
30
|
+
puts "run data= #{new_run}"
|
|
31
|
+
|
|
32
|
+
client.delete_run(run_id)
|
|
33
|
+
puts "run deleted"
|
|
34
|
+
|
|
35
|
+
puts "Finished!!"
|
|
36
|
+
rescue TestrailError => e
|
|
37
|
+
puts "Exception:"
|
|
38
|
+
puts "Message = #{e.message}"
|
|
39
|
+
puts "Hash = #{e.object}"
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/resttestrail.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
require './lib/resttestrail/requests'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module Resttestrail
|
|
7
|
+
class Client
|
|
8
|
+
attr_reader :net_http
|
|
9
|
+
|
|
10
|
+
private_class_method :new
|
|
11
|
+
|
|
12
|
+
def self.instance
|
|
13
|
+
@instance ||= new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@net_http = Net::HTTP.new(Resttestrail.config.host, Resttestrail.config.port)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_run(run_name, suite_id)
|
|
21
|
+
request = Resttestrail::Requests.add_run(run_name, suite_id)
|
|
22
|
+
http_response = Resttestrail::Client.response(@net_http.request(request))
|
|
23
|
+
http_response[:body]["id"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_run(run_id)
|
|
27
|
+
request = Resttestrail::Requests.get_run(run_id)
|
|
28
|
+
Resttestrail::Client.response(@net_http.request(request))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def delete_run(run_id)
|
|
32
|
+
request = Resttestrail::Requests.delete_run(run_id)
|
|
33
|
+
Resttestrail::Client.response(@net_http.request(request))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add_result_for_case(run_id, test_case_id, status, elapsed_time_secs, exception=nil)
|
|
37
|
+
request = Resttestrail::Requests.add_result_for_case(run_id, test_case_id, status, elapsed_time_secs, exception=nil)
|
|
38
|
+
http_response = Resttestrail::Client.response(@net_http.request(request))
|
|
39
|
+
http_response[:body]["id"]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.close_run(run_id)
|
|
43
|
+
request = Resttestrail::Requests.close_run(run_id)
|
|
44
|
+
http_response = Resttestrail::Client.response(@net_http.request(request))
|
|
45
|
+
http_response[:body]["id"]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.response(http_response)
|
|
49
|
+
response_hash = {:success => false, :code => nil, :body => nil, :message => nil}
|
|
50
|
+
|
|
51
|
+
if http_response.nil?
|
|
52
|
+
raise Resttestrail::TestrailError.new(response_hash), "Received nil response"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
response_hash[:success] = (http_response.code == "200" && http_response.message == "OK")
|
|
56
|
+
response_hash[:code] = http_response.code
|
|
57
|
+
response_hash[:body] = http_response.body
|
|
58
|
+
response_hash[:message] = http_response.message
|
|
59
|
+
|
|
60
|
+
raise Resttestrail::TestrailError.new(response_hash), "Unsuccessful response" unless response_hash[:success]
|
|
61
|
+
|
|
62
|
+
begin
|
|
63
|
+
response_hash[:body] = (http_response.body == "") ? "" : JSON.parse(http_response.body)
|
|
64
|
+
response_hash[:success] = true
|
|
65
|
+
rescue StandardError => e
|
|
66
|
+
response_hash[:success] = false
|
|
67
|
+
raise Resttestrail::TestrailError.new(response_hash), "Error while parsing response"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
response_hash
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module Resttestrail
|
|
5
|
+
|
|
6
|
+
module Requests
|
|
7
|
+
URI = "/index.php?/api/v2"
|
|
8
|
+
ADD_RUN = "/add_run/"
|
|
9
|
+
GET_RUN = "/get_run/"
|
|
10
|
+
DELETE_RUN = "/delete_run/"
|
|
11
|
+
ADD_RESULT_FOR_CASE = "/add_result_for_case/"
|
|
12
|
+
CLOSE_RUN = "/close_run/"
|
|
13
|
+
|
|
14
|
+
TEST_STATUS_PASSED = 1
|
|
15
|
+
TEST_STATUS_FAILED = 5
|
|
16
|
+
TEST_STATUS_BLOCKED = 2
|
|
17
|
+
|
|
18
|
+
def self.add_run(run_name, suite_id)
|
|
19
|
+
uri = "#{URI}#{ADD_RUN}#{Resttestrail.config.project_id}"
|
|
20
|
+
request = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
|
|
21
|
+
request.body = {"suite_id" => suite_id, "name" => run_name, "include_all" => true}.to_json
|
|
22
|
+
request
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.get_run(run_id)
|
|
26
|
+
Net::HTTP::Get.new("#{URI}#{GET_RUN}#{run_id}", initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.delete_run(run_id)
|
|
30
|
+
Net::HTTP::Post.new("#{URI}#{DELETE_RUN}#{run_id}", initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.add_result_for_case(run_id, test_case_id, status, elapsed_time_secs, exception=nil)
|
|
34
|
+
uri = "#{URI}#{ADD_RESULT_FOR_CASE}#{run_id}/#{test_case_id}"
|
|
35
|
+
request = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
|
|
36
|
+
body = {"status_id" => status}
|
|
37
|
+
unless elapsed_time_secs.nil?
|
|
38
|
+
elapsed_time_secs = 1 if elapsed_time_secs < 1
|
|
39
|
+
elapsed_time = elapsed_time_secs.round.to_s+"s"
|
|
40
|
+
body.merge!("elapsed" => elapsed_time)
|
|
41
|
+
end
|
|
42
|
+
body.merge!("defects" => exception) unless exception.nil?
|
|
43
|
+
request.body = body.to_json
|
|
44
|
+
request
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.close_run(run_id)
|
|
48
|
+
uri = "#{URI}#{CLOSE_RUN}#{run_id}"
|
|
49
|
+
Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.basic_auth_string
|
|
53
|
+
@@basic_auth_string ||= "Basic " + Base64.encode64("#{Resttestrail.config.username}:#{Resttestrail.config.password}")
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'resttestrail/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "resttestrail"
|
|
8
|
+
spec.version = Resttestrail::VERSION
|
|
9
|
+
spec.authors = ["Syed Hussain"]
|
|
10
|
+
spec.email = ["shussain@groupon.com"]
|
|
11
|
+
spec.summary = %q{Gem for Testrail rest api}
|
|
12
|
+
spec.description = %q{Supports api calls related to test runs}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = [`git ls-files -z`.split("\x0")]
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'activesupport', '~> 3.1'
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
24
|
+
spec.add_development_dependency "rspec"
|
|
25
|
+
spec.add_development_dependency "rake"
|
|
26
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
describe Resttestrail::Client do
|
|
5
|
+
|
|
6
|
+
describe "response" do
|
|
7
|
+
it "raises error for nil http response from testrail" do
|
|
8
|
+
hash_object = {:success => false, :code => nil, :body => nil, :message => nil}
|
|
9
|
+
expect { Resttestrail::Client.response(nil) }.to raise_error { |e|
|
|
10
|
+
expect(e).to be_a(Resttestrail::TestrailError)
|
|
11
|
+
expect(e.message).to eq "Received nil response"
|
|
12
|
+
expect(e.object).to eq hash_object
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "raises error for a non 200 http response code from testrail" do
|
|
17
|
+
http_response = Net::HTTPResponse.new("1.1", "201", "OK")
|
|
18
|
+
body_hash = {"field1" => "value1"}
|
|
19
|
+
hash_object = {:success=>false, :code=>"201", :body=>"{\"field1\":\"value1\"}", :message=>"OK"}
|
|
20
|
+
allow(http_response).to receive_messages(:stream_check => true, :body => body_hash.to_json)
|
|
21
|
+
expect { Resttestrail::Client.response(http_response) }.to raise_error { |e|
|
|
22
|
+
expect(e).to be_a(Resttestrail::TestrailError)
|
|
23
|
+
expect(e.message).to eq "Unsuccessful response"
|
|
24
|
+
expect(e.object).to eq hash_object
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "raises error for nil http response body from testrail" do
|
|
29
|
+
http_response = Net::HTTPResponse.new("1.1", "200", "OK")
|
|
30
|
+
allow(http_response).to receive_messages(:stream_check => true)
|
|
31
|
+
hash_object = {:success=>false, :code=>"200", :body=>nil, :message=>"OK"}
|
|
32
|
+
expect { Resttestrail::Client.response(http_response) }.to raise_error { |e|
|
|
33
|
+
expect(e).to be_a(Resttestrail::TestrailError)
|
|
34
|
+
expect(e.message).to eq "Error while parsing response"
|
|
35
|
+
expect(e.object).to eq hash_object
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "returns the response hash for a successful http response from testrail" do
|
|
40
|
+
http_response = Net::HTTPResponse.new("1.1", "200", "OK")
|
|
41
|
+
body_hash = {"field1" => "value1"}
|
|
42
|
+
hash_object = {:success=>true, :code=>"200", :body=>body_hash, :message=>"OK"}
|
|
43
|
+
allow(http_response).to receive_messages(:stream_check => true, :body => body_hash.to_json)
|
|
44
|
+
expect { Resttestrail::Client.response(http_response) }.not_to raise_error
|
|
45
|
+
response = Resttestrail::Client.response(http_response)
|
|
46
|
+
expect(response).to eq hash_object
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "raises error for a not ok http response message from testrail" do
|
|
50
|
+
http_response = Net::HTTPResponse.new("1.1", "200", "Not OK")
|
|
51
|
+
body_hash = {"field1" => "value1"}.to_json
|
|
52
|
+
hash_object = {:success=>false, :code=>"200", :body=>body_hash, :message=>"Not OK"}
|
|
53
|
+
allow(http_response).to receive_messages(:stream_check => true, :body => body_hash)
|
|
54
|
+
expect { Resttestrail::Client.response(http_response) }.to raise_error { |e|
|
|
55
|
+
expect(e).to be_a(Resttestrail::TestrailError)
|
|
56
|
+
expect(e.message).to eq "Unsuccessful response"
|
|
57
|
+
expect(e.object).to eq hash_object
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "raises error for any json parsing errors" do
|
|
62
|
+
http_response = Net::HTTPResponse.new("1.1", "200", "OK")
|
|
63
|
+
hash_object = {:success=>false, :code=>"200", :body=>{}, :message=>"OK"}
|
|
64
|
+
allow(http_response).to receive_messages(:stream_check => true, :body => {})
|
|
65
|
+
expect { Resttestrail::Client.response(http_response) }.to raise_error { |e|
|
|
66
|
+
expect(e.message).to eq "Error while parsing response"
|
|
67
|
+
expect(e.object).to eq hash_object
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "does not raise error for an empty string response body" do
|
|
72
|
+
http_response = Net::HTTPResponse.new("1.1", "200", "OK")
|
|
73
|
+
hash_object = {:success=>true, :code=>"200", :body=>"", :message=>"OK"}
|
|
74
|
+
allow(http_response).to receive_messages(:stream_check => true, :body => "")
|
|
75
|
+
expect { Resttestrail::Client.response(http_response) }.not_to raise_error
|
|
76
|
+
response = Resttestrail::Client.response(http_response)
|
|
77
|
+
expect(response).to eq hash_object
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Resttestrail.config do
|
|
4
|
+
it "returns a Resttestrail::Config object" do
|
|
5
|
+
expect(Resttestrail.config).to be_a(Resttestrail::Config)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "returns the same config object" do
|
|
9
|
+
config1 = Resttestrail.config
|
|
10
|
+
config2 = Resttestrail.config
|
|
11
|
+
expect(config2).to eq config1
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe Resttestrail::Config do
|
|
16
|
+
it "has the right configurations" do
|
|
17
|
+
config = Resttestrail::Config.new
|
|
18
|
+
expect{ config.host }.not_to raise_error
|
|
19
|
+
expect{ config.port }.not_to raise_error
|
|
20
|
+
expect{ config.username }.not_to raise_error
|
|
21
|
+
expect{ config.password }.not_to raise_error
|
|
22
|
+
expect{ config.project_id }.not_to raise_error
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Resttestrail::Requests do
|
|
4
|
+
before(:all) do
|
|
5
|
+
config = Resttestrail.config
|
|
6
|
+
config.username = "some_username"
|
|
7
|
+
config.password = "some_password"
|
|
8
|
+
config.project_id = 37
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "makes the correct basic auth string" do
|
|
12
|
+
expect(Resttestrail::Requests.basic_auth_string).to eq "Basic c29tZV91c2VybmFtZTpzb21lX3Bhc3N3b3Jk\n"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "makes the add run request" do
|
|
16
|
+
add_run_request = Resttestrail::Requests.add_run("an amazing run", 1234)
|
|
17
|
+
expect(add_run_request.method).to eq "POST"
|
|
18
|
+
expect(add_run_request.path).to eq "/index.php?/api/v2/add_run/37"
|
|
19
|
+
expect(add_run_request.body).to eq "{\"suite_id\":1234,\"name\":\"an amazing run\",\"include_all\":true}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "makes the add result for case request for passed test" do
|
|
23
|
+
add_result_for_case_request = Resttestrail::Requests.add_result_for_case(1234, 45, Resttestrail::Requests::TEST_STATUS_PASSED, 37, nil)
|
|
24
|
+
expect(add_result_for_case_request.method).to eq "POST"
|
|
25
|
+
expect(add_result_for_case_request.path).to eq "/index.php?/api/v2/add_result_for_case/1234/45"
|
|
26
|
+
expect(add_result_for_case_request.body).to eq "{\"status_id\":1,\"elapsed\":\"37s\"}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "makes the add result for case request for failed test" do
|
|
30
|
+
add_result_for_case_request = Resttestrail::Requests.add_result_for_case(1234, 45, Resttestrail::Requests::TEST_STATUS_FAILED, 37, "some exception")
|
|
31
|
+
expect(add_result_for_case_request.method).to eq "POST"
|
|
32
|
+
expect(add_result_for_case_request.path).to eq "/index.php?/api/v2/add_result_for_case/1234/45"
|
|
33
|
+
expect(add_result_for_case_request.body).to eq "{\"status_id\":5,\"elapsed\":\"37s\",\"defects\":\"some exception\"}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "makes the close run request" do
|
|
37
|
+
close_run_request = Resttestrail::Requests.close_run(1234)
|
|
38
|
+
expect(close_run_request.method).to eq "POST"
|
|
39
|
+
expect(close_run_request.path).to eq "/index.php?/api/v2/close_run/1234"
|
|
40
|
+
expect(close_run_request.body).to eq nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "makes the get run request" do
|
|
44
|
+
get_run_request = Resttestrail::Requests.get_run(1234)
|
|
45
|
+
expect(get_run_request.method).to eq "GET"
|
|
46
|
+
expect(get_run_request.path).to eq "/index.php?/api/v2/get_run/1234"
|
|
47
|
+
expect(get_run_request.body).to eq nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "makes the delete run request" do
|
|
51
|
+
delete_run_request = Resttestrail::Requests.delete_run(1234)
|
|
52
|
+
expect(delete_run_request.method).to eq "POST"
|
|
53
|
+
expect(delete_run_request.path).to eq "/index.php?/api/v2/delete_run/1234"
|
|
54
|
+
expect(delete_run_request.body).to eq nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Resttestrail::TestrailError do
|
|
4
|
+
it "raises the exception with the correct data" do
|
|
5
|
+
message = "Amazing Error"
|
|
6
|
+
hash_object = {:success => false, :body => "body", :error => "error"}
|
|
7
|
+
expect { raise Resttestrail::TestrailError.new(hash_object), message }.to raise_error { |e|
|
|
8
|
+
expect(e).to be_a(Resttestrail::TestrailError)
|
|
9
|
+
expect(e.message).to eq message
|
|
10
|
+
expect(e.object).to eq hash_object
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
|
5
|
+
#
|
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
|
11
|
+
# that actually need it.
|
|
12
|
+
#
|
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
|
14
|
+
# users commonly want.
|
|
15
|
+
#
|
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
17
|
+
|
|
18
|
+
Bundler.setup
|
|
19
|
+
|
|
20
|
+
require 'pry'
|
|
21
|
+
|
|
22
|
+
require './lib/resttestrail/config'
|
|
23
|
+
require './lib/resttestrail/client'
|
|
24
|
+
require './lib/resttestrail/requests'
|
|
25
|
+
require './lib/resttestrail/testrailerror'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
RSpec.configure do |config|
|
|
29
|
+
# The settings below are suggested to provide a good initial experience
|
|
30
|
+
# with RSpec, but feel free to customize to your heart's content.
|
|
31
|
+
=begin
|
|
32
|
+
# These two settings work together to allow you to limit a spec run
|
|
33
|
+
# to individual examples or groups you care about by tagging them with
|
|
34
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
|
35
|
+
# get run.
|
|
36
|
+
config.filter_run :focus
|
|
37
|
+
config.run_all_when_everything_filtered = true
|
|
38
|
+
|
|
39
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
|
40
|
+
# file, and it's useful to allow more verbose output when running an
|
|
41
|
+
# individual spec file.
|
|
42
|
+
if config.files_to_run.one?
|
|
43
|
+
# Use the documentation formatter for detailed output,
|
|
44
|
+
# unless a formatter has already been configured
|
|
45
|
+
# (e.g. via a command-line flag).
|
|
46
|
+
config.default_formatter = 'doc'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Print the 10 slowest examples and example groups at the
|
|
50
|
+
# end of the spec run, to help surface which specs are running
|
|
51
|
+
# particularly slow.
|
|
52
|
+
config.profile_examples = 10
|
|
53
|
+
|
|
54
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
55
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
56
|
+
# the seed, which is printed after each run.
|
|
57
|
+
# --seed 1234
|
|
58
|
+
config.order = :random
|
|
59
|
+
|
|
60
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
|
61
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
62
|
+
# test failures related to randomization by passing the same `--seed` value
|
|
63
|
+
# as the one that triggered the failure.
|
|
64
|
+
Kernel.srand config.seed
|
|
65
|
+
|
|
66
|
+
# rspec-expectations config goes here. You can use an alternate
|
|
67
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
68
|
+
# assertions if you prefer.
|
|
69
|
+
config.expect_with :rspec do |expectations|
|
|
70
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
|
71
|
+
# For more details, see:
|
|
72
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
|
73
|
+
expectations.syntax = :expect
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
|
77
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
78
|
+
config.mock_with :rspec do |mocks|
|
|
79
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
|
80
|
+
# For more details, see:
|
|
81
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
82
|
+
mocks.syntax = :expect
|
|
83
|
+
|
|
84
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
|
85
|
+
# a real object. This is generally recommended.
|
|
86
|
+
mocks.verify_partial_doubles = true
|
|
87
|
+
end
|
|
88
|
+
=end
|
|
89
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: resttestrail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Syed Hussain
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.1'
|
|
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.6'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.6'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
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: Supports api calls related to test runs
|
|
70
|
+
email:
|
|
71
|
+
- shussain@groupon.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- Gemfile
|
|
79
|
+
- LICENSE.txt
|
|
80
|
+
- README.md
|
|
81
|
+
- Rakefile
|
|
82
|
+
- integration_spec/resttestrail.rb
|
|
83
|
+
- lib/resttestrail.rb
|
|
84
|
+
- lib/resttestrail/client.rb
|
|
85
|
+
- lib/resttestrail/config.rb
|
|
86
|
+
- lib/resttestrail/requests.rb
|
|
87
|
+
- lib/resttestrail/testrailerror.rb
|
|
88
|
+
- lib/resttestrail/version.rb
|
|
89
|
+
- resttestrail.gemspec
|
|
90
|
+
- spec/lib/resttestrail/client_spec.rb
|
|
91
|
+
- spec/lib/resttestrail/config_spec.rb
|
|
92
|
+
- spec/lib/resttestrail/requests_spec.rb
|
|
93
|
+
- spec/lib/resttestrail/testrailerror_spec.rb
|
|
94
|
+
- spec/spec_helper.rb
|
|
95
|
+
homepage: ''
|
|
96
|
+
licenses:
|
|
97
|
+
- MIT
|
|
98
|
+
metadata: {}
|
|
99
|
+
post_install_message:
|
|
100
|
+
rdoc_options: []
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
requirements: []
|
|
114
|
+
rubyforge_project:
|
|
115
|
+
rubygems_version: 2.2.2
|
|
116
|
+
signing_key:
|
|
117
|
+
specification_version: 4
|
|
118
|
+
summary: Gem for Testrail rest api
|
|
119
|
+
test_files:
|
|
120
|
+
- spec/lib/resttestrail/client_spec.rb
|
|
121
|
+
- spec/lib/resttestrail/config_spec.rb
|
|
122
|
+
- spec/lib/resttestrail/requests_spec.rb
|
|
123
|
+
- spec/lib/resttestrail/testrailerror_spec.rb
|
|
124
|
+
- spec/spec_helper.rb
|