From 09d2623783183c0e9c22d92b52c64b05980c3b7e Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Mon, 30 Mar 2015 00:11:02 +0300 Subject: Switch to `bin/rails test` in testing guide rails/rails#18305 --- guides/source/testing.md | 53 +++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 52e3655142..3bc3dbc672 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -141,24 +141,18 @@ users(:david).id email(david.girlfriend.email, david.location_tonight) ``` -### Rake Tasks for Running your Tests - -Rails comes with a number of built-in rake tasks to help with testing. The -table below lists the commands included in the default Rakefile when a Rails -project is created. - -| Tasks | Description | -| ----------------------- | ----------- | -| `rake test` | Runs all tests in the `test` directory. You can also run `rake` and Rails will run all tests by default | -| `rake test:controllers` | Runs all the controller tests from `test/controllers` | -| `rake test:functionals` | Runs all the functional tests from `test/controllers`, `test/mailers`, and `test/functional` | -| `rake test:helpers` | Runs all the helper tests from `test/helpers` | -| `rake test:integration` | Runs all the integration tests from `test/integration` | -| `rake test:jobs` | Runs all the job tests from `test/jobs` | -| `rake test:mailers` | Runs all the mailer tests from `test/mailers` | -| `rake test:models` | Runs all the model tests from `test/models` | -| `rake test:units` | Runs all the unit tests from `test/models`, `test/helpers`, and `test/unit` | -| `rake test:db` | Runs all tests in the `test` directory and resets the db | +### Console Tasks for Running your Tests + +Rails comes with a CLI command to run tests. +Here are some examples how to use it: + +```bash +$ bin/rails test # run all tests in the `test` directory +$ bin/rails test controllers # run all controller tests in the `test/controllers` directory +$ bin/rails test test/controllers # run all tests from specific directory +$ bin/rails test test/models/post_test.rb # run specific test +$ bin/rails test test/models/post_test.rb:44 # run specific test and line +``` We will cover each of types Rails tests listed above in this guide. @@ -259,10 +253,10 @@ be rebuilt. This can be done by executing `bin/rake db:test:prepare`. ### Running Tests -Running a test is as simple as invoking the file containing the test cases through `rake test` command. +Running a test is as simple as invoking the file containing the test cases through `rails test` command. ```bash -$ bin/rake test test/models/article_test.rb +$ bin/rails test test/models/article_test.rb . Finished tests in 0.009262s, 107.9680 tests/s, 107.9680 assertions/s. @@ -275,7 +269,7 @@ This will run all test methods from the test case. You can also run a particular test method from the test case by running the test and providing the `test method name`. ```bash -$ bin/rake test test/models/article_test.rb test_the_truth +$ bin/rails test test/models/article_test.rb test_the_truth . Finished tests in 0.009064s, 110.3266 tests/s, 110.3266 assertions/s. @@ -299,7 +293,7 @@ end Let us run this newly added test. ```bash -$ bin/rake test test/models/article_test.rb test_should_not_save_article_without_title +$ bin/rails test test/models/article_test.rb test_should_not_save_article_without_title F Finished tests in 0.044632s, 22.4054 tests/s, 22.4054 assertions/s. @@ -339,7 +333,7 @@ end Now the test should pass. Let us verify by running the test again: ```bash -$ bin/rake test test/models/article_test.rb test_should_not_save_article_without_title +$ bin/rails test test/models/article_test.rb test_should_not_save_article_without_title . Finished tests in 0.047721s, 20.9551 tests/s, 20.9551 assertions/s. @@ -368,7 +362,7 @@ end Now you can see even more output in the console from running the tests: ```bash -$ bin/rake test test/models/article_test.rb test_should_report_error +$ bin/rails test test/models/article_test.rb test_should_report_error E Finished tests in 0.030974s, 32.2851 tests/s, 0.0000 assertions/s. @@ -393,11 +387,10 @@ When a test fails you are presented with the corresponding backtrace. By default Rails filters that backtrace and will only print lines relevant to your application. This eliminates the framework noise and helps to focus on your code. However there are situations when you want to see the full -backtrace. simply set the `BACKTRACE` environment variable to enable this -behavior: +backtrace. Simply set the `-b` (or `--backtrace`) argument to enable this behavior: ```bash -$ BACKTRACE=1 bin/rake test test/models/article_test.rb +$ bin/rails test -b test/models/article_test.rb ``` If we want this test to pass we can modify it to use `assert_raises` like so: @@ -666,7 +659,7 @@ end If we run our test now, we should see a failure: ```bash -$ bin/rake test test/controllers/articles_controller_test.rb test_should_create_article +$ bin/rails test test/controllers/articles_controller_test.rb test_should_create_article Run options: -n test_should_create_article --seed 32266 # Running: @@ -704,7 +697,7 @@ end Now if we run our tests, we should see it pass: ```bash -$ bin/rake test test/controllers/articles_controller_test.rb test_should_create_article +$ bin/rails test test/controllers/articles_controller_test.rb test_should_create_article Run options: -n test_should_create_article --seed 18981 # Running: @@ -852,7 +845,7 @@ end I've added this file here `test/controllers/articles_routes_test.rb` and if we run the test we should see: ```bash -$ bin/rake test test/controllers/articles_routes_test.rb +$ bin/rails test test/controllers/articles_routes_test.rb # Running: -- cgit v1.2.3 From b016533d5b54fc932a851fca6148cfb5965da8b5 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Mon, 30 Mar 2015 09:14:32 -0700 Subject: Add missing "of" to testing guide. --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 1139f367c6..4b7d6411be 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -144,7 +144,7 @@ email(david.partner.email, david.location_tonight) ### Console Tasks for Running your Tests Rails comes with a CLI command to run tests. -Here are some examples how to use it: +Here are some examples of how to use it: ```bash $ bin/rails test # run all tests in the `test` directory -- cgit v1.2.3 From 3cee8ce2e8b9a7a651d88765b2c9ffd1fbda01e4 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Tue, 31 Mar 2015 13:45:05 +0300 Subject: Don't suggest `bin/rails test controllers` --- guides/source/testing.md | 1 - 1 file changed, 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 4b7d6411be..df61c61aa3 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -148,7 +148,6 @@ Here are some examples of how to use it: ```bash $ bin/rails test # run all tests in the `test` directory -$ bin/rails test controllers # run all controller tests in the `test/controllers` directory $ bin/rails test test/controllers # run all tests from specific directory $ bin/rails test test/models/post_test.rb # run specific test $ bin/rails test test/models/post_test.rb:44 # run specific test and line -- cgit v1.2.3 From 487aa51b1414d3f316c7ccdc92af2f212961e0bb Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Tue, 31 Mar 2015 14:36:26 +0300 Subject: Suggest new hash syntax in testing guide --- guides/source/testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index df61c61aa3..a67f2edbaa 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -496,13 +496,13 @@ All the keyword arguments are optional. Example: Calling the `:show` action, passing an `id` of 12 as the `params` and setting a `user_id` of 5 in the session: ```ruby -get(:show, params: { 'id' => "12" }, session: { 'user_id' => 5 }) +get(:show, params: { id: 12 }, session: { user_id: 5 }) ``` Another example: Calling the `:view` action, passing an `id` of 12 as the `params`, this time with no session, but with a flash message. ```ruby -get(:view, params: { 'id' => '12' }, flash: { 'message' => 'booya!' }) +get(:view, params: { id: 12 }, flash: { message: 'booya!' }) ``` NOTE: If you try running `test_should_create_article` test from `articles_controller_test.rb` it will fail on account of the newly added model level validation and rightly so. -- cgit v1.2.3 From 851621bf19f21eaab4a3a8476cd19b5fb1fd7d93 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Tue, 31 Mar 2015 14:37:46 +0300 Subject: New test runner syntax in testing guide --- guides/source/testing.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index a67f2edbaa..220e61e088 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -289,10 +289,10 @@ test "should not save article without title" do end ``` -Let us run this newly added test. +Let us run this newly added test (where `6` is the number of line where the test is defined). ```bash -$ bin/rails test test/models/article_test.rb test_should_not_save_article_without_title +$ bin/rails test test/models/article_test.rb:6 F Finished tests in 0.044632s, 22.4054 tests/s, 22.4054 assertions/s. @@ -332,7 +332,7 @@ end Now the test should pass. Let us verify by running the test again: ```bash -$ bin/rails test test/models/article_test.rb test_should_not_save_article_without_title +$ bin/rails test test/models/article_test.rb:6 . Finished tests in 0.047721s, 20.9551 tests/s, 20.9551 assertions/s. @@ -361,7 +361,7 @@ end Now you can see even more output in the console from running the tests: ```bash -$ bin/rails test test/models/article_test.rb test_should_report_error +$ bin/rails test test/models/article_test.rb E Finished tests in 0.030974s, 32.2851 tests/s, 0.0000 assertions/s. -- cgit v1.2.3 From afbd6559f98b2166ba4c1f3dec52a33f10c2a827 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Tue, 31 Mar 2015 14:38:18 +0300 Subject: No need to mention unit tests in testing guide anymore --- guides/source/testing.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 220e61e088..f12daf0dbc 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -158,8 +158,6 @@ We will cover each of types Rails tests listed above in this guide. Model Testing ------------------------ -In Rails, unit tests are what you write to test your models. - For this guide we will be using the application we built in the [Getting Started with Rails](getting_started.html) guide. If you remember when you used the `rails generate scaffold` command from earlier. We created our first resource among other things it created a test stub in the `test/models` directory: -- cgit v1.2.3 From 66bf962a7a9f5304c2437f42a9af81ee46ef9dbb Mon Sep 17 00:00:00 2001 From: yui-knk Date: Wed, 1 Apr 2015 19:59:54 +0900 Subject: [ci skip] Add `:` --- guides/source/active_record_querying.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index bef903b751..2820b641f1 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -529,7 +529,7 @@ Client.order("orders_count ASC, created_at DESC") Client.order("orders_count ASC", "created_at DESC") ``` -If you want to call `order` multiple times e.g. in different context, new order will append previous one +If you want to call `order` multiple times e.g. in different context, new order will append previous one: ```ruby Client.order("orders_count ASC").order("created_at DESC") -- cgit v1.2.3 From 0f26977d092dff56561c0697d2bf2dccece611a7 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Wed, 1 Apr 2015 20:02:56 +0900 Subject: [ci skip] Remove unnecessary lines --- guides/source/layouts_and_rendering.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index c57fa358d6..d1a01f87ab 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -123,8 +123,6 @@ Content-Type: */*; charset=utf-8 X-Runtime: 0.014297 Set-Cookie: _blog_session=...snip...; path=/; HttpOnly Cache-Control: no-cache - -$ ``` We see there is an empty response (no data after the `Cache-Control` line), but the request was successful because Rails has set the response to 200 OK. You can set the `:status` option on render to change this response. Rendering nothing can be useful for Ajax requests where all you want to send back to the browser is an acknowledgment that the request was completed. -- cgit v1.2.3 From fdcc71d0146575a6387bb5cc4380eda1072dd435 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Fri, 10 Apr 2015 13:54:25 +0900 Subject: [ci skip] Wrap with double quotation --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 8c1551f4a1..65dbb070fa 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -667,7 +667,7 @@ You may notice in the above code that we're using `render xml: @users`, not `ren Filters ------- -Filters are methods that are run before, after or "around" a controller action. +Filters are methods that are run "before", "after" or "around" a controller action. Filters are inherited, so if you set a filter on `ApplicationController`, it will be run on every controller in your application. -- cgit v1.2.3 From 746695d6c8426ecc48d4a7099b6330ef3fda16ea Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Fri, 10 Apr 2015 22:35:46 +0300 Subject: [ci skip] fix helper name --- guides/source/engines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/engines.md b/guides/source/engines.md index 84017d5e13..7b20b48c81 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -368,7 +368,7 @@ called `Blorgh::ArticlesController` (at `app/controllers/blorgh/articles_controller.rb`) and its related views at `app/views/blorgh/articles`. This generator also generates a test for the controller (`test/controllers/blorgh/articles_controller_test.rb`) and a helper -(`app/helpers/blorgh/articles_controller.rb`). +(`app/helpers/blorgh/articles_helper.rb`). Everything this generator has created is neatly namespaced. The controller's class is defined within the `Blorgh` module: -- cgit v1.2.3 From 81b291915ca76f2b935cbfe2d32918fbd81a0958 Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Fri, 10 Apr 2015 22:55:19 +0300 Subject: [ci skip] format rake output --- guides/source/engines.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/engines.md b/guides/source/engines.md index 7b20b48c81..5496b6e1ad 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -831,11 +831,9 @@ Notice that only _one_ migration was copied over here. This is because the first two migrations were copied over the first time this command was run. ``` -NOTE Migration [timestamp]_create_blorgh_articles.rb from blorgh has been -skipped. Migration with the same name already exists. NOTE Migration -[timestamp]_create_blorgh_comments.rb from blorgh has been skipped. Migration -with the same name already exists. Copied migration -[timestamp]_add_author_id_to_blorgh_articles.rb from blorgh +NOTE Migration [timestamp]_create_blorgh_articles.rb from blorgh has been skipped. Migration with the same name already exists. +NOTE Migration [timestamp]_create_blorgh_comments.rb from blorgh has been skipped. Migration with the same name already exists. +Copied migration [timestamp]_add_author_id_to_blorgh_articles.rb from blorgh ``` Run the migration using: -- cgit v1.2.3 From 8ec88a1b9eee2f259fd9c4de87b9d7d0d4b21fba Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Fri, 10 Apr 2015 23:07:04 +0300 Subject: [ci skip] add missing file extension --- guides/source/engines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/engines.md b/guides/source/engines.md index 5496b6e1ad..b6775cae4d 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -1199,7 +1199,7 @@ end ``` ```ruby -# Blorgh/lib/concerns/models/article +# Blorgh/lib/concerns/models/article.rb module Blorgh::Concerns::Models::Article extend ActiveSupport::Concern -- cgit v1.2.3