dock_test 0.4.5 → 0.4.6
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/lib/dock_test/methods.rb +44 -32
- data/lib/dock_test/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: d7d02f2bd497b1164ea2681c4d3e511d80ba5d4e
|
4
|
+
data.tar.gz: 76b280e326bb795ac5a5346bff4cfa4d8e929221
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f38ac82284f77aeeaf6f36c57d789d0bf4dcfac4664adbcbe37727ec8520628dc92901ac52feab7f50d16fd5e274a59d34e75c85c3c4ce360e947013eb50f27e
|
7
|
+
data.tar.gz: 0f48db876fea3d8b463ecc3b019cdc89c89ae4ddf4aaf32b0c389cfec13a18252acca600e4580e14cda53bdaa14968cb04c3ddaeabbe62e29f8321529334c334
|
data/lib/dock_test/methods.rb
CHANGED
@@ -6,43 +6,27 @@ module DockTest
|
|
6
6
|
%w(get post put patch delete options head).each do |meth_name|
|
7
7
|
define_method meth_name do |path, params = '', headers = {}, &block|
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
if with_side_effects && DockTest.skippy?
|
9
|
+
if verb_has_side_effects?(meth_name) && DockTest.skippy?
|
12
10
|
skip_test_to_avoid_side_efforts
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
|
-
uri = URI.parse(request_url)
|
13
|
+
construct_request(meth_name, path, params, headers)
|
17
14
|
|
18
|
-
|
19
|
-
uri.port = DockTest.port
|
20
|
-
end
|
15
|
+
execute_request
|
21
16
|
|
22
|
-
|
23
|
-
if !with_side_effects && !params.empty?
|
24
|
-
if(params.is_a?(Hash))
|
25
|
-
uri.query = URI.encode_www_form(URI.decode_www_form(uri.query || '') + params.to_a)
|
26
|
-
else
|
27
|
-
uri.query = uri.query.nil? ? params : "#{uri.query}&#{params}"
|
28
|
-
end
|
29
|
-
end
|
17
|
+
yield @last_response if block_given?
|
30
18
|
|
31
|
-
@
|
19
|
+
@last_response
|
20
|
+
end
|
32
21
|
|
33
|
-
|
34
|
-
if with_side_effects
|
35
|
-
@last_request.body = params
|
36
|
-
end
|
22
|
+
end
|
37
23
|
|
38
|
-
|
39
|
-
headers.each do |key, value|
|
40
|
-
@last_request[key] = value
|
41
|
-
end
|
24
|
+
private
|
42
25
|
|
26
|
+
def execute_request
|
43
27
|
# execute the request
|
44
|
-
@last_response = Net::HTTP.start(uri.hostname, uri.port,
|
45
|
-
:use_ssl => (uri.scheme == 'https'),
|
28
|
+
@last_response = Net::HTTP.start(@uri.hostname, @uri.port,
|
29
|
+
:use_ssl => (@uri.scheme == 'https'),
|
46
30
|
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
47
31
|
# processing oauth signing
|
48
32
|
if DockTest.oauth?
|
@@ -61,16 +45,44 @@ module DockTest
|
|
61
45
|
|
62
46
|
http.request(@last_request)
|
63
47
|
end
|
48
|
+
end
|
64
49
|
|
65
|
-
|
50
|
+
def construct_request(meth_name, path, params, headers)
|
66
51
|
|
67
|
-
|
52
|
+
construct_uri(meth_name, path, params)
|
53
|
+
|
54
|
+
@last_request = Net::HTTP.const_get(meth_name.capitalize).new(@uri.request_uri).tap do |req|
|
55
|
+
|
56
|
+
# add the params to the body of other requests
|
57
|
+
if verb_has_side_effects?(meth_name)
|
58
|
+
req.body = params
|
59
|
+
end
|
60
|
+
|
61
|
+
# sets the headers
|
62
|
+
headers.each do |key, value|
|
63
|
+
req[key] = value
|
64
|
+
end
|
65
|
+
end
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
68
|
+
def construct_uri(meth_name, path, params)
|
69
|
+
request_url = full_url(DockTest.url, path)
|
70
|
+
@uri = URI.parse(request_url).tap do |uri|
|
72
71
|
|
73
|
-
|
72
|
+
if DockTest.localhost?
|
73
|
+
uri.port = DockTest.port
|
74
|
+
end
|
75
|
+
|
76
|
+
# add the params to the GET requests
|
77
|
+
if !verb_has_side_effects?(meth_name) && !params.empty?
|
78
|
+
if(params.is_a?(Hash))
|
79
|
+
uri.query = URI.encode_www_form(URI.decode_www_form(uri.query || '') + params.to_a)
|
80
|
+
else
|
81
|
+
uri.query = uri.query.nil? ? params : "#{uri.query}&#{params}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
74
86
|
|
75
87
|
def verb_has_side_effects?(verb)
|
76
88
|
%w(post put patch delete).include?(verb)
|
data/lib/dock_test/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dock_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Xu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|