[openstreetmap/openstreetmap-website] Use `assert_content` instead of `assert page.has_content?` (PR #3411)
Andy Allan
notifications at github.com
Thu Jan 6 13:37:16 UTC 2022
This PR switches to using `assert_content` (and `assert_link`) from Capybara's list of assertions, instead of using a plain assert on the Capybara node matchers (e.g. assert page.has_content?).
This makes little difference when the tests are working, but the error messages are much more helpful when the tests fail (e.g. during development or refactoring). The previous approach led to "Expected false to be truthy" which is not super helpful to debug!
Example for `assert_content`:
```diff
Failure:
DiaryEntrySystemTest#test_reply_to_diary_entry_should_prefill_the_message_subject [/test/system/diary_entry_test.rb:15]:
- Expected false to be truthy.
+ expected to find text "Receive a new message" in "OpenStreetMap\nEdit\nHistory\nExport\nGPS Traces\nUser Diaries\nCopyright\nHelp\nAbout\nUser 5\nSend a new message to User 4\nSubject\nBody\nParsed with kramdown\nHeadings\n# Heading\n## Subheading\nUnordered list\n* First item\n* Second item\nOrdered list\n1. First item\n2. Second item\nLink\n[Text](URL)\nImage\n\nBack to inbox"
```
Example for `assert_link`:
```diff
IssuesTest#test_issue_index_with_multiple_roles [/test/system/issues_test.rb:116]:
- Expected false to be truthy.
+ expected to find link "5 Reports" with href "/issues/446" but there were no matches
```
https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Minitest/Assertions
You can view, comment on, or merge this pull request online at:
https://github.com/openstreetmap/openstreetmap-website/pull/3411
-- Commit Summary --
* Use `assert_content` instead of `assert page.has_content?`
* Use `assert_link` instead of `assert page.has_link?`
-- File Changes --
M test/system/confirmation_resend_test.rb (4)
M test/system/diary_entry_test.rb (12)
M test/system/issues_test.rb (32)
M test/system/preferences_test.rb (4)
M test/system/report_diary_comment_test.rb (12)
M test/system/report_diary_entry_test.rb (20)
M test/system/report_note_test.rb (16)
M test/system/report_user_test.rb (22)
M test/system/user_logout_test.rb (24)
M test/system/user_signup_test.rb (2)
-- Patch Links --
https://github.com/openstreetmap/openstreetmap-website/pull/3411.patch
https://github.com/openstreetmap/openstreetmap-website/pull/3411.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/3411
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/3411 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20220106/2ecd397b/attachment.htm>
More information about the rails-dev
mailing list