From 2c8bc2cdcdb7b144b7a583d24922fd8064bcff3d Mon Sep 17 00:00:00 2001 From: Paul Nikitochkin Date: Fri, 6 Sep 2013 21:41:04 +0300 Subject: Use Ruby on Rails Coding Conventions for code examples in the guides * Indent after private/protected * Ruby >= 1.9 syntax for hashes * Prefer method { do_stuff } instead of method{do_stuff} for single-line blocks. [ci skip] --- guides/source/testing.md | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'guides/source/testing.md') diff --git a/guides/source/testing.md b/guides/source/testing.md index 1b0a0abf9a..5b8829b89a 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -757,24 +757,24 @@ class UserFlowsTest < ActionDispatch::IntegrationTest private - module CustomDsl - def browses_site - get "/products/all" - assert_response :success - assert assigns(:products) + module CustomDsl + def browses_site + get "/products/all" + assert_response :success + assert assigns(:products) + end end - end - def login(user) - open_session do |sess| - sess.extend(CustomDsl) - u = users(user) - sess.https! - sess.post "/login", username: u.username, password: u.password - assert_equal '/welcome', path - sess.https!(false) + def login(user) + open_session do |sess| + sess.extend(CustomDsl) + u = users(user) + sess.https! + sess.post "/login", username: u.username, password: u.password + assert_equal '/welcome', path + sess.https!(false) + end end - end end ``` @@ -887,10 +887,9 @@ class PostsControllerTest < ActionController::TestCase private - def initialize_post - @post = posts(:one) - end - + def initialize_post + @post = posts(:one) + end end ``` -- cgit v1.2.3 From 76d36458eadcb32c233f44065fccfbbef9a58119 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Fri, 20 Sep 2013 09:50:07 +0200 Subject: mention controller test base class in testing guide. [ci skip] --- guides/source/testing.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'guides/source/testing.md') diff --git a/guides/source/testing.md b/guides/source/testing.md index 5b8829b89a..50115607c9 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -438,10 +438,12 @@ Now that we have used Rails scaffold generator for our `Post` resource, it has a Let me take you through one such test, `test_should_get_index` from the file `posts_controller_test.rb`. ```ruby -test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:posts) +class PostsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:posts) + end end ``` -- cgit v1.2.3 From 54c1cdf4ce36fd4d0a5e7036d61ad35a9e8841e3 Mon Sep 17 00:00:00 2001 From: Geoffrey Roguelon Date: Thu, 3 Oct 2013 10:26:19 +0200 Subject: Fix a typo in the code of Testing guide. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the word «Accepts» by «Accept» in the example of custom request headers. --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source/testing.md') diff --git a/guides/source/testing.md b/guides/source/testing.md index 50115607c9..edf4813d74 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -534,7 +534,7 @@ instance variable: ```ruby # setting a HTTP Header -@request.headers["Accepts"] = "text/plain, text/html" +@request.headers["Accept"] = "text/plain, text/html" get :index # simulate the request with custom header # setting a CGI variable -- cgit v1.2.3 From 9c4261351c7b19e2b75ec3a981caafcf26d2def8 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 4 Nov 2013 12:33:30 +0100 Subject: document `BACKTRACE` env var usage in testing guide. [ci skip] --- guides/source/testing.md | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'guides/source/testing.md') diff --git a/guides/source/testing.md b/guides/source/testing.md index edf4813d74..cf01650b2a 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -359,6 +359,17 @@ Notice the 'E' in the output. It denotes a test with error. NOTE: The execution of each test method stops as soon as any error or an assertion failure is encountered, and the test suite continues with the next method. All test methods are executed in alphabetical order. +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 framwork 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: + +```bash +$ BACKTRACE=1 rake test test/models/post_test.rb +``` + ### What to Include in Your Unit Tests Ideally, you would like to include a test for everything which could possibly break. It's a good practice to have at least one test for each of your validations and at least one test for every method in your model. -- cgit v1.2.3 From 18010385fd3ef77316adfdd7a19f9d941690e110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Dahl=20M=C3=B8llerh=C3=B8j?= Date: Tue, 5 Nov 2013 23:12:51 +0100 Subject: Fixed minor typo instead of 'rake test' as shortcut, use 'rake'. Closes #12780 [ci skip] --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source/testing.md') diff --git a/guides/source/testing.md b/guides/source/testing.md index cf01650b2a..2fd0ed209d 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -798,7 +798,7 @@ You don't need to set up and run your tests by hand on a test-by-test basis. Rai | Tasks | Description | | ----------------------- | ----------- | -| `rake test` | Runs all unit, functional and integration tests. You can also simply run `rake test` as Rails will run all the tests by default| +| `rake test` | Runs all unit, functional and integration tests. You can also simply run `rake` as Rails will run all the 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`| -- cgit v1.2.3