require 'rubygems' require 'spec' require 'pp' require 'lib/em-http' require 'lib/em-http/mock' describe 'em-http mock' do before(:each) do EM::HttpRequest.reset_registry! EM::HttpRequest.reset_counts! end it "should serve a fake http request from a file" do EM::HttpRequest.register_file('http://www.google.ca:80/', :get, File.join(File.dirname(__FILE__), 'fixtures', 'google.ca')) EM.run do http = EM::HttpRequest.new('http://www.google.ca/').get http.callback do http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca')).split("\n\n", 2).last EM.stop end http.errback do fail EM.stop end end EM::HttpRequest.count('http://www.google.ca:80/', :get).should == 1 end it "should serve a fake http request from a string" do data = <<-HEREDOC HTTP/1.0 200 OK Date: Mon, 16 Nov 2009 20:39:15 GMT Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 Set-Cookie: PREF=ID=9454187d21c4a6a6:TM=1258403955:LM=1258403955:S=2-mf1n5oV5yAeT9-; expires=Wed, 16-Nov-2011 20:39:15 GMT; path=/; domain=.google.ca Set-Cookie: NID=28=lvxxVdiBQkCetu_WFaUxLyB7qPlHXS5OdAGYTqge_laVlCKVN8VYYeVBh4bNZiK_Oan2gm8oP9GA-FrZfMPC3ZMHeNq37MG2JH8AIW9LYucU8brOeuggMEbLNNXuiWg4; expires=Tue, 18-May-2010 20:39:15 GMT; path=/; domain=.google.ca; HttpOnly Server: gws X-XSS-Protection: 0 X-Cache: MISS from . Via: 1.0 .:80 (squid) Connection: close
©2009 - Privacy