soaspec 0.1.17 → 0.1.18
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 +4 -4
- data/ChangeLog +6 -0
- data/README.md +54 -9
- data/Todo.md +3 -1
- data/lib/soaspec/exchange.rb +3 -0
- data/lib/soaspec/exchange_handlers/rest_handler.rb +2 -0
- data/lib/soaspec/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d67dcecc12aa7ed80c4064617ae5b4edf939c38
|
4
|
+
data.tar.gz: d38ea5011a5668761890aa5b66b93e8703f385cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 445f7ce4e2883bbbe784a9e2b672860f90f68c46ad9b3b2e39659efd6c81375b646fe51a5b147df5b30e807f08628b52d6a276031314901519e7d9fe1f5dbd43
|
7
|
+
data.tar.gz: 8531ebc72ae98481f5d2b701b6ef719cc8ad77a94297b33469cdcb3a7ada81e4a11f21b5075e05d2e7c83bd81fe5a173fcfe520179abaa2c68fb275d5da4f24c
|
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Version 0.1.18
|
2
|
+
* Enhancements
|
3
|
+
* Define 'exchange' method on response object so original exchange can be accessed
|
4
|
+
* Make simply approach for setting body of request with just a string passed `ExchangeHandler.post(message_body)` where message_body is not
|
5
|
+
a `Hash` but a `String`
|
6
|
+
|
1
7
|
Version 0.1.17
|
2
8
|
* Enhancements
|
3
9
|
* Added Wait class to easily wait for an expected condition to be true, either using global Soaspec::Wait or `exchange.until { true }`
|
data/README.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Soaspec
|
2
2
|
|
3
|
-
This gem helps to represent multiple API tests against a backend briefly, concisely and clearly.
|
3
|
+
This gem helps to represent multiple API tests against a backend briefly, concisely and clearly.
|
4
|
+
It is essentially a wrapper around the Savon and RestClient gems, adding useful functionality including
|
5
|
+
|
6
|
+
* Creating multiple API calls from the same base configuration through the use of an `ExchangeHandler`
|
7
|
+
* Extracting values from response body's through either `XPath` or `JSONPath`
|
8
|
+
* Building up a custom RSpec `success scenario` shared example to repeatedly writing the same tests
|
9
|
+
* Methods making setting and extracting values from a `Request/Response` pair (`Exchange`) easy
|
10
|
+
* Waiting for a particular response from an API by polling it
|
11
|
+
* Way of abstracting paths to values from a response with business-meaningful method names
|
12
|
+
* Generating initial code for an API with `soaspec new`
|
13
|
+
* Way of accessing and using an `oauth2` access token
|
14
|
+
* Hosting a `virtual_server` that simulates REST & SOAP responses from an API
|
4
15
|
|
5
16
|
[](https://gitlab.com/samuel-garratt/soaspec/pipelines)
|
6
17
|
[](https://samuel-garratt.gitlab.io/soaspec)
|
@@ -49,28 +60,46 @@ You can also use `soaspec generate` to generate a set of tests from a WSDL. This
|
|
49
60
|
for such defaults. When describing an API override this in 'savon_options' method
|
50
61
|
* REST - this uses the resource class from the Rest-Client gem behind the scenes.
|
51
62
|
|
52
|
-
See specs for example of usage.
|
63
|
+
See [specs](specs) and [features](features) for example of usage.
|
53
64
|
|
54
|
-
|
65
|
+
### ExchangeHandler
|
66
|
+
|
67
|
+
To start with a class inheriting from a ‘Handler’ class for each web service that’s tested needs to be created.
|
55
68
|
In this class you define the common parameters used for testing this class.
|
56
69
|
|
57
70
|
For example:
|
58
71
|
|
59
72
|
```ruby
|
73
|
+
# Classes are set up through inheriting from either `Soaspec::RestHandler` or `Soaspec::SoapHandler`
|
60
74
|
class PuppyService < Soaspec::RestHandler
|
61
75
|
|
62
|
-
headers accept: 'application/json', content_type: 'application/json'
|
76
|
+
headers accept: 'application/json', content_type: 'application/json' # Set default headers for all `Exchanges` using this class
|
63
77
|
|
64
|
-
base_url 'http://petstore.swagger.io/v2/pet'
|
78
|
+
base_url 'http://petstore.swagger.io/v2/pet' # URL for which all requests using this class will start with
|
65
79
|
|
66
|
-
element :id, :id
|
67
|
-
element :category_id, '$..category.id'
|
80
|
+
element :id, :id # Define a method 'id' that can be obtained with either XPATH '//id' or JSONPath '$..id'
|
81
|
+
element :category_id, '$..category.id' # Define method to obtain a category id through JSON Path
|
68
82
|
end
|
69
83
|
```
|
70
84
|
|
85
|
+
### Exchange
|
86
|
+
|
71
87
|
Then you reference this class in creating `Exchange`’s (representing a request / response pair).
|
72
88
|
Upon initialization of the Exchange object or later on through setters, parameters specific to this request are set
|
73
89
|
All getters of the Exchange are on the response & will implicitly trigger the API request to be made.
|
90
|
+
Once this request has been made, all following accessors of the response will just use the previous request made.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
exchange = PuppyService.post(body: { status: 'sold' }) # The 'body' key will convert it's value from a Hash to JSON
|
94
|
+
# Create a new Exchange that will post to 'http://petstore.swagger.io/v2/pet' with JSON { "status": "sold" }
|
95
|
+
exchange.category_id
|
96
|
+
# This will trigger the request to be made & return a value at JSON path $..category.id, throwing an exception if not found
|
97
|
+
```
|
98
|
+
|
99
|
+
See [Request Body Parameters](wikis/RequestBodyParameters) for more details on setting a request body.
|
100
|
+
See [Creating an Exchange](wikis/CreatingExchange) for details on how to create an Exchange.
|
101
|
+
|
102
|
+
### RSpec
|
74
103
|
|
75
104
|
For example:
|
76
105
|
|
@@ -82,9 +111,9 @@ context PuppyService.new('Order Puppies') do
|
|
82
111
|
end
|
83
112
|
```
|
84
113
|
|
85
|
-
|
114
|
+
#### Tips
|
86
115
|
|
87
|
-
If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
|
116
|
+
If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
|
88
117
|
backtrace.
|
89
118
|
|
90
119
|
RSpec.configure do |config|
|
@@ -94,6 +123,22 @@ RSpec.configure do |config|
|
|
94
123
|
]
|
95
124
|
end
|
96
125
|
|
126
|
+
### Cucumber
|
127
|
+
|
128
|
+
If you're using `Cucumber` then I would recommend the following
|
129
|
+
|
130
|
+
In the `Given` (or background) specify the `Exchange` object.
|
131
|
+
Either store this as an instance variable (e.g `@exchange`) or use the global `Soaspec.last_exchange`
|
132
|
+
|
133
|
+
In the `When` use the `call` method to make the request `@exchange.call`
|
134
|
+
|
135
|
+
In the `Then` make the assertions from the `@exchange` object.
|
136
|
+
E.g
|
137
|
+
```ruby
|
138
|
+
expect(@exchange['message']).to include 'success'
|
139
|
+
expect(@exchange.status_code).to eq true
|
140
|
+
```
|
141
|
+
|
97
142
|
## Development
|
98
143
|
|
99
144
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Todo.md
CHANGED
@@ -7,5 +7,7 @@
|
|
7
7
|
* Give examples and convenience methods for building classes for each SOAP or REST operation
|
8
8
|
* Potentially have in built use of 'vcr' and 'http_stub' gems
|
9
9
|
* Handle proxies to record traffic for MiddleWare testing
|
10
|
-
*
|
10
|
+
* soaspec generate
|
11
|
+
* Get wsdl generator working for non complex gems (Put on hold til new Savon version)
|
12
|
+
* Generate from a RAML
|
11
13
|
* Much more - please raise an issue for suggestion
|
data/lib/soaspec/exchange.rb
CHANGED
@@ -148,9 +148,12 @@ class Exchange
|
|
148
148
|
# @example For SOAP it will be a Savon response
|
149
149
|
# response.body (body of response as Hash)
|
150
150
|
# response.header (head of response as Hash)
|
151
|
+
# @example For REST it will be a RestClient::Response
|
151
152
|
def response
|
152
153
|
Soaspec.last_exchange = self
|
153
154
|
@response ||= make_request
|
155
|
+
@response.define_singleton_method(:exchange) { Soaspec.last_exchange } unless @response.respond_to?(:exchange)
|
156
|
+
@response
|
154
157
|
end
|
155
158
|
|
156
159
|
alias call response
|
data/lib/soaspec/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.18
|
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-
|
11
|
+
date: 2018-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|