67 lines
1.2 KiB
Ruby
67 lines
1.2 KiB
Ruby
|
|
ENV["RACK_ENV"] = "test"
|
||
|
|
#require File.join(File.dirname(__FILE__), '..', '..', 'config.ru')
|
||
|
|
|
||
|
|
require 'test/unit'
|
||
|
|
require 'rack/test'
|
||
|
|
require "json"
|
||
|
|
require 'httpclient'
|
||
|
|
|
||
|
|
USERNAME = '<username>'
|
||
|
|
PASSWORD = '<password>'
|
||
|
|
HOST = '<host>'
|
||
|
|
PORT = 7070
|
||
|
|
|
||
|
|
class MyWorld
|
||
|
|
|
||
|
|
include Rack::Test::Methods
|
||
|
|
@@app = nil
|
||
|
|
def app
|
||
|
|
@@app ||= eval("Rack::Builder.new {( " + File.read(File.dirname(__FILE__) + '/../../config.ru') + "\n )}")
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
class RequestSender
|
||
|
|
|
||
|
|
@last_res = nil
|
||
|
|
$test_hash = Hash.new
|
||
|
|
|
||
|
|
def host
|
||
|
|
"http://#{HOST}:#{PORT}"
|
||
|
|
end
|
||
|
|
|
||
|
|
def last_response
|
||
|
|
@last_res
|
||
|
|
end
|
||
|
|
|
||
|
|
def get path, query, headers
|
||
|
|
submit do |http|
|
||
|
|
http.get(host + path, query, headers)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def post path, query, headers
|
||
|
|
submit do |http|
|
||
|
|
http.receive_timeout = 0 #!!! bring out to appropriate server step
|
||
|
|
http.post(host + path, JSON.pretty_generate(query), headers)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def delete path, query, headers
|
||
|
|
submit do |http|
|
||
|
|
http.delete(host + path, JSON.pretty_generate(query), headers)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def submit
|
||
|
|
http = HTTPClient.new
|
||
|
|
http.set_auth(host, USERNAME, PASSWORD)
|
||
|
|
res = yield http
|
||
|
|
@last_res = res
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
World do
|
||
|
|
#MyWorld.new
|
||
|
|
RequestSender.new
|
||
|
|
end
|