Skip to content

Commit d615371

Browse files
morgothp8
andcommitted
Prefer assert_dom over assert_select.
One is the alias of the other, but assert_select is a confusing name in presence of the assert_selector method (from Capybara). Also there is a conflicting `assert_select` on the Capybara itself https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FMinitest%2FAssertions:assert_select This is a follow up to rails#54299 (comment) and rails/rails-dom-testing#92 (comment) [ci skip] Co-authored-by: Petrik de Heus <[email protected]>
1 parent d4acb7a commit d615371

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

actionpack/lib/action_dispatch/testing/integration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def method_missing(method, ...)
549549
# https!(false)
550550
# get "/articles/all"
551551
# assert_response :success
552-
# assert_select 'h1', 'Articles'
552+
# assert_dom 'h1', 'Articles'
553553
# end
554554
# end
555555
#
@@ -588,7 +588,7 @@ def method_missing(method, ...)
588588
# def browses_site
589589
# get "/products/all"
590590
# assert_response :success
591-
# assert_select 'h1', 'Products'
591+
# assert_dom 'h1', 'Products'
592592
# end
593593
# end
594594
#

guides/source/testing.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,18 +1334,16 @@ require "test_helper"
13341334
class BlogFlowTest < ActionDispatch::IntegrationTest
13351335
test "can see the welcome page" do
13361336
get "/"
1337-
assert_select "h1", "Welcome#index"
1337+
assert_dom "h1", "Welcome#index"
13381338
end
13391339
end
13401340
```
13411341

13421342
If you visit the root path, you should see `welcome/index.html.erb` rendered for
13431343
the view. So this assertion should pass.
13441344

1345-
NOTE: The assertion `assert_select` is available in integration tests to check
1346-
the presence of key HTML elements and their content. It is similar to
1347-
`assert_dom`, which should be used when [testing views](#testing-views) as
1348-
outlined in the section below.
1345+
NOTE: The assertion `assert_dom` (aliased to `assert_select`) is available in integration tests to check
1346+
the presence of key HTML elements and their content.
13491347

13501348
#### Creating Articles Integration
13511349

@@ -1439,7 +1437,7 @@ class UsersTest < ApplicationSystemTestCase
14391437
# test "visiting the index" do
14401438
# visit users_url
14411439
#
1442-
# assert_select "h1", text: "Users"
1440+
# assert_dom "h1", text: "Users"
14431441
# end
14441442
end
14451443
```
@@ -1578,7 +1576,7 @@ require "application_system_test_case"
15781576
class ArticlesTest < ApplicationSystemTestCase
15791577
test "viewing the index" do
15801578
visit articles_path
1581-
assert_select "h1", text: "Articles"
1579+
assert_selector "h1", text: "Articles"
15821580
end
15831581
end
15841582
```
@@ -1654,7 +1652,7 @@ require "mobile_system_test_case"
16541652
class PostsTest < MobileSystemTestCase
16551653
test "visiting the index" do
16561654
visit posts_url
1657-
assert_select "h1", text: "Posts"
1655+
assert_selector "h1", text: "Posts"
16581656
end
16591657
end
16601658
```
@@ -1671,7 +1669,7 @@ which can be used in system tests.
16711669
| `assert_current_path(string, **options)` | Asserts that the page has the given path. |
16721670
| `assert_field(locator = nil, **options, &optional_filter_block)` | Checks if the page has a form field with the given label, name or id. |
16731671
| `assert_link(locator = nil, **options, &optional_filter_block)` | Checks if the page has a link with the given text or id. |
1674-
| `assert_select(*args, &optional_filter_block)` | Asserts that a given selector is on the page. |
1672+
| `assert_selector(*args, &optional_filter_block)` | Asserts that a given selector is on the page. |
16751673
| `assert_table(locator = nil, **options, &optional_filter_block` | Checks if the page has a table with the given id or caption. |
16761674
| `assert_text(type, text, **options)` | Asserts that the page has the given text content. |
16771675

0 commit comments

Comments
 (0)