peterc (owner)

Revisions

gist: 89862 Download_button fork
public
Public Clone URL: git://gist.github.com/89862.git
Embed All Files: show embed
blog_spec.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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