Testing to see if a page exists

I recently wanted to write a spec that would test if I actually brought up a rails server at a certain address. Turns out the way to interact with stuff on the web in your specs is Net::HTTP. Here’s an example:

it “starts up a rails server on that port” do
Net::HTTP.start(”forkolator.org”, 80) { |http|
response, body = http.get(”/”)
response.code.should == “200″
}
end

This spec looks for http://forkolator.org:80/ to respond with success code 200. Works great.

Tags: ,

Leave a Reply