Class: RestAPIBuilder::WebMockRequestExpectationsSingleton
- Inherits:
-
Object
- Object
- RestAPIBuilder::WebMockRequestExpectationsSingleton
- Includes:
- UrlHelper, WebMock::API
- Defined in:
- lib/rest_api_builder/webmock_request_expectations.rb
Instance Method Summary collapse
- #add_request_expectations(expectation, request) ⇒ Object
- #expect_execute(base_url:, method:, path: nil, request: nil, response: nil) ⇒ Object
- #expect_json_execute(response: nil, **options) ⇒ Object
Methods included from UrlHelper
Instance Method Details
#add_request_expectations(expectation, request) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rest_api_builder/webmock_request_expectations.rb', line 30 def add_request_expectations(expectation, request) if request[:body].is_a?(Hash) request = request.merge(body: hash_including(request[:body])) end if request[:query].is_a?(Hash) query = request[:query].transform_values(&:to_s) request = request.merge(query: hash_including(query)) end expectation.with(request) end |
#expect_execute(base_url:, method:, path: nil, request: nil, response: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rest_api_builder/webmock_request_expectations.rb', line 17 def expect_execute(base_url:, method:, path: nil, request: nil, response: nil) url = path.is_a?(Regexp) ? /#{base_url}#{path}/ : full_url(base_url, path) expectation = stub_request(method, url) if !request.nil? && request.any? add_request_expectations(expectation, request) end expectation.to_return(response) if response expectation end |
#expect_json_execute(response: nil, **options) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rest_api_builder/webmock_request_expectations.rb', line 9 def expect_json_execute(response: nil, **) if response && response[:body] response = response.merge(body: JSON.generate(response[:body])) end expect_execute(**, response: response) end |