RSpec - how to validate that controller renders xml

Hi List

I have a controller method that I would like to render some objects as
XML, using the following:

render :xml => @goals

Is there anyway in RSpec to check that the controller is indeed
rendering xml?

Rory

Is this a conditional render call or does the action always render xml?
It
will always render xml if you tell it to, and you don’t need to test
Rails;
it’s already been tested.

On Mon, May 19, 2008 at 5:12 PM, Rory McKinley
[email protected]
wrote:

Rory


Appreciated my help?
Reccommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg

On 19 May 2008, at 08:44, Ryan B. (Radar) wrote:

Is this a conditional render call or does the action always render
xml? It will always render xml if you tell it to, and you don’t need
to test Rails; it’s already been tested.

That said, you could always check @response.content_type

Fred

I didn’t know about that @response.content_type, thanks Fred!

Also, isn’t it response, not @response?

On Mon, May 19, 2008 at 6:10 PM, Rory McKinley
[email protected]
wrote:


Appreciated my help?
Reccommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg

Frederick C. wrote:

On 19 May 2008, at 08:44, Ryan B. (Radar) wrote:

Is this a conditional render call or does the action always render
xml? It will always render xml if you tell it to, and you don’t need
to test Rails; it’s already been tested.

That said, you could always check @response.content_type

Thanks Frederick and Ryan

To answer Ryan’s question:

Currently, it will always render xml, but I am trying to do BDD and
writing my specs first, therefore I am putting the spec in to force
myself to remember to render as xml, rather than checking rails :wink:

Frederick C. wrote:

On 19 May 2008, at 10:43, Ryan B. (Radar) wrote:

I didn’t know about that @response.content_type, thanks Fred!

Also, isn’t it response, not @response?

Not as far as I know.

Fred

Plain old response seems to work for me. Does anybody know if there is
some place where the response methods are documented (e…g
response.code, response.content_type etc) ?

I normally test XML and JSON responses using something like
http://pastie.caboo.se/199453

On May 19, 11:30 am, Rory McKinley [email protected]

On 19 May 2008, at 10:43, Ryan B. (Radar) wrote:

I didn’t know about that @response.content_type, thanks Fred!

Also, isn’t it response, not @response?

Not as far as I know.

Fred

Rory McKinley wrote:

Plain old response seems to work for me. Does anybody know if there is
some place where the response methods are documented (e…g
response.code, response.content_type etc) ?

ActionController::AbstractResponse

Nice code in the pastie
Very helpful.
Thanks.

Spongy wrote:

I normally test XML and JSON responses using something like
http://pastie.caboo.se/199453

On May 19, 11:30�am, Rory McKinley [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs