Module: APISmith::WebMockExtensions
- Defined in:
- lib/api_smith/web_mock_extensions.rb
Overview
A set of extensions to make using APISmith with WebMock (or most test utilities in general) simpler when it comes checking values. Please note this is primarily intended for use with rspec due to dependence on subject in some places.
Instance Method Summary collapse
-
#api_url_for(path) ⇒ String
Expands the given path relative to the API for the current subject class.
-
#stub_api(type, path) ⇒ Object
Short hand for #stub_request that lets you give it a relative path prior to expanding it.
-
#subject_api_class ⇒ Class
Returns the class of the current subject.
-
#subject_class_instance ⇒ Object
Returns an instance of the subject class, created via allocate (vs. new).
Instance Method Details
#api_url_for(path) ⇒ String
Expands the given path relative to the API for the current subject class. Namely, this makes it possible to convert a relative path to an endpoint-specified path.
27 28 29 30 31 |
# File 'lib/api_smith/web_mock_extensions.rb', line 27 def api_url_for(path) path = subject_class_instance.send(:path_for, path) base_uri = subject_api_class.base_uri File.join base_uri, path end |
#stub_api(type, path) ⇒ Object
Short hand for #stub_request that lets you give it a relative path prior to expanding it.
37 38 39 |
# File 'lib/api_smith/web_mock_extensions.rb', line 37 def stub_api(type, path) stub_request(type, api_url_for(path)) end |
#subject_api_class ⇒ Class
Returns the class of the current subject
12 13 14 |
# File 'lib/api_smith/web_mock_extensions.rb', line 12 def subject_api_class subject.is_a?(Class) ? subject : subject.class end |
#subject_class_instance ⇒ Object
Returns an instance of the subject class, created via allocate (vs. new)
18 19 20 |
# File 'lib/api_smith/web_mock_extensions.rb', line 18 def subject_class_instance @subject_class_instance ||= subject_api_class.allocate end |