Class: Koine::RestClient::MockBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/koine/rest_client/rspec_mock_client.rb

Overview

mock builder

Instance Method Summary collapse

Constructor Details

#initialize(mock) ⇒ MockBuilder

Returns a new instance of MockBuilder.



123
124
125
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 123

def initialize(mock)
  @mock = mock
end

Instance Method Details

#on_error(&block) ⇒ Object



143
144
145
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 143

def on_error(&block)
  @error_handler = block
end

#will_return(body: {}, code: 200) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 132

def will_return(body: {}, code: 200)
  response = MockResponse.new
  response.parsed_response = body
  response.code = code
  if block_given?
    response = yield(response)
  end
  @mock.and_return(response)
  self
end

#with(*args) ⇒ Object



127
128
129
130
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 127

def with(*args)
  @mock.with(*args)
  self
end