Class: Conduit::Core::RequestMocker
- Inherits:
-
Object
- Object
- Conduit::Core::RequestMocker
- Defined in:
- lib/conduit/core/request_mocker.rb
Instance Method Summary collapse
-
#initialize(base, options = nil) ⇒ RequestMocker
constructor
A new instance of RequestMocker.
-
#mock ⇒ Object
Starts mocking, override if using something different than excon to make the requests.
-
#unmock ⇒ Object
Ends mocking, override if using something different than excon to make the requests.
-
#with_mocking ⇒ Object
Wraps the block inside a mocking state.
Constructor Details
#initialize(base, options = nil) ⇒ RequestMocker
Returns a new instance of RequestMocker.
20 21 22 23 24 25 |
# File 'lib/conduit/core/request_mocker.rb', line 20 def initialize(base, = nil) @base = base @options = @mock_status = [:mock_status].to_sym || :success @http_status = [:http_status] || 200 end |
Instance Method Details
#mock ⇒ Object
Starts mocking, override if using something different than excon to make the requests.
30 31 32 33 |
# File 'lib/conduit/core/request_mocker.rb', line 30 def mock Excon.defaults[:mock] = true Excon.stub({}, body: response, status: @http_status) end |
#unmock ⇒ Object
Ends mocking, override if using something different than excon to make the requests.
38 39 40 41 |
# File 'lib/conduit/core/request_mocker.rb', line 38 def unmock Excon.defaults[:mock] = false Excon.stubs.clear end |
#with_mocking ⇒ Object
Wraps the block inside a mocking state.
45 46 47 |
# File 'lib/conduit/core/request_mocker.rb', line 45 def with_mocking mock and yield.tap { unmock } end |