Class: MockHttpSend

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

Instance Method Summary collapse

Constructor Details

#initialize(mockfile) ⇒ MockHttpSend

Returns a new instance of MockHttpSend.



2
3
4
# File 'lib/mock_http_send.rb', line 2

def initialize(mockfile)
  @mock_results = JSON.parse(File.open(mockfile).read)
end

Instance Method Details

#send(url, method, headers = nil, body = nil) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/mock_http_send.rb', line 6

def send(url, method, headers=nil, body = nil)
  @mock_results.each { |result|
    if result["url"] == url && result["method"] == method.to_s
      return result["response_code"], result["response_body"]
    end
  }
  return -1, "unable to find match for #{url},#{method} in mock file"
end