Skip to content

Instantly share code, notes, and snippets.

@taf2
Created April 22, 2009 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taf2/99951 to your computer and use it in GitHub Desktop.
Save taf2/99951 to your computer and use it in GitHub Desktop.
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