开发者

Writing spec for controller actions that return XML -- Ruby on Rails

In my controller 开发者_如何转开发I have some methods which return json as well as xml data. I need to test those actions. For testing the json part I found this reference and it is working fine. Now I am need of testing the actions for the XML part. Anyone who can help or suggest something are most welcome I've been scratching my head for an hour now but to no avail. Please help. Thanks in advance.


when you request your controller you specify the format you want. After parse the result with Nokogiri and see if your XML is valid or not

it 'should has tag hello' do
  get :index :format => :xml
  Nokogiri::XML(response.body).should has_tag('hello')
ebd


@shingara thanks for the answer. But I wanted to do it without using any extra tools and just rspec. I found the solution here. Read the complete post. It has what I want and also a bit demo of Hpricot. Well anyways thanks for answering.

it 'should has tag hello' do
  get :index :format => :xml
  response.should have_tag("hello",'value inside hello tag')
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜