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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30da376cf32eddf2ecc30c0b164f99f6bef93963
4
- data.tar.gz: ade277507f628f20b1f44a8c4e7f7721d6af9d0d
3
+ metadata.gz: 2538ccba33bc022b6bb97c0bcc9d0a5aaa7343fd
4
+ data.tar.gz: f47ff6cc2f02249b8d2e010891c7f9c4b045e18e
5
5
  SHA512:
6
- metadata.gz: a514f931b968ea6162bf50c6327ca16d1b67e889e2136d71a16412e0838f39e4fe70db3a632e82b41c26ac8c87c7e407d11152116def8b5a21e160acd5972ab8
7
- data.tar.gz: e80e9da782506e982e900a4ea759ab33075167fb7632ef4935b14819471046657cd417ab9a1def4730966f2c883aa008c8a84f901c69b0ce63da1de970025ea0
6
+ metadata.gz: 3cf7d6de4111c646ed0e9433e53ea9832f145f03da04d180037e93e49b23144ddeeccada857307702ec41210b00a151551e3bbee25b8e2e2c9ee24d0c4149af9
7
+ data.tar.gz: 0ca35ee0234986529942bf7412a203500c567ceb6b0445675473df551ba35047191fb85dba04ec7c4f08632a4365087b308eac16d337bc0fd844f26273d22f09
@@ -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
- $mock_api_call_container.add(Mocktopus::MockApiCall.new(log_path, verb, request_headers, body))
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(&:to_hash)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mocktopus'
5
- s.version = '0.1.4'
5
+ s.version = '0.1.5'
6
6
  s.date = '2017-04-14'
7
7
  s.required_ruby_version = '>= 2.0.0'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocktopus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rackspace