From d6952ee7afcbe17b3fa030ed2b416456cdd2e809 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 7 Feb 2019 19:00:47 +0800 Subject: [PATCH] Add section for designing tests to pass regardless of time of execution --- Code-Conventions.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Code-Conventions.md b/Code-Conventions.md index c6b6091..1f61cc5 100644 --- a/Code-Conventions.md +++ b/Code-Conventions.md @@ -67,4 +67,16 @@ Date.new(2019, 1, 2).to_formatted_s(:long) # One space before day of month Date.new(2019, 1, 20).to_formatted_s(:long) # => "January 20, 2019" -``` \ No newline at end of file +``` + +### Design tests to pass regardless of time of execution + +A test may be run at any time of day, any day of month, and any calendar month. Make sure that the test will always pass. + +Some things to watch out for: + +* `now + 1.hour` can still be part of today, or it can be tomorrow. +* `today - 1.day` can be in the current calendar month, or last month +* `today + 1.day` can be part of this calendar year, or next year + +If needed, you may also use `Timecop` to mock the time at which the test thinks it is running. \ No newline at end of file