optimus_prime 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -187,17 +187,17 @@ describe OptimusPrime do
187
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
188
  end
189
189
 
190
- it "tries for up to 2 seconds to get the last request" do
191
- op = OptimusPrime::Base.new(wait_for: 2)
190
+ it "tries for up to 0.1 seconds to get the last request" do
191
+ op = OptimusPrime::Base.new(wait_for: 0.1)
192
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" })}
193
+ Thread.new { sleep(0.01); ::Faraday.get("http://localhost:7003/get/waitMan", nil, { "Content-Type" => "application/json", "Accept" => "application/json" })}
194
194
  expect( op.last_request_for("waitMan") ).to eq({ "method" => "GET", "body" => {}, "headers" => { "content_type" => "application/json", "accept" => ["application/json"] } })
195
195
  end
196
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)
197
+ it "returns the last request as nil if it doesn't find a request after 0.1 seconds" do
198
+ op = OptimusPrime::Base.new(wait_for: 0.1)
199
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" })}
200
+ Thread.new { sleep(0.5); ::Faraday.get("http://localhost:7003/get/waitMan", nil, { "Content-Type" => "application/json", "Accept" => "application/json" })}
201
201
  expect( op.last_request_for("waitMan") ).to eq({})
202
202
  end
203
203
 
@@ -208,31 +208,30 @@ describe OptimusPrime do
208
208
 
209
209
  end
210
210
 
211
- context "allow devs to expect a request to be made" do
211
+ context "allow devs to wait for a request to be made" do
212
212
 
213
- it "does not raise an exception when the request has been made" do
214
- op = OptimusPrime::Base.new(wait_for: 4)
213
+ it "waits until the correct request has been made" do
214
+ op = OptimusPrime::Base.new(wait_for: 1)
215
215
  op.prime("expectation", { status: "UNKOWN" }, content_type: :json)
216
216
 
217
217
  ::Faraday.post("http://localhost:7003/get/expectation", { status: "IN_PROGRESS" } )
218
- Thread.new { sleep(3); ::Faraday.post("http://localhost:7003/get/expectation", { status: "COMPLETED" } )}
218
+ Thread.new { sleep(0.5); ::Faraday.post("http://localhost:7003/get/expectation", { status: "COMPLETED" } )}
219
219
 
220
- op.expect("expectation") do |response|
221
- expect(response["body"]["status"]).to eq("COMPLETED")
220
+ op.wait_until_request("expectation") do |request|
221
+ expect(request["body"]["status"]).to eq("COMPLETED")
222
222
  end
223
223
 
224
224
  end
225
225
 
226
226
  it "does raise an error when it times out" do
227
- op = OptimusPrime::Base.new(wait_for: 1)
227
+ op = OptimusPrime::Base.new(wait_for: 0.1)
228
228
  op.prime("timeOut", { status: "NO" }, content_type: :json)
229
229
 
230
- ::Faraday.post("http://localhost:7003/get/timeOut", { status: "NO" } )
231
- Thread.new { sleep(3); ::Faraday.post("http://localhost:7003/get/timeOut", { status: "YES" } )}
230
+ Thread.new { sleep(1); ::Faraday.post("http://localhost:7003/get/timeOut", { status: "YES" } ) }
232
231
 
233
- op.expect("timeOut") do |response|
234
- expect(response["body"]["status"]).to eq("NO")
235
- end
232
+ expect do
233
+ op.wait_until_request("timeOut") { |request| }
234
+ end.to raise_error
236
235
  end
237
236
 
238
237
  end
data/tags CHANGED
@@ -12,7 +12,6 @@ Server lib/optimus_prime/server.rb /^ class Server < ::Sinatra::Base$/;" c clas
12
12
  clear! lib/optimus_prime.rb /^ def clear!$/;" f class:OptimusPrime.Base
13
13
  count lib/optimus_prime.rb /^ def count(path_name)$/;" f class:OptimusPrime.Base
14
14
  current_path lib/optimus_prime.rb /^ def self.current_path; `pwd`.chomp; end$/;" F class:OptimusPrime
15
- expect lib/optimus_prime.rb /^ def expect(path_name, &block)$/;" f class:OptimusPrime.Base
16
15
  full_path lib/optimus_prime.rb /^ def self.full_path$/;" F class:OptimusPrime
17
16
  get_boolean lib/optimus_prime/server.rb /^ def get_boolean(boolean)$/;" f
18
17
  get_path lib/optimus_prime/server.rb /^ def get_path$/;" f
@@ -27,3 +26,4 @@ responses lib/optimus_prime/server.rb /^ def responses$/;" f
27
26
  restart_server lib/optimus_prime.rb /^ def self.restart_server$/;" F class:OptimusPrime
28
27
  start_server lib/optimus_prime.rb /^ def self.start_server(options={})$/;" F class:OptimusPrime
29
28
  stop_server lib/optimus_prime.rb /^ def self.stop_server$/;" F class:OptimusPrime
29
+ wait_until_request lib/optimus_prime.rb /^ def wait_until_request(path_name, &block)$/;" f class:OptimusPrime.Base
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: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Nalesso