Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Create a self contained Rack server for use with unit tests
module Rack::MiniServer
def start
@server_pid = fork do
puts "start forking ..."
Rack::Handler::WEBrick.run(
Rack::ShowExceptions.new(Rack::Lint.new(self.new)), :Port => 9292) do |server|
['INT', 'TERM'].each{ |signal| trap(signal){ puts "shutting down"; server.shutdown} }
end
end
sleep 2
end
def stop
Process.kill('INT',@server_pid)
end
end
class TestHelloWorld
extend Rack::MiniServer
def initialize
super
puts "server ready"
end
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
require 'httpclient'
HelloWorld.start
client = HTTPClient.new
assert_equal "Hello World",client.get_content("http://localhost:9292/")
HelloWorld.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.