Class: Net::HTTP::Persistent

Inherits:
Object
  • Object
show all
Defined in:
lib/gmail_contacts/test_stub.rb

Overview

:startdoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stub_dataObject

Accessor for data the stub will return



214
215
216
# File 'lib/gmail_contacts/test_stub.rb', line 214

def stub_data
  @stub_data
end

#stub_urlsObject

Accessor for URLs the stub accessed



219
220
221
# File 'lib/gmail_contacts/test_stub.rb', line 219

def stub_urls
  @stub_urls
end

Instance Method Details

#old_requestObject



221
# File 'lib/gmail_contacts/test_stub.rb', line 221

alias old_request request

#request(url) ⇒ Object

Fetches url, records in stub_urls, and returns data if there’s still data in stub_data, or raises an exception



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/gmail_contacts/test_stub.rb', line 227

def request(url)
  @stub_urls << url.to_s
  raise 'stub data empty' if @stub_data.empty?

  data = @stub_data.shift

  return data.call if Proc === data

  res = Net::HTTPOK.new nil, '200', 'OK'
  def res.body() @data end
  res.instance_variable_set :@data, data
  res
end

#stub_resetObject

Resets the stub to empty



244
245
246
247
# File 'lib/gmail_contacts/test_stub.rb', line 244

def stub_reset
  @stub_urls = []
  @stub_data = []
end