Class: ProxyTest::TestCase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/proxytest/testcase.rb

Instance Method Summary collapse

Instance Method Details

#expect(method, path) {|mock_res, mock_req| ... } ⇒ Object

Yields:

  • (mock_res, mock_req)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/proxytest/testcase.rb', line 7

def expect(method, path, &block)
  # Create stub objects for the response and the request
  url = URI.parse("http://#{::ProxyTest::Config.proxy_host}:#{::ProxyTest::Config.proxy_port}")
  mock_req = requester(method).new(path)
  mock_res = ::ProxyTest::Response.new

  yield(mock_res, mock_req)

  # Pass the response into the http server
  q.enq(mock_res.to_http)

  # TODO Configurable port
  real_res = Net::HTTP.start(url.host,url.port) do |http|
    http.request(mock_req)
  end

  real_req = q.deq

  [real_res, real_req]
end

#get(path, hdr, &block) ⇒ Object



44
45
46
# File 'lib/proxytest/testcase.rb', line 44

def get(path, hdr, &block)
  @paths << [path, hdr, block]
end

#pathsObject



48
49
50
# File 'lib/proxytest/testcase.rb', line 48

def paths
  @paths ||= Array.new
end

#qObject



3
4
5
# File 'lib/proxytest/testcase.rb', line 3

def q
  ::ProxyTest::SingletonQueue.get
end

#requester(sym) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/proxytest/testcase.rb', line 28

def requester(sym)
  case sym
  when :get
    Net::HTTP::Get
  when :post
    Net::HTTP::Post
  when :put
    Net::HTTP::Put
  when :head
    Net::HTTP::Head
  else
    raise "Unsupported HTTP verb"
  end
end