Class: Conduit::Core::RequestMocker

Inherits:
Object
  • Object
show all
Defined in:
lib/conduit/core/request_mocker.rb

Instance Method Summary collapse

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, options = nil)
  @base = base
  @options = options
  @mock_status = options[:mock_status].to_sym || :success
  @http_status = options[:http_status] || 200
end

Instance Method Details

#mockObject

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

#unmockObject

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_mockingObject

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