Class: Handsoap::Http::Drivers::MockDriver

Inherits:
AbstractDriver show all
Defined in:
lib/handsoap/http/drivers/mock_driver.rb

Overview

A mock driver for your testing needs.

To use it, create a new instance and assign to Handsoap::Http.drivers. Then configure Handsoap::Service to use it:

Handsoap::Http.drivers[:mock] = Handsoap::Http::Drivers::MockDriver.new :status => 200, :headers => headers, :content => body
Handsoap.http_driver = :mock

Remember that headers should use rn, rather than n.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractDriver

load!, #parse_headers, #parse_http_part, #parse_multipart, #parse_multipart_boundary

Constructor Details

#initialize(mock) ⇒ MockDriver

Returns a new instance of MockDriver



18
19
20
21
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 18

def initialize(mock)
  @mock = mock
  @is_loaded = false
end

Instance Attribute Details

#is_loadedObject

Returns the value of attribute is_loaded



16
17
18
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 16

def is_loaded
  @is_loaded
end

#last_requestObject

Returns the value of attribute last_request



16
17
18
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 16

def last_request
  @last_request
end

#mockObject

Returns the value of attribute mock



16
17
18
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 16

def mock
  @mock
end

Instance Method Details

#load!Object



23
24
25
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 23

def load!
  is_loaded = true
end

#newObject



27
28
29
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 27

def new
  self
end

#send_http_request(request) ⇒ Object



31
32
33
34
35
# File 'lib/handsoap/http/drivers/mock_driver.rb', line 31

def send_http_request(request)
  @last_request = request
  (mock.kind_of? Hash) ?
    parse_http_part(mock[:headers], mock[:content], mock[:status], mock[:content_type]) : mock
end