Anyone have any tips on how to test an rss feed with cucumber (preference) or rspec?
Note, I am currently working on a Rails 3 application with a blog which I expose as an rss feed.
I would like to set up a test to ensure that 开发者_如何转开发it remains well formatted and consumable.
Thanks!
Jonathan
To test an RSS feed with RSpec you can use :format => "rss"
in your controller tests, i.e. you can simple use something like this:
describe "GET RSS feed" do
it "returns an RSS feed" do
get :index, :format => "rss"
response.should be_success
response.should render_template("posts/index")
response.content_type.should eq("application/rss+xml")
end
end
Using Test::Unit, you would write
def test_get_rss_feed
get :index, :format => "rss"
assert_response :success
assert_template "posts/index"
assert_equal 'application/rss+xml', @response.content_type
end
You could find some ideas by looking at the specs for an existing RSS gem, such as feedzirra.
精彩评论