aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2015-11-15 19:16:58 +0000
committerVijay Dev <vijaydev.cse@gmail.com>2015-11-15 19:16:58 +0000
commit153d7ca630d10449f24f5576f27452f9efb40791 (patch)
treeb6a8fa0639a6fc275c5809ea9ba7d268954b1709 /guides
parent69f72223e82a4a4f16f16ad7abb36ebfd162a366 (diff)
parent905226fc262861201d843d622a803ed1aeaebaa8 (diff)
downloadrails-153d7ca630d10449f24f5576f27452f9efb40791.tar.gz
rails-153d7ca630d10449f24f5576f27452f9efb40791.tar.bz2
rails-153d7ca630d10449f24f5576f27452f9efb40791.zip
Merge branch 'master' of github.com:rails/docrails
Diffstat (limited to 'guides')
-rw-r--r--guides/source/testing.md26
1 files changed, 24 insertions, 2 deletions
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 2f941a8280..f63ea49955 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -155,7 +155,7 @@ Failed assertion, no message given.
1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
```
-In the output, `F` denotes a failure. You can see the corresponding trace shown under `1)` along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable, every assertion provides an optional message parameter, as shown here:
+In the output, `F` denotes a failure. You can see the corresponding trace shown under `1)` along with the name of the failing test. The next few lines contain the stack trace followed by a message that mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable, every assertion provides an optional message parameter, as shown here:
```ruby
test "should not save article without title" do
@@ -523,7 +523,7 @@ Model tests don't have their own superclass like `ActionMailer::TestCase` instea
Integration Testing
-------------------
-Integration tests are used to test how various parts of your application interact. They are generally used to test important work flows within your application.
+Integration tests are used to test how various parts of your application interact. They are generally used to test important workflows within your application.
For creating Rails integration tests, we use the 'test/integration' directory for your application. Rails provides a generator to create an integration test skeleton for you.
@@ -1232,3 +1232,25 @@ class ProductTest < ActiveJob::TestCase
end
end
```
+
+Testing Time-Dependent Code
+---------------------------
+
+Rails provides inbuilt helper methods that enable you to assert that your time-sensitve code works as expected.
+
+Here is an example using the [`travel_to`](http://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html#method-i-travel_to) helper:
+
+```ruby
+# Lets say that a user is eligible for gifting a month after they register.
+user = User.create(name: 'Gaurish', activation_date: Date.new(2004, 10, 24))
+assert_not user.applicable_for_gifting?
+travel_to Date.new(2004, 11, 24) do
+ assert_equal Date.new(2004, 10, 24), user.activation_date # inside the travel_to block `Date.current` is mocked
+ assert user.applicable_for_gifting?
+end
+assert_equal Date.new(2004, 10, 24), user.activation_date # The change was visible only inside the `travel_to` block.
+```
+
+Please see [`ActiveSupport::TimeHelpers` API Documentation](http://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html)
+for in-depth information about the available time helpers.
+