Class: StubRequests::WebMockBuilder
- Includes:
- HashUtil
- Defined in:
- lib/stub_requests/webmock_builder.rb
Overview
Note:
This module can either be used by its class methods or included in say RSpec
Module API abstraction to reduce the amount of WebMock.stub_request
Instance Attribute Summary collapse
- #callback ⇒ Object readonly
- #options ⇒ Object readonly
- #request_stub ⇒ Object readonly
Class Method Summary collapse
-
.build(verb, uri, options = {}) { ... } ⇒ WebMock::RequestStub
Builds and registers a WebMock::RequestStub.
Instance Method Summary collapse
-
#build ⇒ WebMock::RequestStub
Prepares a WebMock::RequestStub and registers it in WebMock.
-
#initialize(verb, uri, options = {}) { ... } ⇒ WebMockBuilder
constructor
Initializes a new instance of.
Methods included from HashUtil
Constructor Details
#initialize(verb, uri, options = {}) { ... } ⇒ WebMockBuilder
Initializes a new instance of
58 59 60 61 62 |
# File 'lib/stub_requests/webmock_builder.rb', line 58 def initialize(verb, uri, = {}, &callback) @request_stub = WebMock::RequestStub.new(verb, uri) @options = @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
46 47 48 |
# File 'lib/stub_requests/webmock_builder.rb', line 46 def callback @callback end |
#options ⇒ Object (readonly)
42 43 44 |
# File 'lib/stub_requests/webmock_builder.rb', line 42 def @options end |
#request_stub ⇒ Object (readonly)
38 39 40 |
# File 'lib/stub_requests/webmock_builder.rb', line 38 def request_stub @request_stub end |
Class Method Details
.build(verb, uri, options = {}) { ... } ⇒ WebMock::RequestStub
Builds and registers a WebMock::RequestStub
31 32 33 |
# File 'lib/stub_requests/webmock_builder.rb', line 31 def self.build(verb, uri, = {}, &callback) new(verb, uri, , &callback).build end |
Instance Method Details
#build ⇒ WebMock::RequestStub
Prepares a WebMock::RequestStub and registers it in WebMock
70 71 72 73 74 75 76 77 78 |
# File 'lib/stub_requests/webmock_builder.rb', line 70 def build if callback.present? Docile.dsl_eval(request_stub, &callback) else prepare_mock_request end WebMock::StubRegistry.instance.register_request_stub(request_stub) end |