mocktopus 0.0.6 → 0.0.7

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: 28b6c35e654e4773073f3a03584ad7900a76691c
4
- data.tar.gz: 05f9a56facd7cf28fa56191fcfd5e37da981e4fe
3
+ metadata.gz: a375cef90270d421fba8b9027f691f714895ff66
4
+ data.tar.gz: bb9b5e7bb8e238a3a348b253c382d911bde8d0ec
5
5
  SHA512:
6
- metadata.gz: ef1be1d2e1c03956a55ccf084c943e637c64507e37c57020e0330ee95aa083382ec8981443d1f188b77d676657cd556a693b28e8a8011fed769cb19cb9142f50
7
- data.tar.gz: 1a5de7dbc5ca4a8973ecacdb2a9b66e9f1edd840db3a0e1972a88c7628a534c7690c428390b77d11aca6671249dff5a978224cf3c31d118c02e25d3782197562
6
+ metadata.gz: 25ff3a4a335a101184ae096fc884dc9f4f46bc7e28470f3db5ff7e2a5ef8d91feb1f3cc636a28e6db7254511b31e0da7b4ea88613e5d09e116bea1b11027f5b2
7
+ data.tar.gz: ba54b6aa842d651abc8544e19c24c3d8bce9696d08aa8d8a3a8856ff69f39d13d71a97fa11ce6bc946cc3751748aeb6b4b4e3b16db7b38a9637797251f92ddf5
data/config.ru CHANGED
@@ -1,3 +1,20 @@
1
1
  require 'mocktopus'
2
2
 
3
+ class LoggerMiddleware
4
+
5
+ def initialize(app, logger)
6
+ @app, @logger = app, logger
7
+ end
8
+
9
+ def call(env)
10
+ env['rack.errors'] = @logger
11
+ @app.call(env)
12
+ end
13
+
14
+ end
15
+
16
+ use Rack::CommonLogger, $logger
17
+ use LoggerMiddleware, $logger
18
+ set :show_exceptions, false
19
+
3
20
  run Sinatra::Application
data/lib/mocktopus.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'logger'
2
- LOGGER = Logger.new('mocktopus.log', 'daily')
2
+
3
+ $logger = Logger.new(STDOUT) unless $logger
4
+
5
+ class ::Logger; alias_method :write, :info; end
6
+ class ::Logger; alias_method :puts, :error; end
3
7
 
4
8
  require 'mocktopus/response'
5
9
  require 'mocktopus/input'
data/lib/mocktopus/app.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'sinatra'
2
1
  require_relative '../../ascii.rb'
3
2
 
4
- LOGGER.info 'initialized mocktopus app'
3
+ require 'sinatra'
4
+
5
+ $logger.info 'initialized mocktopus app'
5
6
  $input_container = Mocktopus::InputContainer.new
6
7
  $mock_api_call_container = Mocktopus::MockApiCallContainer.new
7
8
 
@@ -24,7 +25,7 @@ error_example = {
24
25
  }
25
26
 
26
27
  post '/mocktopus/inputs/:name' do
27
- LOGGER.info("received new input named #{params[:name]}")
28
+ $logger.info("received new input named #{params[:name]}")
28
29
  begin
29
30
  body = JSON.parse(request.body.read().to_s)
30
31
  rescue
@@ -34,22 +35,22 @@ post '/mocktopus/inputs/:name' do
34
35
  body error_hash.to_json
35
36
  return
36
37
  end
37
- LOGGER.debug("body: #{body.inspect()}")
38
+ $logger.debug("body: #{body.inspect()}")
38
39
 
39
- LOGGER.debug("creating response object from #{body['response']}")
40
+ $logger.debug("creating response object from #{body['response']}")
40
41
  response = Mocktopus::Response.new(body['response'])
41
42
 
42
- LOGGER.debug("creating input object from #{body.inspect}, #{response.inspect}")
43
+ $logger.debug("creating input object from #{body.inspect}, #{response.inspect}")
43
44
  input = Mocktopus::Input.new(body, response)
44
45
 
45
- LOGGER.info("added input #{params[:name]} successfully")
46
+ $logger.info("added input #{params[:name]} successfully")
46
47
  $input_container.add(params[:name], input)
47
48
  end
48
49
 
49
50
  get '/mocktopus/inputs' do
50
- LOGGER.info("all inputs requested")
51
+ $logger.info("all inputs requested")
51
52
  all_inputs = $input_container.all()
52
- LOGGER.debug("found #{all_inputs.size()} inputs")
53
+ $logger.debug("found #{all_inputs.size()} inputs")
53
54
  return_inputs = {}
54
55
  all_inputs.each do |k,v|
55
56
  return_inputs[k] = v.to_hash
@@ -59,7 +60,7 @@ get '/mocktopus/inputs' do
59
60
  end
60
61
 
61
62
  get '/mocktopus/inputs/:name' do
62
- LOGGER.info("retrieving input by name #{params[:name]}")
63
+ $logger.info("retrieving input by name #{params[:name]}")
63
64
  input = $input_container.get_by(params[:name])
64
65
  if (input != nil)
65
66
  input.to_hash.to_json
@@ -81,12 +82,12 @@ delete '/mocktopus/mock_api_calls' do
81
82
  end
82
83
 
83
84
  delete '/mocktopus/inputs' do
84
- LOGGER.info("deleting all inputs")
85
+ $logger.info("deleting all inputs")
85
86
  $input_container.delete_all()
86
87
  end
87
88
 
88
89
  delete '/mocktopus/inputs/:name' do
89
- LOGGER.info("deleting input by name #{params[:name]}")
90
+ $logger.info("deleting input by name #{params[:name]}")
90
91
  $input_container.delete_by(params[:name])
91
92
  end
92
93
 
@@ -112,13 +113,13 @@ not_found do
112
113
 
113
114
  $mock_api_call_container.add(Mocktopus::MockApiCall.new(log_path, verb, request_headers, body))
114
115
 
115
- LOGGER.info("not_found catch all invoked")
116
+ $logger.info("not_found catch all invoked")
116
117
  start_time = Time.now.to_f
117
- LOGGER.debug("looking for a match with path #{request.fullpath}, verb #{verb}, headers #{request_headers}, body #{body}")
118
+ $logger.debug("looking for a match with path #{request.fullpath}, verb #{verb}, headers #{request_headers}, body #{body}")
118
119
  match = $input_container.match(path, verb, request_headers, body, request.env['rack.request.query_hash'])
119
- LOGGER.debug("match lookup complete")
120
+ $logger.debug("match lookup complete")
120
121
  if (match.nil?)
121
- LOGGER.info("match not found. sending 428")
122
+ $logger.info("match not found. sending 428")
122
123
  status 428
123
124
  content_type :json
124
125
  body_detail = {
@@ -132,12 +133,12 @@ not_found do
132
133
  }
133
134
  body body_detail.to_json
134
135
  else
135
- LOGGER.info("match found #{match.inspect}")
136
+ $logger.info("match found #{match.inspect}")
136
137
  sleep(match.response.delay/1000)
137
138
  status match.response.code
138
139
  headers match.response.headers
139
140
  body match.response.body
140
141
  end
141
142
  end_time = Time.now.to_f
142
- LOGGER.info("not_found catch all completed in #{((end_time - start_time) * 1000)} milliseconds")
143
+ $logger.info("not_found catch all completed in #{((end_time - start_time) * 1000)} milliseconds")
143
144
  end
@@ -49,7 +49,7 @@ module Mocktopus
49
49
 
50
50
  validate_instance_variables
51
51
 
52
- LOGGER.debug("initialized input object from hash #{hash.inspect()}")
52
+ $logger.debug("initialized input object from hash #{hash.inspect()}")
53
53
  end
54
54
 
55
55
  def to_hash
@@ -16,7 +16,7 @@ module Mocktopus
16
16
  :delay
17
17
 
18
18
  def initialize(hash)
19
- LOGGER.debug("initializing response object")
19
+ $logger.debug("initializing response object")
20
20
  @code = hash['code']
21
21
  @headers = hash['headers']
22
22
  @body = hash['body']
@@ -30,7 +30,7 @@ module Mocktopus
30
30
 
31
31
  validate_instance_variables()
32
32
 
33
- LOGGER.debug("initialized response object from hash #{hash.inspect()}")
33
+ $logger.debug("initialized response object from hash #{hash.inspect()}")
34
34
  end
35
35
 
36
36
  def to_hash
data/mocktopus.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mocktopus'
5
- s.version = '0.0.6'
5
+ s.version = '0.0.7'
6
6
  s.date = '2015-03-14'
7
7
  s.required_ruby_version = '>= 1.9.3'
8
8
 
@@ -27,4 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency 'mocha', '~> 0.14.0', '>= 0.14.0'
28
28
  s.add_development_dependency 'simplecov', '~> 0.9.2', '>= 0.9.2'
29
29
  s.add_development_dependency 'coveralls', '~> 0.7.11', '>= 0.7.11'
30
+ s.add_development_dependency 'pry', '~> 0.10.1', '>= 0.10.1'
30
31
  end
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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rackspace
@@ -230,6 +230,26 @@ dependencies:
230
230
  - - ">="
231
231
  - !ruby/object:Gem::Version
232
232
  version: 0.7.11
233
+ - !ruby/object:Gem::Dependency
234
+ name: pry
235
+ requirement: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: 0.10.1
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: 0.10.1
243
+ type: :development
244
+ prerelease: false
245
+ version_requirements: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: 0.10.1
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: 0.10.1
233
253
  description: The Mocktopus is a Sinatra/thin-based Web API that lets you mock your
234
254
  app dependencies
235
255
  email: