From 177cb8589f935c832829f819e1b06f46792beec5 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 7 Feb 2019 19:22:25 +0800 Subject: [PATCH] Move Test > Gotchas section to new page /Automated-Testing-Gotchas (HEAD 5b34302) --- Code-Conventions.md | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/Code-Conventions.md b/Code-Conventions.md index 1f61cc5..dc74163 100644 --- a/Code-Conventions.md +++ b/Code-Conventions.md @@ -49,34 +49,4 @@ Bad `expect(json_response['errors']).to eq "Hm, something went wrong. No order cycle data found."` Good -`expect(json_response['errors']).to eq I18n.t('admin.order_cycles.bulk_update.no_data')` - -## Gotchas - -### Multiple consecutive spaces in HTML - -Multiple consecutive spaces in HTML are rendered as a single space in the browser, and consequently also processed that way by `has_text?` and `has_content?` methods in Capybara. But they retain the original number of spaces when using `contains()` in CSS selectors and when inspecting strings in Javascript and Ruby. - -This can cause format-related intermittent spec failures, such as when dealing with space-padded strings. An example is the day of month when `Date` is in `:long` format: - -```ruby -# Two spaces before day of month -Date.new(2019, 1, 2).to_formatted_s(:long) -# => "January 2, 2019" - -# One space before day of month -Date.new(2019, 1, 20).to_formatted_s(:long) -# => "January 20, 2019" -``` - -### 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 +`expect(json_response['errors']).to eq I18n.t('admin.order_cycles.bulk_update.no_data')` \ No newline at end of file