optimus_prime 1.4.0 → 1.5.0

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.
@@ -1,3 +1,5 @@
1
+ OptimusPrime.restart_server
2
+
1
3
  describe OptimusPrime do
2
4
 
3
5
  let(:op) { OptimusPrime::Base.new }
@@ -159,33 +161,53 @@ describe OptimusPrime do
159
161
 
160
162
  end
161
163
 
162
- context "it returns the requests made for a path" do
164
+ context "it returns the last request made for a path" do
163
165
 
164
166
  it "GET" do
165
167
  op.prime("continue", { username: "Test" }.to_json, content_type: :json)
166
168
  ::Faraday.get("http://localhost:7003/get/continue", nil, { "Content-Type" => "application/json", "Accept" => "application/json" })
167
- expect( op.requests("continue") ).to eq([{ "method" => "GET", "body" => {}, "headers" => { "content_type" => "application/json", "accept" => ["application/json"] } }])
169
+ expect( op.last_request_for("continue") ).to eq({ "method" => "GET", "body" => {}, "headers" => { "content_type" => "application/json", "accept" => ["application/json"] } })
168
170
  end
169
171
 
170
172
  it "POST" do
171
173
  op.prime("kermit", { username: "Test" }.to_json, content_type: :json)
172
174
  ::Faraday.post("http://localhost:7003/get/kermit", { username: "Test" })
173
- expect( op.requests("kermit") ).to eq([{ "method" => "POST", "body" => { "username" => "Test" }, "headers"=>{ "content_type"=>"application/x-www-form-urlencoded", "accept"=>["*/*"]} }])
175
+ expect( op.last_request_for("kermit") ).to eq({ "method" => "POST", "body" => { "username" => "Test" }, "headers"=>{ "content_type"=>"application/x-www-form-urlencoded", "accept"=>["*/*"]} })
174
176
  end
175
177
 
176
178
  it "PUT" do
177
179
  op.prime("put/kermit", { username: "Test" }.to_json, content_type: :json)
178
180
  ::Faraday.put("http://localhost:7003/get/put/kermit", { username: "Test" })
179
- expect( op.requests("put/kermit") ).to eq([{"method"=>"PUT", "body"=>{"username"=>"Test"}, "headers"=>{"content_type"=>"application/x-www-form-urlencoded", "accept"=>["*/*"]}}])
181
+ expect( op.last_request_for("put/kermit") ).to eq({"method"=>"PUT", "body"=>{"username"=>"Test"}, "headers"=>{"content_type"=>"application/x-www-form-urlencoded", "accept"=>["*/*"]}})
180
182
  end
181
183
 
182
184
  it "returns a decoded body" do
183
185
  op.prime("kermit", { username: "Test" }.to_json, content_type: :json)
184
186
  ::Faraday.post("http://localhost:7003/get/kermit", { word: "with spaces and other shit" })
185
- expect( op.requests("kermit") ).to eq([{"method"=>"POST", "body"=>{"word"=>"with spaces and other shit"}, "headers"=>{"content_type"=>"application/x-www-form-urlencoded", "accept"=>["*/*"]}}])
187
+ expect( op.last_request_for("kermit") ).to eq({"method"=>"POST", "body"=>{"word"=>"with spaces and other shit"}, "headers"=>{"content_type"=>"application/x-www-form-urlencoded", "accept"=>["*/*"]}})
188
+ end
189
+
190
+ it "tries for up to 2 seconds to get the last request" do
191
+ op = OptimusPrime::Base.new(wait_for: 2)
192
+ op.prime("waitMan", { status: "waiting" }.to_json, content_type: :json)
193
+ Thread.new { sleep(1); ::Faraday.get("http://localhost:7003/get/waitMan", nil, { "Content-Type" => "application/json", "Accept" => "application/json" })}
194
+ expect( op.last_request_for("waitMan") ).to eq({ "method" => "GET", "body" => {}, "headers" => { "content_type" => "application/json", "accept" => ["application/json"] } })
195
+ end
196
+
197
+ it "returns the last request as nil if it doesn't find a request after 2 seconds" do
198
+ op = OptimusPrime::Base.new(wait_for: 2)
199
+ op.prime("waitMan", { status: "waiting" }.to_json, content_type: :json)
200
+ Thread.new { sleep(3); ::Faraday.get("http://localhost:7003/get/waitMan", nil, { "Content-Type" => "application/json", "Accept" => "application/json" })}
201
+ expect( op.last_request_for("waitMan") ).to eq({})
186
202
  end
187
203
 
204
+ it "sets default seconds for wait_for" do
205
+ op = OptimusPrime::Base.new
206
+ expect( op.wait_for ).to eq(3)
207
+ end
188
208
 
189
209
  end
190
210
 
211
+
212
+
191
213
  end
data/tags CHANGED
@@ -15,11 +15,12 @@ current_path lib/optimus_prime.rb /^ def self.current_path; `pwd`.chomp; end$/;
15
15
  full_path lib/optimus_prime.rb /^ def self.full_path$/;" F class:OptimusPrime
16
16
  get_boolean lib/optimus_prime/server.rb /^ def get_boolean(boolean)$/;" f
17
17
  get_path lib/optimus_prime/server.rb /^ def get_path$/;" f
18
+ initialize lib/optimus_prime.rb /^ def initialize(opts={})$/;" f class:OptimusPrime.Base
19
+ last_request_for lib/optimus_prime.rb /^ def last_request_for(path_name)$/;" f class:OptimusPrime.Base
18
20
  op_port lib/optimus_prime.rb /^ def self.op_port; @@op_port; end$/;" F class:OptimusPrime
19
21
  optimus_prime_path lib/optimus_prime.rb /^ def self.optimus_prime_path$/;" F class:OptimusPrime
20
22
  prime lib/optimus_prime.rb /^ def prime(path_name, response="", options={})$/;" f class:OptimusPrime.Base
21
23
  record_request lib/optimus_prime/server.rb /^ def record_request(path)$/;" f
22
- requests lib/optimus_prime.rb /^ def requests(path_name)$/;" f class:OptimusPrime.Base
23
24
  requests lib/optimus_prime/server.rb /^ def requests$/;" f
24
25
  responses lib/optimus_prime/server.rb /^ def responses$/;" f
25
26
  restart_server lib/optimus_prime.rb /^ def self.restart_server$/;" F class:OptimusPrime
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: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Nalesso