quinoa 0.0.10 → 0.0.11
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 +4 -4
- data/.travis.yml +1 -0
- data/Gemfile.lock +46 -44
- data/README.md +5 -2
- data/changelog +4 -0
- data/lib/quinoa/service.rb +127 -5
- data/lib/quinoa/version.rb +1 -1
- data/quinoa.gemspec +8 -8
- data/spec/core_spec.rb +339 -0
- data/spec/report_spec.rb +126 -0
- data/spec/spec_helper.rb +2 -2
- metadata +47 -45
- data/spec/service_object_spec.rb +0 -310
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca78ca9a7145903febd11f41319a4ab5788c4d96
|
4
|
+
data.tar.gz: 9328cbc86f97b6b6c94ba0a3e998e92c498e05c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '081cb739b5a70aaa723fb3a6218823c4038d0ed8234784f22b96275f08fa299a524b0b590a21e8806ccfadd9eadce1ed03aa19663fff40d63d09597ba92fc843'
|
7
|
+
data.tar.gz: 65bd1981b810bec653c87f0b999ecc81f1ca3a7f193d14cd3bb5cc0bc4dc0003f12b87cb350a2e60f51b2826197cd5d6882d41661b21639f035fd107206696b4
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,80 +1,82 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
quinoa (0.0.
|
5
|
-
rest-client (~>
|
6
|
-
rspec (~> 3.
|
4
|
+
quinoa (0.0.11)
|
5
|
+
rest-client (~> 2.0.0)
|
6
|
+
rspec (~> 3.5.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
addressable (2.4.0)
|
12
12
|
builder (3.2.2)
|
13
|
-
codeclimate-test-reporter (0.
|
13
|
+
codeclimate-test-reporter (0.6.0)
|
14
14
|
simplecov (>= 0.7.1, < 1.0.0)
|
15
|
-
coderay (1.1.
|
15
|
+
coderay (1.1.1)
|
16
16
|
crack (0.4.3)
|
17
17
|
safe_yaml (~> 1.0.0)
|
18
|
-
cucumber (2.
|
18
|
+
cucumber (2.4.0)
|
19
19
|
builder (>= 2.1.2)
|
20
|
-
cucumber-core (~> 1.
|
20
|
+
cucumber-core (~> 1.5.0)
|
21
21
|
cucumber-wire (~> 0.0.1)
|
22
22
|
diff-lcs (>= 1.1.3)
|
23
|
-
gherkin (~>
|
23
|
+
gherkin (~> 4.0)
|
24
24
|
multi_json (>= 1.7.5, < 2.0)
|
25
25
|
multi_test (>= 0.1.2)
|
26
|
-
cucumber-core (1.
|
27
|
-
gherkin (~>
|
26
|
+
cucumber-core (1.5.0)
|
27
|
+
gherkin (~> 4.0)
|
28
28
|
cucumber-wire (0.0.1)
|
29
29
|
diff-lcs (1.2.5)
|
30
30
|
docile (1.1.5)
|
31
|
-
domain_name (0.5.
|
31
|
+
domain_name (0.5.20160826)
|
32
32
|
unf (>= 0.0.5, < 1.0.0)
|
33
|
-
gherkin (
|
34
|
-
hashdiff (0.
|
35
|
-
http-cookie (1.0.
|
33
|
+
gherkin (4.0.0)
|
34
|
+
hashdiff (0.3.0)
|
35
|
+
http-cookie (1.0.3)
|
36
36
|
domain_name (~> 0.5)
|
37
|
-
json (
|
37
|
+
json (2.0.2)
|
38
38
|
method_source (0.8.2)
|
39
|
-
mime-types (
|
40
|
-
|
39
|
+
mime-types (3.1)
|
40
|
+
mime-types-data (~> 3.2015)
|
41
|
+
mime-types-data (3.2016.0521)
|
42
|
+
multi_json (1.12.1)
|
41
43
|
multi_test (0.1.2)
|
42
44
|
netrc (0.11.0)
|
43
45
|
nyan-cat-formatter (0.11)
|
44
46
|
rspec (>= 2.99, >= 2.14.2, < 4)
|
45
|
-
pry (0.10.
|
47
|
+
pry (0.10.4)
|
46
48
|
coderay (~> 1.1.0)
|
47
49
|
method_source (~> 0.8.1)
|
48
50
|
slop (~> 3.4)
|
49
|
-
rake (
|
50
|
-
rest-client (
|
51
|
+
rake (11.3.0)
|
52
|
+
rest-client (2.0.0)
|
51
53
|
http-cookie (>= 1.0.2, < 2.0)
|
52
|
-
mime-types (>= 1.16, <
|
53
|
-
netrc (~> 0.
|
54
|
-
rspec (3.
|
55
|
-
rspec-core (~> 3.
|
56
|
-
rspec-expectations (~> 3.
|
57
|
-
rspec-mocks (~> 3.
|
58
|
-
rspec-core (3.4
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-expectations (3.
|
54
|
+
mime-types (>= 1.16, < 4.0)
|
55
|
+
netrc (~> 0.8)
|
56
|
+
rspec (3.5.0)
|
57
|
+
rspec-core (~> 3.5.0)
|
58
|
+
rspec-expectations (~> 3.5.0)
|
59
|
+
rspec-mocks (~> 3.5.0)
|
60
|
+
rspec-core (3.5.4)
|
61
|
+
rspec-support (~> 3.5.0)
|
62
|
+
rspec-expectations (3.5.0)
|
61
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-mocks (3.
|
64
|
+
rspec-support (~> 3.5.0)
|
65
|
+
rspec-mocks (3.5.0)
|
64
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.
|
66
|
-
rspec-support (3.
|
67
|
+
rspec-support (~> 3.5.0)
|
68
|
+
rspec-support (3.5.0)
|
67
69
|
safe_yaml (1.0.4)
|
68
|
-
simplecov (0.
|
70
|
+
simplecov (0.12.0)
|
69
71
|
docile (~> 1.1.0)
|
70
|
-
json (
|
72
|
+
json (>= 1.8, < 3)
|
71
73
|
simplecov-html (~> 0.10.0)
|
72
74
|
simplecov-html (0.10.0)
|
73
75
|
slop (3.6.0)
|
74
76
|
unf (0.1.4)
|
75
77
|
unf_ext
|
76
|
-
unf_ext (0.0.7.
|
77
|
-
webmock (1.
|
78
|
+
unf_ext (0.0.7.2)
|
79
|
+
webmock (2.1.0)
|
78
80
|
addressable (>= 2.3.6)
|
79
81
|
crack (>= 0.3.2)
|
80
82
|
hashdiff
|
@@ -83,14 +85,14 @@ PLATFORMS
|
|
83
85
|
ruby
|
84
86
|
|
85
87
|
DEPENDENCIES
|
86
|
-
codeclimate-test-reporter (~> 0.
|
87
|
-
cucumber (~> 2.
|
88
|
+
codeclimate-test-reporter (~> 0.6.0)
|
89
|
+
cucumber (~> 2.4.0)
|
88
90
|
nyan-cat-formatter (~> 0.11)
|
89
|
-
pry (~> 0.10.
|
91
|
+
pry (~> 0.10.4)
|
90
92
|
quinoa!
|
91
|
-
rake (~>
|
92
|
-
simplecov (~> 0.
|
93
|
-
webmock (~> 1.
|
93
|
+
rake (~> 11.3.0)
|
94
|
+
simplecov (~> 0.12.0)
|
95
|
+
webmock (~> 2.1.0)
|
94
96
|
|
95
97
|
BUNDLED WITH
|
96
|
-
1.
|
98
|
+
1.13.6
|
data/README.md
CHANGED
@@ -6,7 +6,6 @@ quinoa
|
|
6
6
|
[](https://codeclimate.com/github/camiloribeiro/quinoa)
|
7
7
|
[](https://gemnasium.com/camiloribeiro/quinoa)
|
8
8
|
[](https://codeclimate.com/github/camiloribeiro/quinoa/coverage)
|
9
|
-
[](https://coderwall.com/camiloribeiro)
|
10
9
|
|
11
10
|

|
12
11
|
|
@@ -37,11 +36,15 @@ To read the response it is as easy as setting the initial data:
|
|
37
36
|
result2.response_body
|
38
37
|
=> "{ "some":"body"}
|
39
38
|
|
39
|
+
To get a report back you can use the function report
|
40
|
+
|
41
|
+
test.report
|
42
|
+
|
40
43
|
|
41
44
|
LICENSE
|
42
45
|
=======
|
43
46
|
|
44
|
-
Copyright 2015 Camilo Ribeiro camilo@camiloribeiro.com
|
47
|
+
Copyright 2015 - 2016 Camilo Ribeiro camilo@camiloribeiro.com
|
45
48
|
|
46
49
|
This file is part of Quinoa.
|
47
50
|
|
data/changelog
CHANGED
data/lib/quinoa/service.rb
CHANGED
@@ -1,23 +1,45 @@
|
|
1
1
|
require "rest-client"
|
2
|
+
require "json"
|
3
|
+
require "benchmark"
|
4
|
+
require "rspec"
|
2
5
|
|
3
6
|
module Quinoa
|
4
7
|
class Service
|
5
8
|
|
6
|
-
attr_accessor :url, :content_type, :accept, :body, :response, :path, :authorization, :custom_headers
|
9
|
+
attr_accessor :url, :content_type, :accept, :body, :response, :path, :authorization, :custom_headers, :time, :expectations, :assertions
|
7
10
|
|
8
11
|
def initialize url
|
12
|
+
self.time = ""
|
9
13
|
self.path = ""
|
10
14
|
self.authorization = ""
|
11
15
|
self.custom_headers = {}
|
16
|
+
self.expectations = {}
|
17
|
+
self.assertions = {}
|
12
18
|
self.url = url
|
13
19
|
end
|
14
20
|
|
15
21
|
def post! url=nil
|
16
22
|
begin
|
17
23
|
if url == nil
|
18
|
-
|
24
|
+
get_time {
|
25
|
+
RestClient.post(
|
26
|
+
self.url + self.path,
|
27
|
+
self.body,
|
28
|
+
{:accept => self.accept,
|
29
|
+
:content_type => self.content_type,
|
30
|
+
:authorization => self.authorization}.merge!(self.custom_headers)
|
31
|
+
)
|
32
|
+
}
|
19
33
|
else
|
20
|
-
|
34
|
+
get_time {
|
35
|
+
RestClient.post(
|
36
|
+
url,
|
37
|
+
self.body,
|
38
|
+
{:accept => self.accept,
|
39
|
+
:content_type => self.content_type,
|
40
|
+
:authorization => self.authorization}.merge!(self.custom_headers)
|
41
|
+
)
|
42
|
+
}
|
21
43
|
end
|
22
44
|
rescue => e
|
23
45
|
self.response = e.response
|
@@ -27,9 +49,21 @@ module Quinoa
|
|
27
49
|
def get! url=nil
|
28
50
|
begin
|
29
51
|
if url == nil
|
30
|
-
|
52
|
+
get_time {
|
53
|
+
RestClient.get(
|
54
|
+
self.url + self.path,
|
55
|
+
{:accept => self.accept,
|
56
|
+
:authorization => self.authorization}.merge!(self.custom_headers)
|
57
|
+
)
|
58
|
+
}
|
31
59
|
else
|
32
|
-
|
60
|
+
get_time {
|
61
|
+
RestClient.get(
|
62
|
+
url,
|
63
|
+
{:accept => self.accept,
|
64
|
+
:authorization => self.authorization}.merge!(self.custom_headers)
|
65
|
+
)
|
66
|
+
}
|
33
67
|
end
|
34
68
|
rescue => e
|
35
69
|
self.response = e.response
|
@@ -64,5 +98,93 @@ module Quinoa
|
|
64
98
|
self.custom_headers.delete custom_header_name.to_sym
|
65
99
|
end
|
66
100
|
|
101
|
+
def report
|
102
|
+
JSON.pretty_generate(
|
103
|
+
{
|
104
|
+
:health => get_health(self.assertions.map{|a| a[1][:status]}),
|
105
|
+
:response => {
|
106
|
+
:status_code => self.response.code,
|
107
|
+
:response_body => self.response.body,
|
108
|
+
:response_time => self.time.real
|
109
|
+
},
|
110
|
+
:assertions => self.assertions
|
111
|
+
}
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
def check!
|
116
|
+
#TO DO: Handle case when response is nil
|
117
|
+
exit 0 if self.response.nil?
|
118
|
+
self.expectations.each do | expectation |
|
119
|
+
assertion_item = expectation[0]
|
120
|
+
expectation_map = Hash[*expectation][assertion_item]
|
121
|
+
|
122
|
+
self.assertions.merge! get_assertion_record(
|
123
|
+
assertion_item,
|
124
|
+
expectation_map[:value],
|
125
|
+
check_attribute?(
|
126
|
+
assertion_item,
|
127
|
+
expectation_map[:value],
|
128
|
+
expectation_map[:compare_using]),
|
129
|
+
expectation_map[:level])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_expected_status value
|
134
|
+
add_expectation "status_code", value, "eq", :fail
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_expected_body_string value
|
138
|
+
add_expectation "body", value, "contains"
|
139
|
+
end
|
140
|
+
|
141
|
+
def add_expected_max_response_time value
|
142
|
+
add_expectation "response_time", value, "under"
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
def add_expectation attribute, value, comparison = "eq", level = :warn
|
147
|
+
self.expectations.merge! attribute.to_sym => {:compare_using => comparison, :value => value, :level => level}
|
148
|
+
end
|
149
|
+
|
150
|
+
def check_attribute? attribute, expected_value, comparator
|
151
|
+
value = self.response.code if attribute == :status_code
|
152
|
+
value = self.response.body if attribute == :body
|
153
|
+
value = self.time.real if attribute == :response_time
|
154
|
+
|
155
|
+
return value == expected_value if (comparator == "eq")
|
156
|
+
return value.include? expected_value if (comparator == "contains")
|
157
|
+
return value < expected_value if (comparator == "under")
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_assertion_record assertion_item, expected_value, assertion_result, level
|
162
|
+
{
|
163
|
+
assertion_item => {
|
164
|
+
:status => get_status(assertion_result, level),
|
165
|
+
:expected_value => expected_value,
|
166
|
+
:assertion_result => assertion_result,
|
167
|
+
}
|
168
|
+
}
|
169
|
+
end
|
170
|
+
|
171
|
+
def get_status assertion_result, level
|
172
|
+
return level if !assertion_result
|
173
|
+
return :health
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_health all_health_status
|
177
|
+
return :fail if all_health_status.include? :fail
|
178
|
+
return :warn if all_health_status.include? :warn
|
179
|
+
return :health if all_health_status.include? :health
|
180
|
+
return "health"
|
181
|
+
end
|
182
|
+
|
183
|
+
def get_time
|
184
|
+
self.time = Benchmark.measure do
|
185
|
+
self.response = yield
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
67
189
|
end
|
68
190
|
end
|
data/lib/quinoa/version.rb
CHANGED
data/quinoa.gemspec
CHANGED
@@ -21,15 +21,15 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_development_dependency 'simplecov', '~> 0.
|
25
|
-
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.
|
26
|
-
s.add_development_dependency 'pry', '~> 0.10.
|
27
|
-
s.add_development_dependency 'rake', '~>
|
24
|
+
s.add_development_dependency 'simplecov', '~> 0.12.0'
|
25
|
+
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.6.0'
|
26
|
+
s.add_development_dependency 'pry', '~> 0.10.4'
|
27
|
+
s.add_development_dependency 'rake', '~> 11.3.0'
|
28
28
|
s.add_development_dependency 'nyan-cat-formatter', '~> 0.11'
|
29
|
-
s.add_development_dependency 'cucumber', '~> 2.
|
30
|
-
s.add_development_dependency 'webmock', '~> 1.
|
29
|
+
s.add_development_dependency 'cucumber', '~> 2.4.0'
|
30
|
+
s.add_development_dependency 'webmock', '~> 2.1.0'
|
31
31
|
|
32
|
-
s.add_dependency 'rest-client', '~>
|
33
|
-
s.add_dependency 'rspec', '~> 3.
|
32
|
+
s.add_dependency 'rest-client', '~> 2.0.0'
|
33
|
+
s.add_dependency 'rspec', '~> 3.5.0'
|
34
34
|
|
35
35
|
end
|
data/spec/core_spec.rb
ADDED
@@ -0,0 +1,339 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/quinoa/service.rb')
|
3
|
+
|
4
|
+
describe Quinoa do
|
5
|
+
describe "Service" do
|
6
|
+
describe "The service should have the basic items of a service under test" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@service = Quinoa::Service.new "http://www.camiloribeiro.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "Should instantiate" do
|
13
|
+
expect(@service.url).to eq "http://www.camiloribeiro.com"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Should have a authorizoation" do
|
17
|
+
expect(@service.content_type).to eq nil
|
18
|
+
|
19
|
+
@service.authorization = "token !#€%&/()="
|
20
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
21
|
+
end
|
22
|
+
|
23
|
+
it "Should have a Content-Type" do
|
24
|
+
expect(@service.content_type).to eq nil
|
25
|
+
|
26
|
+
@service.content_type = "application/json"
|
27
|
+
expect(@service.content_type).to eq "application/json"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "Should have a Accept" do
|
31
|
+
expect(@service.accept).to eq nil
|
32
|
+
|
33
|
+
@service.accept = "application/xml;q=0.9,*/*;q=0.8."
|
34
|
+
expect(@service.accept).to eq "application/xml;q=0.9,*/*;q=0.8."
|
35
|
+
end
|
36
|
+
|
37
|
+
it "Should have a body" do
|
38
|
+
expect(@service.body).to eq nil
|
39
|
+
|
40
|
+
@service.body = "text"
|
41
|
+
expect(@service.body).to eq "text"
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "expectations" do
|
45
|
+
describe "configuration" do
|
46
|
+
|
47
|
+
it "Should be able to add expected response code" do
|
48
|
+
expect(@service.expectations).to eq Hash[]
|
49
|
+
|
50
|
+
@service.add_expected_status 200
|
51
|
+
expect(@service.expectations).to eq Hash[:status_code => {:compare_using=>"eq", :value=>200, :level=>:fail}]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "Should be able to add expected body contains" do
|
55
|
+
expect(@service.expectations).to eq Hash[]
|
56
|
+
|
57
|
+
@service.add_expected_body_string "works"
|
58
|
+
expect(@service.expectations).to eq Hash[:body => {:compare_using=>"contains", :value=>"works", :level=>:warn}]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "Should be able to add expected response time under" do
|
62
|
+
expect(@service.expectations).to eq Hash[]
|
63
|
+
|
64
|
+
@service.add_expected_max_response_time 1
|
65
|
+
expect(@service.expectations).to eq Hash[:response_time => {:compare_using=>"under", :value=>1, :level=>:warn}]
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "Custom headers" do
|
71
|
+
|
72
|
+
it "Should be able to add a single custom header" do
|
73
|
+
|
74
|
+
expect(@service.custom_headers).to eq Hash[]
|
75
|
+
|
76
|
+
@service.add_custom_header "my-company-custom-header", "text"
|
77
|
+
expect(@service.custom_headers).to eq Hash[:"my-company-custom-header" => "text"]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "Should be able to add many custom headers" do
|
81
|
+
expect(@service.custom_headers).to eq Hash[]
|
82
|
+
|
83
|
+
@service.add_custom_header "my-company-custom-header", "text"
|
84
|
+
@service.add_custom_header "headerx", "bar"
|
85
|
+
@service.add_custom_header :"my-foo-custom-header", "foo"
|
86
|
+
|
87
|
+
expect(@service.custom_headers).to eq Hash[:"my-company-custom-header" => "text", :headerx => "bar", :"my-foo-custom-header" => "foo"]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "Should be able to remove one among many custom headers" do
|
91
|
+
expect(@service.custom_headers).to eq Hash[]
|
92
|
+
|
93
|
+
@service.add_custom_header "my-company-custom-header", "text"
|
94
|
+
@service.add_custom_header "headerx", "bar"
|
95
|
+
@service.add_custom_header :"my-foo-custom-header", "foo"
|
96
|
+
|
97
|
+
expect(@service.custom_headers).to eq Hash[:"my-company-custom-header" => "text", :headerx => "bar", :"my-foo-custom-header" => "foo"]
|
98
|
+
|
99
|
+
@service.remove_custom_header "headerx"
|
100
|
+
|
101
|
+
expect(@service.custom_headers).to eq Hash[:"my-company-custom-header" => "text", :"my-foo-custom-header" => "foo"]
|
102
|
+
end
|
103
|
+
|
104
|
+
["post", "get"].each do |method|
|
105
|
+
it "Should be present in the #{method} requests" do
|
106
|
+
# For this mock order matters
|
107
|
+
stub_request(:any, "http://www.camiloribeiro.com").
|
108
|
+
to_return(:status => 200, :body => "This request requires a 'my-company-custom-header' to work")
|
109
|
+
|
110
|
+
stub_request(:any, "http://www.camiloribeiro.com").
|
111
|
+
with(:headers => { 'my-company-custom-header' => "text" }).
|
112
|
+
to_return(:status => 200, :body => "This request works fine")
|
113
|
+
|
114
|
+
@other_service = Quinoa::Service.new "http://www.camiloribeiro.com"
|
115
|
+
|
116
|
+
expect(@service.custom_headers).to eq Hash[]
|
117
|
+
expect(@other_service.custom_headers).to eq Hash[]
|
118
|
+
|
119
|
+
@service.add_custom_header "my-company-custom-header", "text"
|
120
|
+
@service.add_custom_header "headerx", "bar"
|
121
|
+
@service.add_custom_header :"my-foo-custom-header", "foo"
|
122
|
+
|
123
|
+
expect(@service.custom_headers).to eq Hash[:"my-company-custom-header" => "text", :headerx => "bar", :"my-foo-custom-header" => "foo"]
|
124
|
+
expect(@other_service.custom_headers).to eq Hash[]
|
125
|
+
|
126
|
+
@service.send "#{method}!"
|
127
|
+
@other_service.send "#{method}!"
|
128
|
+
|
129
|
+
expect(@service.response.body).to eq("This request works fine")
|
130
|
+
expect(@other_service.response.body).to eq("This request requires a 'my-company-custom-header' to work")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "overwiting the entire url to post and get" do
|
137
|
+
|
138
|
+
before(:each) do
|
139
|
+
stub_request(:any, "http://www.bugbang.com.br/foo").
|
140
|
+
to_return(:status => 200, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json"})
|
141
|
+
|
142
|
+
@service = Quinoa::Service.new "http://www.camiloribeiro.com"
|
143
|
+
@service.path = "/something"
|
144
|
+
@service.content_type = "application/json"
|
145
|
+
@service.authorization = "token !#€%&/()="
|
146
|
+
@service.body = "simple body"
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should overwite for get" do
|
151
|
+
@service.get! "http://www.bugbang.com.br/foo"
|
152
|
+
|
153
|
+
# explicity
|
154
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
155
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
156
|
+
expect(@service.response.body).to eq("simple response")
|
157
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
158
|
+
expect(@service.response.code).to eq(200)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should overwite for post" do
|
162
|
+
@service.post! "http://www.bugbang.com.br/foo"
|
163
|
+
|
164
|
+
# explicity
|
165
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
166
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
167
|
+
expect(@service.response.body).to eq("simple response")
|
168
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
169
|
+
expect(@service.response.code).to eq(200)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
describe "defining a different paths" do
|
175
|
+
|
176
|
+
["/", "/path"].each do |path|
|
177
|
+
describe "should work for the path #{path}" do
|
178
|
+
|
179
|
+
before(:each) do
|
180
|
+
stub_request(:any, "http://www.camiloribeiro.com#{path}").
|
181
|
+
to_return(:status => 200, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json"})
|
182
|
+
|
183
|
+
@service = Quinoa::Service.new "http://www.camiloribeiro.com"
|
184
|
+
@service.path = path
|
185
|
+
@service.content_type = "application/json"
|
186
|
+
@service.authorization = "token !#€%&/()="
|
187
|
+
@service.body = "simple body"
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should post" do
|
192
|
+
@service.post!
|
193
|
+
|
194
|
+
# explicity
|
195
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
196
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
197
|
+
expect(@service.response.body).to eq("simple response")
|
198
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
199
|
+
expect(@service.response.code).to eq(200)
|
200
|
+
|
201
|
+
# natural
|
202
|
+
expect(@service.response_accept).to eq("application/xml")
|
203
|
+
expect(@service.response_content_type).to eq("application/json")
|
204
|
+
expect(@service.response_body).to eq("simple response")
|
205
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
206
|
+
expect(@service.response_code).to eq(200)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should get" do
|
210
|
+
@service.get!
|
211
|
+
|
212
|
+
# explicity
|
213
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
214
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
215
|
+
expect(@service.response.body).to eq("simple response")
|
216
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
217
|
+
expect(@service.response.code).to eq(200)
|
218
|
+
|
219
|
+
# natural
|
220
|
+
expect(@service.response_accept).to eq("application/xml")
|
221
|
+
expect(@service.response_content_type).to eq("application/json")
|
222
|
+
expect(@service.response_body).to eq("simple response")
|
223
|
+
expect(@service.authorization).to eq "token !#€%&/()="
|
224
|
+
expect(@service.response_code).to eq(200)
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
describe "the service should have the basic behaviours of a service" do
|
234
|
+
|
235
|
+
# 303 post and get, 301 get, 302 get and 307 get failing
|
236
|
+
[100,101,102,200,201,202,203,204,205,206,207,208,226,300,304,305,306,308,308,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,420,421,422,423,424,426,428,429,431,440,444,449,450,451,451,494,495,496,497,498,499,499,500,501,502,503,504,505,506,507,508,509,510,511,520,522,598,599].each do |code|
|
237
|
+
describe "when returning code #{code}" do
|
238
|
+
before(:each) do
|
239
|
+
stub_request(:any, "http://www.camiloribeiro.com/").
|
240
|
+
to_return(:status => code, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json"})
|
241
|
+
|
242
|
+
@service = Quinoa::Service.new "http://www.camiloribeiro.com"
|
243
|
+
@service.content_type = "application/json"
|
244
|
+
@service.body = "simple body"
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should post" do
|
249
|
+
@service.post!
|
250
|
+
|
251
|
+
# explicity
|
252
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
253
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
254
|
+
expect(@service.response.body).to eq("simple response")
|
255
|
+
expect(@service.response.code).to eq(code)
|
256
|
+
|
257
|
+
# natural
|
258
|
+
expect(@service.response_accept).to eq("application/xml")
|
259
|
+
expect(@service.response_content_type).to eq("application/json")
|
260
|
+
expect(@service.response_body).to eq("simple response")
|
261
|
+
expect(@service.response_code).to eq(code)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should get" do
|
265
|
+
@service.get!
|
266
|
+
|
267
|
+
# explicity
|
268
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
269
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
270
|
+
expect(@service.response.body).to eq("simple response")
|
271
|
+
expect(@service.response.code).to eq(code)
|
272
|
+
|
273
|
+
# natural
|
274
|
+
expect(@service.response_accept).to eq("application/xml")
|
275
|
+
expect(@service.response_content_type).to eq("application/json")
|
276
|
+
expect(@service.response_body).to eq("simple response")
|
277
|
+
expect(@service.response_code).to eq(code)
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# 303 post and get, 301 get, 302 get and 307 get failing
|
284
|
+
[301,302,307].each do |code|
|
285
|
+
describe "when returning code #{code}" do
|
286
|
+
before(:each) do
|
287
|
+
stub_request(:any, "http://www.camiloribeiro.com/").
|
288
|
+
to_return(:status => code, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json", :location => "http://www.bugbang.com.br"})
|
289
|
+
|
290
|
+
stub_request(:any, "http://www.bugbang.com.br/").
|
291
|
+
to_return(:status => 200, :body => "followed redirect", :headers => {:accept=>"application/xml", :content_type => "application/json"})
|
292
|
+
|
293
|
+
@service = Quinoa::Service.new "http://www.camiloribeiro.com"
|
294
|
+
@service.content_type = "application/json"
|
295
|
+
@service.body = "simple body"
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should post" do
|
300
|
+
@service.post!
|
301
|
+
|
302
|
+
# explicity
|
303
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
304
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
305
|
+
expect(@service.response.body).to eq("simple response")
|
306
|
+
expect(@service.response.headers[:location]).to eq("http://www.bugbang.com.br")
|
307
|
+
expect(@service.response.code).to eq(code)
|
308
|
+
|
309
|
+
# natural
|
310
|
+
expect(@service.response_accept).to eq("application/xml")
|
311
|
+
expect(@service.response_content_type).to eq("application/json")
|
312
|
+
expect(@service.response_body).to eq("simple response")
|
313
|
+
expect(@service.response_location).to eq("http://www.bugbang.com.br")
|
314
|
+
expect(@service.response_code).to eq(code)
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should get" do
|
318
|
+
|
319
|
+
@service.get!
|
320
|
+
|
321
|
+
# explicity
|
322
|
+
expect(@service.response.headers[:accept]).to eq("application/xml")
|
323
|
+
expect(@service.response.headers[:content_type]).to eq("application/json")
|
324
|
+
expect(@service.response.body).to eq("followed redirect")
|
325
|
+
expect(@service.response.code).to eq(200)
|
326
|
+
|
327
|
+
# natural
|
328
|
+
expect(@service.response_accept).to eq("application/xml")
|
329
|
+
expect(@service.response_content_type).to eq("application/json")
|
330
|
+
expect(@service.response_body).to eq("followed redirect")
|
331
|
+
expect(@service.response_code).to eq(200)
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|