diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2012-03-27 21:26:37 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2012-03-27 21:26:37 +0530 |
commit | b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4 (patch) | |
tree | dd296efc489c22850d6cc7fa8d7a69da5e122b54 /guides/source/testing.textile | |
parent | 888fcca01b736b7f91041b7a6a1b162af6688f7a (diff) | |
parent | ae040ed6d8c48bf0cd6d5d6b434d60c9c8c27f81 (diff) | |
download | rails-b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4.tar.gz rails-b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4.tar.bz2 rails-b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'guides/source/testing.textile')
-rw-r--r-- | guides/source/testing.textile | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/guides/source/testing.textile b/guides/source/testing.textile index c367f532ae..60b0aa89b9 100644 --- a/guides/source/testing.textile +++ b/guides/source/testing.textile @@ -524,6 +524,44 @@ You also have access to three instance variables in your functional tests: * +@request+ - The request * +@response+ - The response +h4. Testing Templates and Layouts + +If you want to make sure that the response rendered the correct template and layout, you can use the +assert_template+ +method: + +<ruby> +test "index should render correct template and layout" do + get :index + assert_template :index + assert_template :layout => "layouts/application" +end +</ruby> + +Note that you cannot test for template and layout at the same time, with one call to +assert_template+ method. +Also, for the +layout+ test, you can give a regular expression instead of a string, but using the string, makes +things clearer. On the other hand, you have to include the "layouts" directory name even if you save your layout +file in this standard layout directory. Hence, + +<ruby> +assert_template :layout => "application" +</ruby> + +will not work. + +If your view renders any partial, when asserting for the layout, you have to assert for the partial at the same time. +Otherwise, assertion will fail. + +Hence: + +<ruby> +test "new should render correct layout" do + get :new + assert_template :layout => "layouts/application", :partial => "_form" +end +</ruby> + +is the correct way to assert for the layout when the view renders a partial with name +_form+. Omitting the +:partial+ key in your +assert_template+ call will complain. + h4. A Fuller Functional Test Example Here's another example that uses +flash+, +assert_redirected_to+, and +assert_difference+: |