soaspec 0.0.46 → 0.0.47

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f81e429ef1b144e0977520e79fd5ae9890bf3a89
4
- data.tar.gz: ed934b5fcddfee84837c3dbedfd4b90b424377e5
3
+ metadata.gz: 687a34b22e83e1010cf5619a8abbe2279b15954f
4
+ data.tar.gz: be4f8c9f0f1732e3cb416aa9f812f537330af1a0
5
5
  SHA512:
6
- metadata.gz: a64529f623d73ffe61da1c0d0ed28725d19ee4d26563ff804c24f7ea3c36dba203947a216169b3570d1df8b88a3e97e0e10a3de54e71a568da13caacc935ca34
7
- data.tar.gz: 0b1f8d43be55b3a7a810a5968894093a8d42bebd0e51d46b25921f787c1f8763cf7afc2bafa3fdea97962678ca6dd52f61737c857ca327fff473999fc1fe355a
6
+ metadata.gz: 5f3c5fd3b00ba6e174aaef074770f6b1f4623f6744137e58dc204bca86f8406d9a94a26fd4f7a10c5f73c40f53ef8dca8ebb890656633b3fd628e76ecc6f6b03
7
+ data.tar.gz: b9bea7f0d4ec52d9d580a249d7fe3492484c784e1c1d9661a79c8e9113bbec126d1b627e278421eddce9edea430b7189b85534a592dee43ea808b98dd0fd1434
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.0.47
2
+ * Enhancements
3
+ * 'success scenarios' shared eg and 'retry_for_success' exchange method's status codes include 200..299, not just 200.
4
+
1
5
  Version 0.0.46
2
6
  * Enhancements
3
7
  * 'include_key?' method use 'value_from_path'. Iterating through Hashes with 'include_key?' wouldn't work as expected with some JSON bodies with my current implementation
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.46)
4
+ soaspec (0.0.47)
5
5
  jsonpath
6
6
  rest-client (>= 2.0)
7
7
  rspec (~> 3.0)
data/Todo.md CHANGED
@@ -3,6 +3,7 @@
3
3
  * Demonstrate using Cucumber
4
4
  * Give examples and convenience methods for building classes for each SOAP or REST operation
5
5
  * Handle REST template (similar way to SOAP)
6
+ * spec for oauth demonstrating sharing same oauth params across multiple classes
6
7
  * Potentially have in built use of 'vcr' and 'http_stub' gems
7
8
  * Handle proxies to record traffic for MiddleWare testing
8
9
  * Much more
@@ -11,6 +11,7 @@ require 'jsonpath'
11
11
  require 'soaspec/version'
12
12
  require 'soaspec/exchange_handlers/soap_handler'
13
13
  require 'soaspec/exchange_handlers/exchange_handler'
14
+ require 'soaspec/exchange_handlers/rest_methods'
14
15
  require 'soaspec/exchange'
15
16
  require 'soaspec/matchers'
16
17
  require 'soaspec/soaspec_shared_examples'
@@ -25,130 +26,54 @@ require 'soaspec/not_found_errors'
25
26
  # Gem for handling SOAP and REST api tests
26
27
  module Soaspec
27
28
 
28
- # Folder used to store credentials
29
- # Used in auth2_file command
30
- # @param [String] folder
31
- def self.credentials_folder=(folder)
32
- @credentials_folder = folder
33
- end
34
-
35
- # Credentials folder used to store secret data (not in source control) E.g passwords
36
- def self.credentials_folder
37
- @credentials_folder
38
- end
39
-
40
- # Used so that exchange class knows what context it's in
41
- # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
42
- def self.api_handler=(handler)
43
- @api_handler = handler
44
- end
45
-
46
- def self.api_handler
47
- @api_handler
48
- end
29
+ class << self
49
30
 
50
- # Whether to transform strings to keys automatically
51
- def self.always_use_keys=(use_keys)
52
- @always_use_keys = use_keys
53
- end
54
-
55
- def self.always_use_keys?
56
- @always_use_keys || true
57
- end
58
-
59
- # Whether to remove namespaces from response in Xpath assertion automatically
60
- # For why this may not be a good thing in general see
61
- # http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
62
- # This will be overridden if xpath has a ':' in it
63
- def self.strip_namespaces=(remove_namespaces_from_response)
64
- @strip_namespaces = remove_namespaces_from_response
65
- end
66
-
67
- # Whether to remove namespaces in xpath assertion automatically
68
- def self.strip_namespaces?
69
- @strip_namespaces || false
70
- end
31
+ # Folder used to store credentials
32
+ # Used in auth2_file command
33
+ # @param [String] folder
34
+ def credentials_folder=(folder)
35
+ @credentials_folder = folder
36
+ end
71
37
 
72
- # -Deprecated- for favour of putting directly in Soaspec
73
- # Represents Environment parameters used in Soaspec tests
74
- module Environment
38
+ # Credentials folder used to store secret data (not in source control) E.g passwords
39
+ def credentials_folder
40
+ @credentials_folder
41
+ end
75
42
 
76
43
  # Used so that exchange class knows what context it's in
77
- def self.api_handler=(handler)
78
- Soaspec.api_handler = handler
44
+ # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
45
+ def api_handler=(handler)
46
+ @api_handler = handler
79
47
  end
80
48
 
81
- def self.api_handler
82
- Soaspec.api_handler
49
+ def api_handler
50
+ @api_handler
83
51
  end
84
52
 
85
- # Whether to transform strings to keys automatically
86
- def self.always_use_keys=(use_keys)
87
- Soaspec.always_use_keys = use_keys
53
+ # Set whether to transform strings to keys in request automatically
54
+ # @param [Boolean] use_keys
55
+ def always_use_keys=(use_keys)
56
+ @always_use_keys = use_keys
88
57
  end
89
58
 
90
- def self.always_use_keys?
91
- Soaspec.always_use_keys? || true
59
+ # @return [Boolean] Whether to transform strings to keys in request automatically
60
+ def always_use_keys?
61
+ @always_use_keys || true
92
62
  end
93
63
 
94
64
  # Whether to remove namespaces from response in Xpath assertion automatically
95
65
  # For why this may not be a good thing in general see
96
66
  # http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
97
67
  # This will be overridden if xpath has a ':' in it
98
- def self.strip_namespaces=(remove_namespaces_from_response)
99
- Soaspec.strip_namespaces = remove_namespaces_from_response
68
+ def strip_namespaces=(remove_namespaces)
69
+ @strip_namespaces = remove_namespaces
100
70
  end
101
71
 
102
72
  # Whether to remove namespaces in xpath assertion automatically
103
- def self.strip_namespaces?
104
- Soaspec.strip_namespaces? || false
105
- end
106
-
107
- end
108
-
109
- # Contains commonly used REST methods
110
- module RestMethods
111
- # Make REST Post Exchange
112
- # @param [String] name Name of test displayed
113
- # @param [Hash] params Exchange parameters
114
- # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
115
- def post(name, params = {})
116
- Exchange.new(name, method: :post, **params)
117
- end
118
-
119
- # Make REST Patch Exchange
120
- # @param [String] name Name of test displayed
121
- # @param [Hash] params Exchange parameters
122
- # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
123
- def patch(name, params = {})
124
- Exchange.new(name, method: :patch, **params)
125
- end
126
-
127
- # Make REST Put Exchange
128
- # @param [String] name Name of test displayed
129
- # @param [Hash] params Exchange parameters
130
- # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
131
- def put(name, params = {})
132
- Exchange.new(name, method: :put, **params)
133
- end
134
-
135
- # Make REST Get Exchange
136
- # @param [String] name Name of test displayed
137
- # @param [Hash] params Exchange parameters
138
- # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
139
- def get(name, params = {})
140
- Exchange.new(name, method: :get, **params)
141
- end
142
-
143
- # Make REST Delete Exchange
144
- # @param [String] name Name of test displayed
145
- # @param [Hash] params Exchange parameters
146
- # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
147
- def delete(name, params = {})
148
- Exchange.new(name, method: :delete, **params)
73
+ def strip_namespaces?
74
+ @strip_namespaces || false
149
75
  end
150
76
  end
151
-
152
77
  end
153
78
 
154
79
  RestClient.log = Soaspec::SpecLogger.create
@@ -3,6 +3,7 @@ require_relative '../soaspec'
3
3
  # This represents a request / response pair
4
4
  class Exchange
5
5
 
6
+ # Class of Api Handler for which this exchange is made
6
7
  attr_reader :api_class
7
8
  # How many times to retry for a success
8
9
  attr_accessor :retry_count
@@ -23,7 +24,7 @@ class Exchange
23
24
  # @param [Hash] override_parameters Parameters to override for default params
24
25
  def initialize(name, override_parameters = {})
25
26
  @test_name = name.to_s
26
- @api_class = Soaspec.api_handler
27
+ @api_class = Soaspec.api_handler # This uses the global parameter. The handler should be set straight before an exchange is made
27
28
  @override_parameters = override_parameters
28
29
  @retry_for_success = false
29
30
  self.retry_count = 3
@@ -37,7 +38,7 @@ class Exchange
37
38
  retry_count.times do
38
39
  response = @api_class.make_request(@override_parameters)
39
40
  return response unless retry_for_success?
40
- return response if @api_class.status_code_for(response) == 200
41
+ return response if (200..299).cover? @api_class.status_code_for(response)
41
42
  response
42
43
  end
43
44
  end
@@ -0,0 +1,45 @@
1
+
2
+ module Soaspec
3
+ # Contains commonly used REST methods
4
+ module RestMethods
5
+ # Make REST Post Exchange
6
+ # @param [String] name Name of test displayed
7
+ # @param [Hash] params Exchange parameters
8
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
9
+ def post(name, params = {})
10
+ Exchange.new(name, method: :post, **params)
11
+ end
12
+
13
+ # Make REST Patch Exchange
14
+ # @param [String] name Name of test displayed
15
+ # @param [Hash] params Exchange parameters
16
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
17
+ def patch(name, params = {})
18
+ Exchange.new(name, method: :patch, **params)
19
+ end
20
+
21
+ # Make REST Put Exchange
22
+ # @param [String] name Name of test displayed
23
+ # @param [Hash] params Exchange parameters
24
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
25
+ def put(name, params = {})
26
+ Exchange.new(name, method: :put, **params)
27
+ end
28
+
29
+ # Make REST Get Exchange
30
+ # @param [String] name Name of test displayed
31
+ # @param [Hash] params Exchange parameters
32
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
33
+ def get(name, params = {})
34
+ Exchange.new(name, method: :get, **params)
35
+ end
36
+
37
+ # Make REST Delete Exchange
38
+ # @param [String] name Name of test displayed
39
+ # @param [Hash] params Exchange parameters
40
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
41
+ def delete(name, params = {})
42
+ Exchange.new(name, method: :delete, **params)
43
+ end
44
+ end
45
+ end
@@ -1,8 +1,8 @@
1
1
  require 'rspec'
2
2
 
3
3
  shared_examples_for 'success scenario' do
4
- it 'has status code of 200' do
5
- expect(described_class.status_code).to eq 200
4
+ it 'has successful status code' do
5
+ expect(200..299).to cover described_class.status_code
6
6
  end
7
7
  context 'has expected mandatory elements' do
8
8
  described_class.api_class.expected_mandatory_elements.each do |mandatory_element|
@@ -21,6 +21,4 @@ shared_examples_for 'success scenario' do
21
21
  expect(described_class).to have_xpath_value(xpath => value)
22
22
  end
23
23
  end
24
-
25
-
26
- end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.46'
2
+ VERSION = '0.0.47'
3
3
  end
@@ -1,5 +1,5 @@
1
1
 
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path('lib', __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'soaspec/version'
5
5
 
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['SamuelGarrattIQA']
10
10
  spec.email = ['samuel.garratt@integrationqa.com']
11
11
 
12
- spec.summary = %q{Helps to create RSpec specs for SOAP or REST apis }
13
- spec.description = %q{Helps to create RSpec specs for SOAP or REST apis. Easily represent multiple requests with
14
- the same configuration }
12
+ spec.summary = "Helps to create RSpec specs for 'SOAP' or 'REST' apis "
13
+ spec.description = "Helps to create RSpec specs for 'SOAP' or 'REST' apis. Easily represent multiple requests with
14
+ the same configuration "
15
15
  spec.homepage = 'https://gitlab.com/samuel-garratt/soaspec'
16
16
  spec.license = 'MIT'
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.46
4
+ version: 0.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.1.5
139
- description: "Helps to create RSpec specs for SOAP or REST apis. Easily represent
139
+ description: "Helps to create RSpec specs for 'SOAP' or 'REST' apis. Easily represent
140
140
  multiple requests with\nthe same configuration "
141
141
  email:
142
142
  - samuel.garratt@integrationqa.com
@@ -171,6 +171,7 @@ files:
171
171
  - lib/soaspec/exchange.rb
172
172
  - lib/soaspec/exchange_handlers/exchange_handler.rb
173
173
  - lib/soaspec/exchange_handlers/rest_handler.rb
174
+ - lib/soaspec/exchange_handlers/rest_methods.rb
174
175
  - lib/soaspec/exchange_handlers/soap_handler.rb
175
176
  - lib/soaspec/exe_helpers.rb
176
177
  - lib/soaspec/hash_methods.rb
@@ -209,5 +210,5 @@ rubyforge_project:
209
210
  rubygems_version: 2.6.14
210
211
  signing_key:
211
212
  specification_version: 4
212
- summary: Helps to create RSpec specs for SOAP or REST apis
213
+ summary: Helps to create RSpec specs for 'SOAP' or 'REST' apis
213
214
  test_files: []