Skip to content

Commit

Permalink
Merge pull request #83 from cookpad/use-minutes
Browse files Browse the repository at this point in the history
Use minutes not second when asserting results order
  • Loading branch information
sogamoso authored May 4, 2018
2 parents 7b02a54 + fc2a2f8 commit 0fc252f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions best-practices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@
expect(page).to have_text t("signups.create.welcome_message")
```
</details>
- <a name="use-minutes"></a>
Use minutes instead of seconds when setting timestamps for the purpose of asserting the order of results
<sup>[link](#use-minutes)</sup>
<details>
<summary><em>Example</em></summary>
```ruby
## Bad: Causes random failures depending on the timing of each step
older_recipe = create(:recipe, published_at: 2.seconds.ago)
newest_recipe = create(:recipe, published_at: 1.second.ago)
expect(Recipe.recently_published.first).to eq(newest_recipe)
expect(Recipe.recently_published.last).to eq(older_recipe)
## Good
older_recipe = create(:recipe, published_at: 2.minutes.ago)
newest_recipe = create(:recipe, published_at: 1.minute.ago)
expect(Recipe.recently_published.first).to eq(newest_recipe)
expect(Recipe.recently_published.last).to eq(older_recipe)
```
</details>
## I18n
Expand Down

0 comments on commit 0fc252f

Please sign in to comment.