optimus_prime 0.1.0 → 0.1.1

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: 63bf3354440bf026485806d80f3872d0ef821db6
4
- data.tar.gz: 517612f79a22d402cf1e1770b008a9bf26c6213e
3
+ metadata.gz: 79382a0cd439f8c3e2fe3e39036c3733de719e53
4
+ data.tar.gz: b476f6bd79cdbc27eb13beb59fd61262830ca617
5
5
  SHA512:
6
- metadata.gz: 27e8950c4931551143da168fdbbb8effff0feabaa07450f893c5812fbe96b37a3abc4893f5c9e8469e9324f9f8aa07ef48d976f8decea1b8743967dabae1c8f2
7
- data.tar.gz: 53a8705d11c92f5814f6c9910a0f0cd2da4d3778159569a9853fc28052a095a94df51ba714c6e680603dac6a73d2bd469569ae53d93a467d641b283c116418a0
6
+ metadata.gz: 225dd5cd8d2e15f6f11127e74c4e091e69a467000ab6032518dd37fcc48c1b53c0aa807e0eda7eb490c4963f1911375e69c28f024cb1e7d34b9175a9666a6c4d
7
+ data.tar.gz: 1a96b86edca6c5d89e6ddc614f0488ee60b18f6baf85913c21f857d342e42fdf27952b040fa70bce12521a418feee5d9dc85286302962f0d4d6b2d62dc54b6ed
data/README.md CHANGED
@@ -67,7 +67,7 @@ response.status #=> 404
67
67
 
68
68
  ## Assert on a POST request body
69
69
  ```ruby
70
- op.prime("users", " response... ", include: "I am a body")
70
+ op.prime("users", " response... ", requested_with: "a body")
71
71
  response = Faraday.post("http://localhost:7002/get/users", "I am a body")
72
72
  response.status #=> 200
73
73
  ```
data/lib/optimus_prime.rb CHANGED
@@ -40,5 +40,9 @@ module OptimusPrime
40
40
  ::Faraday.post("http://localhost:7002/prime", { path_name: path_name, response: response }.merge!(options))
41
41
  end
42
42
 
43
+ def clear!
44
+ ::Faraday.get("http://localhost:7002/clear")
45
+ end
46
+
43
47
  end
44
48
  end
@@ -12,20 +12,27 @@ module OptimusPrime
12
12
  path = self.env["REQUEST_URI"].sub("/get/", "")
13
13
  response = responses[path]
14
14
  return 404 if response.nil?
15
- sleep(response[:sleep].to_f) if response[:sleep]
16
15
 
17
- if response[:include]
18
- return 404 unless eval("request.body.string.include?('#{response[:include]}')")
16
+ if response[:requested_with]
17
+ return 404 unless eval("request.body.string.include?('#{response[:requested_with]}')")
19
18
  end
20
19
 
21
20
  content_type(response[:content_type])
22
21
  status(response[:status_code])
22
+
23
+ sleep(response[:sleep].to_i) if response[:sleep]
24
+
23
25
  response[:body]
24
26
  end
25
27
 
26
- get "/get/*" do
28
+ def get_response
27
29
  path = self.env["REQUEST_URI"].sub("/get/", "")
28
- response = responses[path]
30
+ responses[path]
31
+ end
32
+
33
+ get "/get/*" do
34
+ #path = self.env["REQUEST_URI"].sub("/get/", "")
35
+ response = get_response
29
36
  return 404 if response.nil?
30
37
  sleep(response[:sleep].to_f) if response[:sleep]
31
38
 
@@ -36,7 +43,7 @@ module OptimusPrime
36
43
 
37
44
  post "/prime" do
38
45
  path = params["path_name"]
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) }
46
+ responses[path] = { content_type: (params["content_type"] || :html), body: params["response"], status_code: (params["status_code"] || 200), requested_with: (params["requested_with"] || false), sleep: (params["sleep"] || false) }
40
47
  201
41
48
  end
42
49
 
@@ -45,6 +52,10 @@ module OptimusPrime
45
52
  responses.to_json
46
53
  end
47
54
 
55
+ get "/clear" do
56
+ @@responses = {}
57
+ end
58
+
48
59
  private
49
60
 
50
61
  def responses
@@ -1,3 +1,3 @@
1
1
  module OptimusPrime
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/optimus_prime.log CHANGED
@@ -1502,3 +1502,52 @@ Thin web server (v1.6.2 codename Doc Brown)
1502
1502
  Debugging ON
1503
1503
  Maximum connections set to 1024
1504
1504
  Listening on 0.0.0.0:7002, CTRL+C to stop
1505
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1506
+ Using rack adapter
1507
+ Thin web server (v1.6.2 codename Doc Brown)
1508
+ Debugging ON
1509
+ Maximum connections set to 1024
1510
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1511
+ Exiting!
1512
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1513
+ Using rack adapter
1514
+ Thin web server (v1.6.2 codename Doc Brown)
1515
+ Debugging ON
1516
+ Maximum connections set to 1024
1517
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1518
+ Exiting!
1519
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1520
+ Using rack adapter
1521
+ Thin web server (v1.6.2 codename Doc Brown)
1522
+ Debugging ON
1523
+ Maximum connections set to 1024
1524
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1525
+ Exiting!
1526
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1527
+ Using rack adapter
1528
+ Thin web server (v1.6.2 codename Doc Brown)
1529
+ Debugging ON
1530
+ Maximum connections set to 1024
1531
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1532
+ Waiting for 1 connection(s) to finish, can take up to 30 sec, CTRL+C to stop now
1533
+ Exiting!
1534
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1535
+ Using rack adapter
1536
+ Thin web server (v1.6.2 codename Doc Brown)
1537
+ Debugging ON
1538
+ Maximum connections set to 1024
1539
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1540
+ Exiting!
1541
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1542
+ Using rack adapter
1543
+ Thin web server (v1.6.2 codename Doc Brown)
1544
+ Debugging ON
1545
+ Maximum connections set to 1024
1546
+ Listening on 0.0.0.0:7002, CTRL+C to stop
1547
+ Exiting!
1548
+ Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
1549
+ Using rack adapter
1550
+ Thin web server (v1.6.2 codename Doc Brown)
1551
+ Debugging ON
1552
+ Maximum connections set to 1024
1553
+ Listening on 0.0.0.0:7002, CTRL+C to stop
@@ -69,30 +69,10 @@ describe OptimusPrime do
69
69
  expect( JSON.parse(response.body) ).to eq({ "username" => "Test" })
70
70
  end
71
71
 
72
- context "Starting and Stopping the server" do
73
- it "starts the server" do
74
- OptimusPrime.restart_server
75
- expect( `ls ./tmp/pids` ).to include("optimus_prime.pid")
76
- end
77
-
78
- it "stops the server" do
79
- OptimusPrime.start_server
80
- OptimusPrime.stop_server
81
- expect( `ls ./tmp/pids` ).to_not include("optimus_prime.pid")
82
- OptimusPrime.start_server
83
- end
84
-
85
- it "informs me if the server is already running" do
86
- OptimusPrime.start_server
87
- expect( OptimusPrime.start_server ).to include("Optimus is already priming :)")
88
- end
89
-
90
- end
91
-
92
72
  context "Asserting on request content" do
93
73
 
94
74
  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, include: "haha")
75
+ op.prime("user", { username: "Test" }.to_json, content_type: :json, requested_with: "haha")
96
76
 
97
77
  response = ::Faraday.post('http://localhost:7002/get/user', "I am a body")
98
78
 
@@ -100,7 +80,7 @@ describe OptimusPrime do
100
80
  end
101
81
 
102
82
  it "returns a 200 if the request body does match the assertion" do
103
- op.prime("user", { username: "Test" }.to_json, content_type: :json, include: "I am a body")
83
+ op.prime("user", { username: "Test" }.to_json, content_type: :json, requested_with: "I am a body")
104
84
 
105
85
  response = ::Faraday.post('http://localhost:7002/get/user', "I am a body")
106
86
 
@@ -110,24 +90,29 @@ describe OptimusPrime do
110
90
  end
111
91
 
112
92
  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
93
 
94
+ it "#GET tells the server to sleep for 10 seconds in order to reproduce timeouts" do
95
+ op.prime("userAsleep", { username: "Test" }.to_json, content_type: :json, sleep: 10)
96
+
97
+ f = ::Faraday.new('http://localhost:7002/get/')
98
+ f.options.timeout = 0
116
99
 
117
- expect do
118
- ::Faraday.get('http://localhost:7002/get/user') { |r| r.options.timeout = 0.2 }
119
- end.to raise_error
100
+ expect { f.get("/userAsleep") }.to raise_error(Faraday::TimeoutError)
120
101
 
102
+ op.clear!
121
103
  end
122
104
 
123
105
  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)
106
+ op.prime("userAsleepAgain", { username: "Test" }.to_json, content_type: :json, sleep: 10)
125
107
 
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
108
+ f = ::Faraday.new('http://localhost:7002/get/')
109
+ f.options.timeout = 0
129
110
 
111
+ expect { f.get("/userAsleepAgain") }.to raise_error(Faraday::TimeoutError)
112
+
113
+ op.clear!
130
114
  end
115
+
131
116
  end
132
117
 
133
118
  end
@@ -0,0 +1,19 @@
1
+ describe OptimusPrime, "Starting and Stopping the server" do
2
+ it "starts the server" do
3
+ OptimusPrime.restart_server
4
+ expect( `ls ./tmp/pids` ).to include("optimus_prime.pid")
5
+ end
6
+
7
+ it "stops the server" do
8
+ OptimusPrime.start_server
9
+ OptimusPrime.stop_server
10
+ expect( `ls ./tmp/pids` ).to_not include("optimus_prime.pid")
11
+ OptimusPrime.start_server
12
+ end
13
+
14
+ it "informs me if the server is already running" do
15
+ OptimusPrime.start_server
16
+ expect( OptimusPrime.start_server ).to include("Optimus is already priming :)")
17
+ end
18
+
19
+ 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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Nalesso
@@ -101,6 +101,7 @@ files:
101
101
  - optimus_prime.gemspec
102
102
  - optimus_prime.log
103
103
  - spec/lib/optimus_prime_spec.rb
104
+ - spec/lib/start_stop_spec.rb
104
105
  - spec/spec_helper.rb
105
106
  homepage: ''
106
107
  licenses:
@@ -128,4 +129,5 @@ specification_version: 4
128
129
  summary: Create endpoints and persists data
129
130
  test_files:
130
131
  - spec/lib/optimus_prime_spec.rb
132
+ - spec/lib/start_stop_spec.rb
131
133
  - spec/spec_helper.rb