soaspec 0.1.17 → 0.1.18

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: 1f25cdd5470680bb035c2296f5b29dba6afe1aef
4
- data.tar.gz: 7a0b0c4c47d201e2025e8bd702ef208c701c410b
3
+ metadata.gz: 2d67dcecc12aa7ed80c4064617ae5b4edf939c38
4
+ data.tar.gz: d38ea5011a5668761890aa5b66b93e8703f385cc
5
5
  SHA512:
6
- metadata.gz: 5f843a8d1775bf6149e398008197225ada75c282693f543ec819ca3cab14d4267316a930256523686bfbef2470d723d0cfc1b45a278e46ded94b07ef5778051a
7
- data.tar.gz: 03b8333eddee14dcd7d65415bf390c571fe2079c4f77ec410385d5fde7b101e7dd65cc69309661a67df0ccfbfca413df5729b86fe697b2a8ec1499df62509361
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. It is essentially a wrapper around the Savon and RestClient gems. Note it is still in early stages of development.
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
  [![Build Status](https://gitlab.com/samuel-garratt/soaspec/badges/master/build.svg)](https://gitlab.com/samuel-garratt/soaspec/pipelines)
6
17
  [![Coverage](https://gitlab.com/samuel-garratt/soaspec/badges/master/coverage.svg)](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. This will be added to later.
63
+ See [specs](specs) and [features](features) for example of usage.
53
64
 
54
- Basically you create a class inheriting from a ‘Handler’ class for each web service that’s tested.
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
- ### Recommended
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
- * Get wsdl generator working for non complex gems (Put on hold til new Savon version)
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
@@ -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
@@ -285,6 +285,8 @@ module Soaspec
285
285
  params = case rest_method
286
286
  when 'get', 'delete'
287
287
  { suburl: params.to_s }
288
+ when 'post', 'put', 'patch'
289
+ { payload: params.to_s }
288
290
  else
289
291
  params
290
292
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.1.17'.freeze
2
+ VERSION = '0.1.18'.freeze
3
3
  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.17
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-15 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler