mocktopus 0.1.4 → 0.1.5
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/mocktopus/app.rb +6 -4
- data/lib/mocktopus/mock_api_call.rb +5 -2
- data/lib/mocktopus/mock_api_call_container.rb +11 -3
- data/mocktopus.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2538ccba33bc022b6bb97c0bcc9d0a5aaa7343fd
|
4
|
+
data.tar.gz: f47ff6cc2f02249b8d2e010891c7f9c4b045e18e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf7d6de4111c646ed0e9433e53ea9832f145f03da04d180037e93e49b23144ddeeccada857307702ec41210b00a151551e3bbee25b8e2e2c9ee24d0c4149af9
|
7
|
+
data.tar.gz: 0ca35ee0234986529942bf7412a203500c567ceb6b0445675473df551ba35047191fb85dba04ec7c4f08632a4365087b308eac16d337bc0fd844f26273d22f09
|
data/lib/mocktopus/app.rb
CHANGED
@@ -73,7 +73,7 @@ end
|
|
73
73
|
get '/mocktopus/mock_api_calls' do
|
74
74
|
content_type :json
|
75
75
|
status 200
|
76
|
-
body $mock_api_call_container.all.to_json
|
76
|
+
body $mock_api_call_container.all(params[:unmatched] || false).to_json
|
77
77
|
end
|
78
78
|
|
79
79
|
delete '/mocktopus/mock_api_calls' do
|
@@ -107,11 +107,12 @@ not_found do
|
|
107
107
|
log_path += k
|
108
108
|
log_path += '='
|
109
109
|
log_path += request.env['rack.request.query_hash'][k].to_s
|
110
|
-
log_path += '&' unless k == request.env['rack.request.query_hash'].keys.last
|
110
|
+
log_path += '&' unless k == request.env['rack.request.query_hash'].keys.last
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
|
114
|
+
call = Mocktopus::MockApiCall.new(log_path, verb, request_headers, body)
|
115
|
+
$mock_api_call_container.add(call)
|
115
116
|
|
116
117
|
$logger.info("not_found catch all invoked")
|
117
118
|
start_time = Time.now.to_f
|
@@ -122,7 +123,7 @@ not_found do
|
|
122
123
|
$logger.info("match not found. sending 428")
|
123
124
|
status 428
|
124
125
|
content_type :json
|
125
|
-
body_detail = {
|
126
|
+
body_detail = {
|
126
127
|
'message' => 'match not found',
|
127
128
|
'call' => {
|
128
129
|
'path' => request.fullpath,
|
@@ -133,6 +134,7 @@ not_found do
|
|
133
134
|
}
|
134
135
|
body body_detail.to_json
|
135
136
|
else
|
137
|
+
call.matched = true
|
136
138
|
$logger.info("match found #{match.inspect}")
|
137
139
|
sleep(match.response.delay/1000)
|
138
140
|
status match.response.code
|
@@ -10,13 +10,15 @@ module Mocktopus
|
|
10
10
|
:path,
|
11
11
|
:verb,
|
12
12
|
:headers,
|
13
|
-
:body
|
13
|
+
:body,
|
14
|
+
:matched
|
14
15
|
|
15
16
|
def initialize(path, verb, headers, body)
|
16
17
|
@timestamp = Time.now.utc.iso8601(10)
|
17
18
|
@path = path
|
18
19
|
@verb = verb
|
19
20
|
@headers = headers
|
21
|
+
@matched = false
|
20
22
|
begin
|
21
23
|
@body = if @headers.has_key?('content_type') && @headers['content_type'] == 'application/x-www-form-urlencoded'
|
22
24
|
URI::decode_www_form_component(body).to_s
|
@@ -34,7 +36,8 @@ module Mocktopus
|
|
34
36
|
'path' => @path,
|
35
37
|
'verb' => @verb,
|
36
38
|
'headers' => @headers,
|
37
|
-
'body' => @body
|
39
|
+
'body' => @body,
|
40
|
+
'matched' => @matched
|
38
41
|
}
|
39
42
|
end
|
40
43
|
|
@@ -9,12 +9,20 @@ module Mocktopus
|
|
9
9
|
@calls << mock_api_call
|
10
10
|
end
|
11
11
|
|
12
|
-
def all
|
13
|
-
@calls.collect
|
12
|
+
def all(unmatched_only=false)
|
13
|
+
@calls.collect { |c|
|
14
|
+
if (unmatched_only && c.matched) then
|
15
|
+
nil
|
16
|
+
else
|
17
|
+
result = c.to_hash
|
18
|
+
result.delete('matched')
|
19
|
+
result
|
20
|
+
end
|
21
|
+
}.compact
|
14
22
|
end
|
15
23
|
|
16
24
|
def delete_all
|
17
25
|
@calls = []
|
18
26
|
end
|
19
27
|
end
|
20
|
-
end
|
28
|
+
end
|
data/mocktopus.gemspec
CHANGED