soaspec 0.2.2 → 0.2.3

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: 1be796f9ede9ecbecec8effaa198c8e7393e3648
4
- data.tar.gz: c80d4e76e7e5fc58e7457fa774e5a3bd7a3932c5
3
+ metadata.gz: 757cc34fa056aa23860299c614c1e981b96a6c7d
4
+ data.tar.gz: af77364e1117ea4fc27d7375ab9366c6d6f3d222
5
5
  SHA512:
6
- metadata.gz: dadb8d208c81c5158d33790d2f308be0dd940b9ee5585a04b94fd5e88ffbbd31c26b5ffc4ae9f5a0c0f3ae797b89918f1b0dd0bdb87377abe18bc2b69557511b
7
- data.tar.gz: c21ab190b0e65a5c750d1d0127c95df18069e31416698e33b7feeafd574ab3a5127ae74866f9d30b200513e266773e6a3c0bb5ed09b1496ead2bb75ee8c427ce
6
+ metadata.gz: aabc608e6182a76290d7c546f66f722dd19c4d7b183f263cffd7bcc3f569951c15c9beb2925a455d7e4c71dcb0d6990ebd4919535f1026b6422cae05f49c364e
7
+ data.tar.gz: 51547871679bbbd4c23c261315f241980f417c9c4bcd1802f450a801c60b2e4abf712c49bcb12c14a692314997377b6c7e2bb18f843194e677d965cc59c39d2f
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.2.3
2
+ * Enhancements
3
+ * Exchange.until itself method returns itself making it easier to reuse last result in assertions
4
+ * Added parameters to Exchange.until so that timeout, message and interval can be specified
5
+ * Soaspec cucumber exe to add generic steps to step_definitions folder
6
+
1
7
  Version 0.2.2
2
8
  * Enhancements
3
9
  * Make accessing test_values from template using indifferent access
data/exe/soaspec CHANGED
@@ -55,7 +55,14 @@ module Soaspec
55
55
  def add(type = 'rest', name = 'TestService')
56
56
  raise "Type '#{type}' is not available" unless %w[rest soap].include? type
57
57
  @name = name # Use instance variable for ERB
58
- create_file(filename: File.join('lib', "#{name.snakecase}.rb"), content: retrieve_contents("lib/new_#{type}_service.rb"))
58
+ create_file filename: File.join('lib', "#{name.snakecase}.rb"),
59
+ content: retrieve_contents(File.join('lib', "new_#{type}_service.rb"))
60
+ end
61
+
62
+ desc 'cucumber', 'Add cucumber generic steps template within step_definitions folder'
63
+ def cucumber
64
+ create_file filename: File.join('features', 'step_definitions', 'generic_steps.rb'),
65
+ content: retrieve_contents(File.join('../cucumber', 'generic_steps.rb'), false)
59
66
  end
60
67
 
61
68
  desc 'generate', 'Generate initial test code from wsdl'
data/exe/xml_to_yaml_file CHANGED
@@ -12,25 +12,6 @@ include Soaspec::ExeHelpers
12
12
 
13
13
  default_output_file = 'output.yml'
14
14
 
15
- # Create file if not present. If present but different give warning
16
- def create_file(options)
17
- filename = options[:filename]
18
- raise 'Need to pass filename' unless filename
19
- content = options[:content]
20
- raise 'Need to pass contents to insert into file' unless content
21
- if File.exist? filename
22
- old_content = File.read(filename)
23
- if old_content != content
24
- warn "!! #{filename} already exists and differs from template"
25
- end
26
- else
27
- File.open(filename, 'w') do |f|
28
- f.puts content
29
- end
30
- puts 'Created: ' + filename
31
- end
32
- end
33
-
34
15
  # For all keys in a Hash, convert Camelcase to underscore separated
35
16
  def convert_hash_keys(value)
36
17
  case value
@@ -7,11 +7,17 @@ end
7
7
 
8
8
  # Pass in the operation (HTTP method or SOAP operation) in first parameter and api name as second.
9
9
  # API name can be mulitple words and it will be converted to camel case to find the ExchangeHandler class
10
+ # @example Create an Exchange representing an HTTP 'post' based on the 'Puppy' RestHandler class
11
+ # I am performing a post on the Puppy API
12
+ # @example Create an Exchange for a 'get_bank' operation on for a 'Banking' SoapHandler class
13
+ # I am performing a get_bank on the Banking API
10
14
  Given 'I am performing a {word} on the {string} API' do |operation, api_name|
11
15
  @current_exchange = api_name.tr(' ', '_').camelize.constantize.send operation
12
16
  end
13
17
 
14
18
  # Set a parameter in the request body
19
+ # @example Set the name element in the request body to Charlie
20
+ # And I set the name to 'Charlie'
15
21
  # @param [String] Element in request body to set
16
22
  # @param [String] Value to set it to
17
23
  Given 'I set the {word} to {string}' do |key, value|
@@ -19,11 +25,17 @@ Given 'I set the {word} to {string}' do |key, value|
19
25
  end
20
26
 
21
27
  # Add onto the base_url to make a complete url for the test
28
+ # @example base_url is 'http://petstore.swagger.io/v2' and I want a post to 'http://petstore.swagger.io/v2/pet'
29
+ # I use the path pet
22
30
  Given 'I use the path {word}' do |suburl|
23
31
  current_exchange.suburl = suburl
24
32
  end
25
33
 
26
34
  # Add a query parameter for http 'get' requests. e.g. will add '?filter_key=filter_value' onto URL
35
+ # @example To create a query for '?status=sold'
36
+ # And I filter 'status' by 'sold'
37
+ # @example To add a query for 'area' being 'australia' to make a total of '?status=sold&area=austrialia'
38
+ # And I filter 'area' by 'australia'
27
39
  Given 'I filter {string} by {string}' do |filter_key, filter_value|
28
40
  transformed_key = filter_key.to_sym
29
41
  if current_exchange.override_parameters[:q]
@@ -34,6 +46,8 @@ Given 'I filter {string} by {string}' do |filter_key, filter_value|
34
46
  end
35
47
 
36
48
  # Add HTTP header 'header_name' as 'header_value'
49
+ # @example
50
+ # And I set header 'accept' to 'application/xml'
37
51
  Given 'I set header {string} to {string}' do |header_name, header_value|
38
52
  if current_exchange.override_parameters[:params]
39
53
  current_exchange.override_parameters[:params][header_name] = header_value
@@ -49,12 +63,16 @@ When 'I make the request' do
49
63
  end
50
64
 
51
65
  # Extract the value from the response that is at the path 'key' and verify it is eq to expected_value
66
+ # @example Assert response body has at the path 'name', the value 'Charlie'
67
+ # Then it should have the name 'Charlie'
52
68
  Then 'it should have the {word} {string}' do |key, expected_value|
53
69
  expect(current_exchange[key]).to eq expected_value
54
70
  end
55
71
 
56
72
  # Extract the value from the response that is at the path 'key_string' and verify it is eq to expected_value
57
73
  # Conversion is made on key_string to make it one snake case word
74
+ # @example Assert response body has at the path 'customer_name', the value 'Charlie'
75
+ # Then it should have the 'customer name' 'Charlie'
58
76
  Then 'it should have the {string} {string}' do |key_string, expected_value|
59
77
  key = key_string.tr(' ', '_')
60
78
  actual_value = current_exchange.respond_to?(key) ? current_exchange.send(key) : current_exchange[key]
@@ -219,10 +219,17 @@ class Exchange
219
219
  end
220
220
 
221
221
  # Wait until the passed block returns true
222
- def until(&script)
223
- Soaspec::Wait.until do
222
+ # @param [Hash] opts Options for this instance
223
+ # @option opts [Numeric] :timeout (5) Seconds to wait before timing out.
224
+ # @option opts [Numeric] :interval (0.2) Seconds to sleep between polls.
225
+ # @option opts [String] :message Exception mesage if timed out.
226
+ # @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Error::NoSuchElementError)
227
+ # @return [Self] Returns itself so operations can be done on the exchange after it's done waiting
228
+ def until(opts = {}, &script)
229
+ Soaspec::Wait.until(opts) do
224
230
  @response = nil # Reset response so it can be made repeatedly
225
231
  instance_eval(&script)
226
232
  end
233
+ self
227
234
  end
228
235
  end
@@ -34,7 +34,11 @@ module Soaspec
34
34
  # @param [String] filename Filename within 'lib/generator' to file retrieve contents from
35
35
  # @param [Boolean] erb Whether to process file with ERB
36
36
  def retrieve_contents(filename, erb = true)
37
- default_file = File.join(File.dirname(__FILE__), 'generator', filename + (erb ? '.erb' : ''))
37
+ default_file = if filename.start_with?('../')
38
+ File.join(File.dirname(__FILE__), filename[3..-1] + (erb ? '.erb' : ''))
39
+ else
40
+ File.join(File.dirname(__FILE__), 'generator', filename + (erb ? '.erb' : ''))
41
+ end
38
42
  contents = File.read(default_file)
39
43
  erb ? ERB.new(contents).result(binding) : contents
40
44
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
data/lib/soaspec/wait.rb CHANGED
@@ -19,6 +19,7 @@ module Soaspec
19
19
  def self.until(opts = {})
20
20
  timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT)
21
21
  ignored = Array(opts[:ignore] || NoElementAtPath)
22
+ interval = opts.fetch(:interval, DEFAULT_INTERVAL)
22
23
  end_time = Time.now + timeout
23
24
  last_error = nil
24
25
 
@@ -29,14 +30,10 @@ module Soaspec
29
30
  rescue *ignored => last_error
30
31
  # swallowed
31
32
  end
32
- sleep opts.fetch(:interval, DEFAULT_INTERVAL)
33
+ sleep interval
33
34
  end
34
35
 
35
- msg = if opts[:message]
36
- opts[:message].dup
37
- else
38
- "timed out after #{timeout} seconds"
39
- end
36
+ msg = opts[:message] ? opts[:message].dup : "timed out after #{timeout} seconds with interval of #{interval}"
40
37
  msg << " (#{last_error.message})" if last_error
41
38
  raise Soaspec::TimeOutError, msg
42
39
  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.2.2
4
+ version: 0.2.3
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-25 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler