Class: RestAPIBuilder::WebMockRequestExpectationsSingleton

Inherits:
Object
  • Object
show all
Includes:
UrlHelper, WebMock::API
Defined in:
lib/rest_api_builder/webmock_request_expectations.rb

Instance Method Summary collapse

Methods included from UrlHelper

#full_url

Instance Method Details

#expect_execute(base_url:, method:, path: nil, request: nil, response: nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/rest_api_builder/webmock_request_expectations.rb', line 17

def expect_execute(base_url:, method:, path: nil, request: nil, response: nil)
  expectation = stub_request(method, full_url(base_url, path))

  expectation.with(request) if request
  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, **options)
  if response && response[:body]
    response = response.merge(body: JSON.generate(response[:body]))
  end

  expect_execute(**options, response: response)
end