require_relative "./helpers" describe "TestWebServer" do it "should respond to mock GET requests" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/').get http.callback { http.response_header.status.should == 200 http.response.should match(/Test/) EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end it "should respond to mock POST requests" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/').put http.callback { http.response_header.status.should == 200 http.response.should match(/Test/) EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end it "should respond to mock PUT requests" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/').post http.callback { http.response_header.status.should == 200 http.response.should match(/Test/) EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end context "should need basic auth" do it "and fail without basic auth credentials" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/basic/auth').get http.callback { http.response_header.status.should == 401 EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end it "and work with basic auth supplied" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/basic/auth').get :head => {'authorization' => ['admin', 'secret']} http.callback { http.response_header.status.should == 200 http.response.should match(/Test/) EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end end context "should need a body" do it "and fail without the right params set" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/post/content').post http.callback { http.response_header.status.should == 406 EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end it "and work with params set" do EventMachine.run { http = EventMachine::HttpRequest.new('http://localhost:3001/post/content').post :body => { :name => "bigbench", :id => 1 } http.callback { http.response_header.status.should == 200 http.response.should match(/Test/) EventMachine.stop } http.errback { puts "Error"; EventMachine.stop } } end end end