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.
29 30 31 32 33 |
# File 'lib/api_smith/web_mock_extensions.rb', line 29 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.
39 40 41 |
# File 'lib/api_smith/web_mock_extensions.rb', line 39 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). Useful for giving access to utility methods used inside of the class without having to\ initialize a new client.
20 21 22 |
# File 'lib/api_smith/web_mock_extensions.rb', line 20 def subject_class_instance @subject_class_instance ||= subject_api_class.allocate end |