optimus_prime 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f522b0e37c978683f8a7014b740295db07b42495
4
- data.tar.gz: 0ca45620a218ec54f55806d302c37ccce1fe5ddc
3
+ metadata.gz: 63bf3354440bf026485806d80f3872d0ef821db6
4
+ data.tar.gz: 517612f79a22d402cf1e1770b008a9bf26c6213e
5
5
  SHA512:
6
- metadata.gz: 75351fd22cfc8c54c06001fa6439603a2198385e7e78cc7b453bee0003d82fadaec558b90455ca7cfdf1d65f2d4beec8bddd0409c5abc785ec307a5dafc42b3e
7
- data.tar.gz: 803d7ffd117cd262e294ab4e3dea32cb54559309c79cfac33944110bbf561bc2b8b159874e2615ba60423d32b108c84433021353a63ddf41b11ce60e582280fe
6
+ metadata.gz: 27e8950c4931551143da168fdbbb8effff0feabaa07450f893c5812fbe96b37a3abc4893f5c9e8469e9324f9f8aa07ef48d976f8decea1b8743967dabae1c8f2
7
+ data.tar.gz: 53a8705d11c92f5814f6c9910a0f0cd2da4d3778159569a9853fc28052a095a94df51ba714c6e680603dac6a73d2bd469569ae53d93a467d641b283c116418a0
data/README.md CHANGED
@@ -37,6 +37,20 @@ op = OptimusPrime::Base.new
37
37
  op.prime("path_name", response, options)
38
38
  ```
39
39
 
40
+ ## GET requests:
41
+ ```ruby
42
+ op.prime("users", " response... ", status_code: 200)
43
+ response = Faraday.get("http://localhost:7002/get/users")
44
+ response.body #=> " response... "
45
+ ```
46
+
47
+ ## POST requests:
48
+ ```ruby
49
+ op.prime("users", " response... ", status_code: 201)
50
+ response = Faraday.post("http://localhost:7002/get/users", { some data })
51
+ response.status #=> 201 - Created
52
+ ```
53
+
40
54
  ## Changing Content Type:
41
55
  ```ruby
42
56
  op.prime("users", { users json... }, { content_type: :json })
@@ -51,13 +65,22 @@ response = Faraday.get("http://localhost:7002/get/users")
51
65
  response.status #=> 404
52
66
  ```
53
67
 
54
- ## POST requests:
68
+ ## Assert on a POST request body
55
69
  ```ruby
56
- op.prime("users", " response... ", status_code: 201)
57
- response = Faraday.post("http://localhost:7002/get/users", { some data })
58
- response.body #=> " response... "
70
+ op.prime("users", " response... ", include: "I am a body")
71
+ response = Faraday.post("http://localhost:7002/get/users", "I am a body")
72
+ response.status #=> 200
59
73
  ```
60
74
 
75
+ ## Simulating server processing or timeouts
76
+ ```ruby
77
+ op.prime("users", " response... ", sleep: 10)
78
+ response = Faraday.get("http://localhost:7002/get/users")
79
+ # .... 10 seconds later ...
80
+ response.status #=> 200
81
+ ```
82
+
83
+
61
84
  ## TODO
62
85
  * Move server initialisation into rake task in order to prevent it from initialising
63
86
  from its directory.
@@ -11,13 +11,13 @@ module OptimusPrime
11
11
  post "/get/*" do
12
12
  path = self.env["REQUEST_URI"].sub("/get/", "")
13
13
  response = responses[path]
14
+ return 404 if response.nil?
15
+ sleep(response[:sleep].to_f) if response[:sleep]
14
16
 
15
- if response[:constraint]
16
- constraint = eval(response[:constraint])
17
- return 404 unless constraint
17
+ if response[:include]
18
+ return 404 unless eval("request.body.string.include?('#{response[:include]}')")
18
19
  end
19
20
 
20
- return 404 if response.nil?
21
21
  content_type(response[:content_type])
22
22
  status(response[:status_code])
23
23
  response[:body]
@@ -27,6 +27,8 @@ module OptimusPrime
27
27
  path = self.env["REQUEST_URI"].sub("/get/", "")
28
28
  response = responses[path]
29
29
  return 404 if response.nil?
30
+ sleep(response[:sleep].to_f) if response[:sleep]
31
+
30
32
  content_type(response[:content_type])
31
33
  status(response[:status_code])
32
34
  response[:body]
@@ -34,7 +36,7 @@ module OptimusPrime
34
36
 
35
37
  post "/prime" do
36
38
  path = params["path_name"]
37
- responses[path] = { content_type: (params["content_type"] || :html), body: params["response"], status_code: (params["status_code"] || 200), constraint: (params["constraint"] || false) }
39
+ responses[path] = { content_type: (params["content_type"] || :html), body: params["response"], status_code: (params["status_code"] || 200), include: (params["include"] || false), sleep: (params["sleep"] || false) }
38
40
  201
39
41
  end
40
42
 
@@ -1,3 +1,3 @@
1
1
  module OptimusPrime
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1203,3 +1203,302 @@ Thin web server (v1.6.2 codename Doc Brown)
1203
1203
  Debugging ON
1204
1204
  Maximum connections set to 1024
1205
1205
  Listening on 0.0.0.0:7002, CTRL+C to stop
1206
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1207
+ Using rack adapter
1208
+ Thin web server (v1.6.2 codename Doc Brown)
1209
+ Debugging ON
1210
+ Maximum connections set to 1024
1211
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1212
+ Waiting for 1 connection(s) to finish, can take up to 30 sec, CTRL+C to stop now
1213
+ Exiting!
1214
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1215
+ Using rack adapter
1216
+ Thin web server (v1.6.2 codename Doc Brown)
1217
+ Debugging ON
1218
+ Maximum connections set to 1024
1219
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1220
+ Waiting for 1 connection(s) to finish, can take up to 30 sec, CTRL+C to stop now
1221
+ Exiting!
1222
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1223
+ Using rack adapter
1224
+ Thin web server (v1.6.2 codename Doc Brown)
1225
+ Debugging ON
1226
+ Maximum connections set to 1024
1227
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1228
+ Exiting!
1229
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1230
+ Using rack adapter
1231
+ Thin web server (v1.6.2 codename Doc Brown)
1232
+ Debugging ON
1233
+ Maximum connections set to 1024
1234
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1235
+ Exiting!
1236
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1237
+ Using rack adapter
1238
+ Thin web server (v1.6.2 codename Doc Brown)
1239
+ Debugging ON
1240
+ Maximum connections set to 1024
1241
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1242
+ Exiting!
1243
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1244
+ Using rack adapter
1245
+ Thin web server (v1.6.2 codename Doc Brown)
1246
+ Debugging ON
1247
+ Maximum connections set to 1024
1248
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1249
+ Exiting!
1250
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1251
+ Using rack adapter
1252
+ Thin web server (v1.6.2 codename Doc Brown)
1253
+ Debugging ON
1254
+ Maximum connections set to 1024
1255
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1256
+ Exiting!
1257
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1258
+ Using rack adapter
1259
+ Thin web server (v1.6.2 codename Doc Brown)
1260
+ Debugging ON
1261
+ Maximum connections set to 1024
1262
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1263
+ TypeError - can't convert String into time interval:
1264
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `sleep'
1265
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `block in <class:Server>'
1266
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
1267
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
1268
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
1269
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
1270
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
1271
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
1272
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
1273
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
1274
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
1275
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
1276
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
1277
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
1278
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
1279
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1280
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1281
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1282
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
1283
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
1284
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1285
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1286
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1287
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
1288
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
1289
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
1290
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
1291
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
1292
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1293
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1294
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
1295
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/nulllogger.rb:9:in `call'
1296
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
1297
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
1298
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
1299
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
1300
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
1301
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
1302
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
1303
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:86:in `block in pre_process'
1304
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `catch'
1305
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pre_process'
1306
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
1307
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
1308
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
1309
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
1310
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
1311
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
1312
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:87:in `start'
1313
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
1314
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
1315
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
1316
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `load'
1317
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `<main>'
1318
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
1319
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
1320
+ TypeError - can't convert String into time interval:
1321
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `sleep'
1322
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `block in <class:Server>'
1323
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
1324
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
1325
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
1326
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
1327
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
1328
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
1329
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
1330
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
1331
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
1332
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
1333
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
1334
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
1335
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
1336
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1337
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1338
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1339
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
1340
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
1341
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1342
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1343
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1344
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
1345
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
1346
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
1347
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
1348
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
1349
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1350
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1351
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
1352
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/nulllogger.rb:9:in `call'
1353
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
1354
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
1355
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
1356
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
1357
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
1358
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
1359
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
1360
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:86:in `block in pre_process'
1361
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `catch'
1362
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pre_process'
1363
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
1364
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
1365
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
1366
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
1367
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
1368
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
1369
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:87:in `start'
1370
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
1371
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
1372
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
1373
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `load'
1374
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `<main>'
1375
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
1376
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
1377
+ TypeError - can't convert String into time interval:
1378
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `sleep'
1379
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `block in <class:Server>'
1380
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
1381
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
1382
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
1383
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
1384
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
1385
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
1386
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
1387
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
1388
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
1389
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
1390
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
1391
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
1392
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
1393
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1394
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1395
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1396
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
1397
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
1398
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1399
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1400
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1401
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
1402
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
1403
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
1404
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
1405
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
1406
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1407
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1408
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
1409
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/nulllogger.rb:9:in `call'
1410
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
1411
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
1412
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
1413
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
1414
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
1415
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
1416
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
1417
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:86:in `block in pre_process'
1418
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `catch'
1419
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pre_process'
1420
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
1421
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
1422
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
1423
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
1424
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
1425
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
1426
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:87:in `start'
1427
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
1428
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
1429
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
1430
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `load'
1431
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `<main>'
1432
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
1433
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
1434
+ TypeError - can't convert String into time interval:
1435
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `sleep'
1436
+ /Users/acnalesso/dev/optimus_prime/lib/optimus_prime/server.rb:15:in `block in <class:Server>'
1437
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
1438
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
1439
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
1440
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
1441
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
1442
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
1443
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
1444
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
1445
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
1446
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
1447
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
1448
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
1449
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
1450
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1451
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1452
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1453
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
1454
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
1455
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
1456
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
1457
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
1458
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
1459
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
1460
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
1461
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
1462
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
1463
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1464
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
1465
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
1466
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/nulllogger.rb:9:in `call'
1467
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
1468
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
1469
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
1470
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
1471
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
1472
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
1473
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
1474
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:86:in `block in pre_process'
1475
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `catch'
1476
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pre_process'
1477
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
1478
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
1479
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
1480
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
1481
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
1482
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
1483
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:87:in `start'
1484
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
1485
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
1486
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
1487
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `load'
1488
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/thin:23:in `<main>'
1489
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
1490
+ /Users/acnalesso/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
1491
+ Exiting!
1492
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1493
+ Using rack adapter
1494
+ Thin web server (v1.6.2 codename Doc Brown)
1495
+ Debugging ON
1496
+ Maximum connections set to 1024
1497
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1498
+ Exiting!
1499
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1500
+ Using rack adapter
1501
+ Thin web server (v1.6.2 codename Doc Brown)
1502
+ Debugging ON
1503
+ Maximum connections set to 1024
1504
+ Listening on 0.0.0.0:7002, CTRL+C to stop
@@ -92,7 +92,7 @@ describe OptimusPrime do
92
92
  context "Asserting on request content" do
93
93
 
94
94
  it "returns a 404 if the request body does not match the assertion" do
95
- op.prime("user", { username: "Test" }.to_json, content_type: :json, constraint: "request.body.string.include?('ahahah')")
95
+ op.prime("user", { username: "Test" }.to_json, content_type: :json, include: "haha")
96
96
 
97
97
  response = ::Faraday.post('http://localhost:7002/get/user', "I am a body")
98
98
 
@@ -100,7 +100,7 @@ describe OptimusPrime do
100
100
  end
101
101
 
102
102
  it "returns a 200 if the request body does match the assertion" do
103
- op.prime("user", { username: "Test" }.to_json, content_type: :json, constraint: "request.body.string.include?('I am a body')")
103
+ op.prime("user", { username: "Test" }.to_json, content_type: :json, include: "I am a body")
104
104
 
105
105
  response = ::Faraday.post('http://localhost:7002/get/user', "I am a body")
106
106
 
@@ -109,4 +109,25 @@ describe OptimusPrime do
109
109
 
110
110
  end
111
111
 
112
+ context "Server processing" do
113
+ it "#GET tells the server to sleep for n seconds in order to reproduce timeouts" do
114
+ op.prime("user", { username: "Test" }.to_json, content_type: :json, sleep: 10)
115
+
116
+
117
+ expect do
118
+ ::Faraday.get('http://localhost:7002/get/user') { |r| r.options.timeout = 0.2 }
119
+ end.to raise_error
120
+
121
+ end
122
+
123
+ it "#POST tells the server to sleep for n seconds in order to reproduce timeouts" do
124
+ op.prime("user", { username: "Test" }.to_json, content_type: :json, sleep: 10)
125
+
126
+ expect do
127
+ ::Faraday.post('http://localhost:7002/get/user', "I am a body") { |r| r.options.timeout = 0.2 }
128
+ end.to raise_error
129
+
130
+ end
131
+ end
132
+
112
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimus_prime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Nalesso