rest_api_builder 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 2e0a07766b5d80c9e2913f70d5004cf946a3c01eb08ea9f43f4c36961122f441
4
- data.tar.gz: 7be95767413d7fa4ce3f881282ff75b1c575353ef9fe5522e85c6936eac5d303
3
+ metadata.gz: dd44f147795470f5d2665d31c027f845fccf9430e925fbae1a2e070037637f8a
4
+ data.tar.gz: 8f9a34b3768349a1e8ec837cd2739b6c997766adee3910a6d7518084eed6e13d
5
5
  SHA512:
6
- metadata.gz: 45531bd762b6039b93f63306be50ada5b880099e04f1c9c59ffbbbca457b790fc2b3f032899b9dfdd65b469e7be319b052d8b024f035d2f0dd82e5e44dc96a1a
7
- data.tar.gz: b75b1bfc01db61ebd28bc50200a0ec3c18f487819515e9cf558db7f4411fdd4a58d5039addaab209ba2896ba48160e2439a0f9fb6c4aa90c0b6af32780bd02f4
6
+ metadata.gz: 23e78a1b9a9e16c120515e389857366b3093ba776b2c329610fa3ef684d302dce82ca5018476ca3381b4edd5fc4cf9c31532e715fa34f347ae30822170f0ea60
7
+ data.tar.gz: fde6a4d5c6fb9fcbb3caeba61720b68f0867492052d566370488f706ec199eef0759937e3ae10e4efa9074a497ee666c85c1c365f49c37732bcfe2e342639f06
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -132,9 +132,9 @@ Expectations.expect_execute(
132
132
  base_url: "test.com",
133
133
  method: :post,
134
134
  response: { body: 'hello' },
135
- request: { body: WebMock::API.hash_including({foo: "bar"}) }
135
+ request: { body: { foo: "bar" } } # body will be matched partially using hash_including matcher
136
136
  )
137
- response = my_request.json_execute(base_url: "test.com", method: :post, body: {foo: "bar"})
137
+ response = my_request.json_execute(base_url: "test.com", method: :post, body: { foo: "bar", bar: "baz" })
138
138
  response[:success] #=> true
139
139
  response[:body] #=> 'hello'
140
140
 
@@ -184,13 +184,13 @@ Returns ruby hash with `:success` and `:raw_response` keys.
184
184
 
185
185
  ## WebMockRequestExpectations API
186
186
  ### RestAPIBuilder::WebMockRequestExpectations.expect_execute(options)
187
- Defines a request expectation using WebMock's `stub_request`. Returns an instance of `WebMock::RequestStub` on which methods such as `with`, `to_return`, `to_timeout` can be called
187
+ Defines a request expectation using WebMock's `stub_request`. Returns an instance of `WebMock::RequestStub` on which methods such as `with`, `to_return`, `to_timeout` can be called.
188
188
 
189
189
  #### Options:
190
190
  * **base_url**: Base URL of the request. Required.
191
191
  * **method**: HTTP method of the request(e.g :get, :post, :patch). Required.
192
192
  * **path**: Path to be appended to the :base_url. Optional.
193
- * **request**: request details which will be passed to `WebMock::RequestStub#with` if provided. Optional
193
+ * **request**: request details which will be passed to `WebMock::RequestStub#with` if provided. If `query` or `body` keys are present and are hashes, they will be converted into WebMock's `hash_including` matcher. Optional
194
194
  * **response**: response details which will be passed to `WebMock::RequestStub#to_return` if provided. Optional
195
195
 
196
196
  ### RestAPIBuilder::WebMockRequestExpectations.expect_json_execute(options)
File without changes
File without changes
File without changes
File without changes
@@ -17,11 +17,27 @@ module RestAPIBuilder
17
17
  def expect_execute(base_url:, method:, path: nil, request: nil, response: nil)
18
18
  expectation = stub_request(method, full_url(base_url, path))
19
19
 
20
- expectation.with(request) if request
20
+ if !request.nil? && request.any?
21
+ add_request_expectations(expectation, request)
22
+ end
23
+
21
24
  expectation.to_return(response) if response
22
25
 
23
26
  expectation
24
27
  end
28
+
29
+ def add_request_expectations(expectation, request)
30
+ if request[:body].is_a?(Hash)
31
+ request = request.merge(body: hash_including(request[:body]))
32
+ end
33
+
34
+ if request[:query].is_a?(Hash)
35
+ query = request[:query].transform_values(&:to_s)
36
+ request = request.merge(query: hash_including(query))
37
+ end
38
+
39
+ expectation.with(request)
40
+ end
25
41
  end
26
42
 
27
43
  WebMockRequestExpectations = WebMockRequestExpectationsSingleton.new
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rest_api_builder'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.summary = "A simple wrapper for rest-client"
5
5
  s.description = "A simple wrapper for rest-client aiming to make creation and testing of API clients easier."
6
6
  s.authors = ["Alexey D"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_api_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey D
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.7.8
89
+ rubygems_version: 3.1.2
91
90
  signing_key:
92
91
  specification_version: 4
93
92
  summary: A simple wrapper for rest-client