Created
April 22, 2009 17:57
-
-
Save taf2/99951 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'curb' | |
require 'webrick' | |
require 'test/unit' | |
# keep webrick quiet | |
class ::WEBrick::HTTPServer | |
def access_log(config, req, res) | |
# nop | |
end | |
end | |
class ::WEBrick::BasicLog | |
def log(level, data) | |
# nop | |
end | |
end | |
class TestServlet < WEBrick::HTTPServlet::AbstractServlet | |
def do_POST(req,res) | |
# echo the request body in the response body | |
res.body = req.body | |
res['Content-Type'] = "text/plain" | |
end | |
end | |
class TestCase < Test::Unit::TestCase | |
def setup | |
@pid = fork do | |
server = WEBrick::HTTPServer.new :Port => '9213' | |
server.mount('/process.php', TestServlet) | |
trap("INT") { server.shutdown } | |
trap("TERM") { server.shutdown } | |
server.start | |
end | |
end | |
def teardown | |
Process.kill("INT",@pid) | |
end | |
def test_it | |
response = Curl::Easy.http_post("http://127.0.0.1:9213/process.php", | |
Curl::PostField.content('Type', 'MC'), | |
Curl::PostField.content('CardNum', '5454545454545454'), | |
Curl::PostField.content('ExpDate', '0512') ) | |
assert_equal "Type=MC&CardNum=5454545454545454&ExpDate=0512", response.body_str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment