From a413111c18ae076f9b14d8c379420eb450ce9a70 Mon Sep 17 00:00:00 2001 From: Aditya Kapoor Date: Wed, 15 Jul 2015 18:07:22 +0530 Subject: [PATCH] [ci skip] add note for individual stub creation --- guides/source/testing.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/guides/source/testing.md b/guides/source/testing.md index 2fd54a48fc..d146df3dc6 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -178,6 +178,14 @@ create test/fixtures/articles.yml ... ``` +You can also generate the test stub for a model using the following command: + +```bash +$ bin/rails generate test_unit:model article title:string body:text +create test/models/article_test.rb +create test/fixtures/articles.yml +``` + The default test stub in `test/models/article_test.rb` looks like this: ```ruby @@ -509,6 +517,14 @@ You should test for things such as: Now that we have used Rails scaffold generator for our `Article` resource, it has already created the controller code and tests. You can take look at the file `articles_controller_test.rb` in the `test/controllers` directory. +The following command will generate a controller test case with a filled up +test for each of the seven default actions. + +```bash +$ bin/rails generate test_unit:scaffold article +create test/controllers/articles_controller_test.rb +``` + Let me take you through one such test, `test_should_get_index` from the file `articles_controller_test.rb`. ```ruby