# Specify format (xml, html, etc) in functional test

**URL:** <https://www.ruby-forum.com/t/specify-format-xml-html-etc-in-functional-test/92753>\
**Category:** Rails\
**Created:** [April 23, 2007, 10:00pm UTC](https://www.ruby-forum.com/t/specify-format-xml-html-etc-in-functional-test/92753 "2007-04-23T22:00:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipp07](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@philipp07](https://www.ruby-forum.com/u/philipp07)\
**Post date:** [April 23, 2007, 10:00pm UTC](https://www.ruby-forum.com/t/specify-format-xml-html-etc-in-functional-test/92753/1 "2007-04-23T22:00:52Z")

</div>

Hi,

I can’t find any information on how to specify the format (like xml,  
html, js, …) of a request in a functional controller test.

For example:

I have a create action in my bookmarks\_controller which responds to  
format.xml and format.html.  
If html is requested it should respond with a redirect, if xml is  
requested with the http status code :created.

def test\_should\_create\_bookmark\_xml  
post :create, :bookmark =\> { :channel\_id =\> 3, :user\_id =\> 1 }  
assert\_equal old\_count+1, Bookmark.count

```
assert_response :created
assert assigns(:bookmark)

```

end

def test\_should\_create\_bookmark\_html  
post :create, :bookmark =\> { :channel\_id =\> 3, :user\_id =\> 1 }  
assert\_equal old\_count+1, Bookmark.count

```
assert_redirected_to bookmark_path(1, assigns(:hypermark))

```

end

How can I specify which format post requests?

lg philipp

---

<div class="post-metadata">

**Author:** ![philipp07](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@philipp07](https://www.ruby-forum.com/u/philipp07)\
**Post date:** [April 23, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/specify-format-xml-html-etc-in-functional-test/92753/2 "2007-04-23T22:25:55Z")

</div>

A finally found a blog regarding this problem:

[http://singlecell.angryamoeba.co.uk/2007/03/16/testing-respond\_to-actions-in-rails-121/](http://singlecell.angryamoeba.co.uk/2007/03/16/testing-respond_to-actions-in-rails-121/)

lg philipp

---

<div class="post-metadata">

**Author:** ![philipp07](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@philipp07](https://www.ruby-forum.com/u/philipp07)\
**Post date:** [April 24, 2007, 3:28am UTC](https://www.ruby-forum.com/t/specify-format-xml-html-etc-in-functional-test/92753/3 "2007-04-24T03:28:18Z")

</div>

Hello Philipp,

2007/4/23, Philipp S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I can’t find any information on how to specify the format (like xml,  
> html, js, …) of a request in a functional controller test.

get :action, :format =\> “xml”

## Hope that helps !

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)
