Class: RatHoleTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- RatHoleTest
- Defined in:
- lib/rat_hole_test.rb
Instance Method Summary collapse
- #normalize_headers(headers) ⇒ Object
-
#test_nothing ⇒ Object
make autotest happy.
- #through_the(rathole_klass, host, uri = '/', headers = {}) {|raw_response, app_response| ... } ⇒ Object
Instance Method Details
#normalize_headers(headers) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rat_hole_test.rb', line 23 def normalize_headers(headers) new_headers = headers.inject({}){|h,e| k,v = e # the value of these headers changes v = nil if k =~ /cookie|date|runtime|last-modified/i # skip headers that rat-hole removes unless k =~ /transfer/i v = v.first if v.is_a?(Array) && v.size == 1 #normalize things h.merge!(k => v) end h } headers.replace(new_headers) end |
#test_nothing ⇒ Object
make autotest happy
38 39 |
# File 'lib/rat_hole_test.rb', line 38 def test_nothing #make autotest happy end |
#through_the(rathole_klass, host, uri = '/', headers = {}) {|raw_response, app_response| ... } ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rat_hole_test.rb', line 4 def through_the(rathole_klass, host, uri='/', headers={}) app = Rack::Builder.new do use Rack::ShowExceptions use Rack::ShowStatus run rathole_klass.new(host) end app_response = Rack::MockRequest.new(app).get(uri, headers) raw_response = Net::HTTP.start(host) do |http| http.get(uri, headers) end # Wrap raw_response in Rack::Response to make things easier to work with. raw_headers = raw_response.to_hash raw_response = Rack::Response.new(raw_response.body, raw_response.code, raw_headers) normalize_headers(raw_response.headers) normalize_headers(app_response.headers) yield(raw_response, app_response) end |