Skip to content

Instantly share code, notes, and snippets.

@peterc
Created April 3, 2009 17:56
Show Gist options
  • Save peterc/89862 to your computer and use it in GitHub Desktop.
Save peterc/89862 to your computer and use it in GitHub Desktop.
# Test a Wordpress blog for compliance with /feed, /feed/ and
# similar requests from normal Feed clients and FeedBurner
# == HELPERS
require 'net/http'
# Fetch a URL without processing redirects and return status code and body
def get_url(url, agent)
iurl = URI.parse(url)
req = Net::HTTP::Get.new(iurl.path, { "User-Agent" => agent })
res = Net::HTTP.start(iurl.host, iurl.port) { |http| http.request(req) }
[(res.code.to_i rescue 500), res.body]
end
# == SPECS
BASE_URL = 'http://127.0.0.1'
describe "Blog" do
it "should return 301 redirect for feed client requesting /feed" do
code, body = get_url(BASE_URL + '/feed', 'Mozilla')
code.should == 301
body.should =~ /\/feed\//
end
it "should return 302 redirect to FeedBurner hosted feed for feed client requesting /feed/" do
code, body = get_url(BASE_URL + '/feed/' , 'Mozilla')
code.should == 302
body.should =~ /feedburner/
end
it "should return actual feed to FeedBurner" do
code, body = get_url(BASE_URL + '/feed', 'FeedBurner/1.0')
code.should == 200
body.length.should > 1000
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment