aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPanayotis Matsinopoulos <panayotis@matsinopoulos.gr>2012-03-24 23:12:39 +0200
committerPanayotis Matsinopoulos <panayotis@matsinopoulos.gr>2012-03-24 23:12:39 +0200
commit214b0ddee74b6b7af0f3f4cd4e36669895c17bd9 (patch)
tree0756b61ad1761b808c5dccb9eec5c246d75e55d2
parent9ff2e928ef90411c5bd5dc6a61dfe735f3002cb1 (diff)
downloadrails-214b0ddee74b6b7af0f3f4cd4e36669895c17bd9.tar.gz
rails-214b0ddee74b6b7af0f3f4cd4e36669895c17bd9.tar.bz2
rails-214b0ddee74b6b7af0f3f4cd4e36669895c17bd9.zip
Testing Template and Layout Example
-rw-r--r--guides/source/testing.textile25
1 files changed, 25 insertions, 0 deletions
diff --git a/guides/source/testing.textile b/guides/source/testing.textile
index c367f532ae..01b406172f 100644
--- a/guides/source/testing.textile
+++ b/guides/source/testing.textile
@@ -524,6 +524,31 @@ You also have access to three instance variables in your functional tests:
* +@request+ - The request
* +@response+ - The response
+h4. Testing Template and Layout Example
+
+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.
+
+
h4. A Fuller Functional Test Example
Here's another example that uses +flash+, +assert_redirected_to+, and +assert_difference+: