spec/proxy_spec.rb in em-proxy-0.1.2 vs spec/proxy_spec.rb in em-proxy-0.1.3

- old
+ new

@@ -24,15 +24,17 @@ it "should call the on_connect callback" do connected = false EM.run do EventMachine.add_timer(0.1) do - EventMachine::HttpRequest.new('http://127.0.0.1:8080/test').get({:timeout => 1}) + EventMachine::HttpRequest.new('http://127.0.0.1:8080/').get({:timeout => 1}) end Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn| - conn.on_connect do + conn.server :goog, :host => "google.com", :port => 80 + + conn.on_connect do |name| connected = true EventMachine.stop end end end @@ -60,11 +62,11 @@ end it "should duplex TCP traffic to two backends google & yahoo" do EM.run do EventMachine.add_timer(0.1) do - EventMachine::HttpRequest.new('http://127.0.0.1:8080/').get({:timeout => 1}) + EventMachine::HttpRequest.new('http://127.0.0.1:8080/test').get({:timeout => 1}) end Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn| conn.server :goog, :host => "google.com", :port => 80 conn.server :yhoo, :host => "yahoo.com", :port => 80 @@ -72,14 +74,14 @@ seen = [] conn.on_response do |backend, resp| case backend when :goog then - resp.should =~ /google/ + resp.should =~ /404/ seen.push backend when :yhoo - resp.should =~ /yahoo|yimg/ + resp.should =~ /404/ seen.push backend end seen.uniq! EventMachine.stop if seen.size == 2 @@ -132,16 +134,16 @@ EM.run do EventMachine.add_timer(0.1) do http =EventMachine::HttpRequest.new('http://127.0.0.1:8080/').get({:timeout => 1}) http.callback { EventMachine.stop } end - + Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn| conn.server :goog, :host => "google.com", :port => 80, :relay_client => true conn.on_data { |data| raise "Should not be here"; data } conn.on_response { |backend, resp| resp } - + end end }.should_not raise_error end @@ -150,15 +152,15 @@ EM.run do EventMachine.add_timer(0.1) do http =EventMachine::HttpRequest.new('http://127.0.0.1:8080/').get({:timeout => 1}) http.callback { EventMachine.stop } end - + Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn| conn.server :goog, :host => "google.com", :port => 80, :relay_server => true conn.on_data { |data| data } conn.on_response { |backend, resp| raise "Should not be here"; } - + end end }.should_not raise_error end end \ No newline at end of file