soaspec 0.1.16 → 0.1.17

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: be29f2183a787b94831d520bd5f08f50a3db0c51
4
- data.tar.gz: 2f04d48ca686b5788f498e1e89878cf0281df642
3
+ metadata.gz: 1f25cdd5470680bb035c2296f5b29dba6afe1aef
4
+ data.tar.gz: 7a0b0c4c47d201e2025e8bd702ef208c701c410b
5
5
  SHA512:
6
- metadata.gz: 21bac4eed696d3f8613f7f9dca483348e16c5e6c843da42f77e71590c7b8b29ca7b8b72143625d28d7c51b6297d50246a3a61e7dd4f031f5b38c72a6b096340a
7
- data.tar.gz: 8266742c1d2db5453e900521a60732f6890f6714a42d72b24604acc6636f9c1981b013d56a5d85f612b0b7e13bc4404510ec62545afd0d6c23eabd403d6dce1a
6
+ metadata.gz: 5f843a8d1775bf6149e398008197225ada75c282693f543ec819ca3cab14d4267316a930256523686bfbef2470d723d0cfc1b45a278e46ded94b07ef5778051a
7
+ data.tar.gz: 03b8333eddee14dcd7d65415bf390c571fe2079c4f77ec410385d5fde7b101e7dd65cc69309661a67df0ccfbfca413df5729b86fe697b2a8ec1499df62509361
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.1.17
2
+ * Enhancements
3
+ * Added Wait class to easily wait for an expected condition to be true, either using global Soaspec::Wait or `exchange.until { true }`
4
+ See spec/unit/wait_spec for example
5
+ * Made shorter way to `get` a REST url with `RestHandler.get 'id'` setting the suburl to 'id' automatically
6
+
1
7
  Version 0.1.16
2
8
  * Bug fix
3
9
  * Retry was not working for OAuth access_token
@@ -31,6 +31,7 @@ require 'soaspec/test_server/invoices'
31
31
  require 'soaspec/test_server/test_namespace'
32
32
  require 'soaspec/test_server/id_manager'
33
33
  require 'soaspec/wsdl_generator'
34
+ require 'soaspec/wait'
34
35
 
35
36
  # Gem for handling SOAP and REST api tests
36
37
  module Soaspec
@@ -235,8 +235,16 @@ class Exchange
235
235
  self
236
236
  end
237
237
 
238
+ # @return [Hash] Hash representing the response of the API
238
239
  def to_hash
239
240
  exchange_handler.to_hash(response)
240
241
  end
241
242
 
243
+ # Wait until the passed block returns true
244
+ def until(&script)
245
+ Soaspec::Wait.until do
246
+ @response = nil # Reset response so it can be made repeatedly
247
+ instance_eval(&script)
248
+ end
249
+ end
242
250
  end
@@ -278,9 +278,17 @@ module Soaspec
278
278
 
279
279
  methods.each do |rest_method|
280
280
  # Make REST Exchange within this Handler context
281
- # @param [Hash] params Exchange parameters
281
+ # @param [Hash, String] params Exchange parameters. If String is used it will be for suburl
282
282
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
283
283
  define_method(rest_method) do |params = {}|
284
+ unless params.is_a? Hash
285
+ params = case rest_method
286
+ when 'get', 'delete'
287
+ { suburl: params.to_s }
288
+ else
289
+ params
290
+ end
291
+ end
284
292
  params[:name] ||= rest_method
285
293
  exchange_params = { name: params[:name] }
286
294
  if params[:template_name]
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.1.16'.freeze
2
+ VERSION = '0.1.17'.freeze
3
3
  end
@@ -0,0 +1,44 @@
1
+ module Soaspec
2
+ class TimeOutError < StandardError; end
3
+ # Class to enable waiting for an expected condition to return true
4
+ class Wait
5
+ DEFAULT_TIMEOUT = 5
6
+ DEFAULT_INTERVAL = 0.2
7
+
8
+ #
9
+ # Wait until the given block returns a true value.
10
+ #
11
+ # @param [Hash] opts Options for this instance
12
+ # @option opts [Numeric] :timeout (5) Seconds to wait before timing out.
13
+ # @option opts [Numeric] :interval (0.2) Seconds to sleep between polls.
14
+ # @option opts [String] :message Exception mesage if timed out.
15
+ # @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Error::NoSuchElementError)
16
+ # @raise [Error::TimeOutError]
17
+ # @return [Object] the result of the block
18
+ #
19
+ def self.until(opts = {})
20
+ timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT)
21
+ ignored = Array(opts[:ignore] || NoElementAtPath)
22
+ end_time = Time.now + timeout
23
+ last_error = nil
24
+
25
+ until Time.now > end_time
26
+ begin
27
+ result = yield
28
+ return result if result
29
+ rescue *ignored => last_error
30
+ # swallowed
31
+ end
32
+ sleep opts.fetch(:interval, DEFAULT_INTERVAL)
33
+ end
34
+
35
+ msg = if opts[:message]
36
+ opts[:message].dup
37
+ else
38
+ "timed out after #{timeout} seconds"
39
+ end
40
+ msg << " (#{last_error.message})" if last_error
41
+ raise Soaspec::TimeOutError, msg
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2018-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -400,6 +400,7 @@ files:
400
400
  - lib/soaspec/test_server/test_namespace.rb
401
401
  - lib/soaspec/version.rb
402
402
  - lib/soaspec/virtual_server.rb
403
+ - lib/soaspec/wait.rb
403
404
  - lib/soaspec/wsdl_generator.rb
404
405
  - soaspec.gemspec
405
406
  - templates/rest_template.json