views:

31

answers:

2

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.

+1  A: 

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
@shingara can we do it without using Nokogiri.
Rohit
I found the answer myself. But still an upvote for your effort. Thanks
Rohit
Even this works. Tested it this is working so it is a right answer, just that I don't want an extra tool in the environment
Rohit
+1  A: 

@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
Rohit
Yes, you can do like that because HTML is an XML so it's use the ActiveSupport::XML this can be Nokogiri or another tool too.
shingara