Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test an RSS feed, with cucumber or rspec

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

like image 811
Jonathan Avatar asked Feb 20 '11 14:02

Jonathan


1 Answers

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
like image 165
0x4a6f4672 Avatar answered Sep 20 '22 22:09

0x4a6f4672