-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a `:status` selector in the same style as the `:alert` selector. Additionally, extend both the `:alert` and `:status` selectors to accept text as a locator argument.
- Loading branch information
1 parent
fcf7a9c
commit 9db73c5
Showing
10 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
Capybara.add_selector(:alert) do | ||
xpath do |*| | ||
XPath.descendant[XPath.attr(:role) == "alert"] | ||
xpath do |locator, *| | ||
XPath.descendant[XPath.attr(:role) == "alert"][XPath.string.n.is(locator.to_s)] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
Capybara.add_selector(:status) do | ||
xpath do |locator, *| | ||
XPath.descendant[XPath.attr(:role) == "status"][XPath.string.is(locator.to_s)] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!doctype html> | ||
<meta charset="UTF-8" /> | ||
<div role="status"> | ||
Status message | ||
<div> | ||
|
||
<div> | ||
Just a message | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "have_status" do | ||
before do | ||
visit "/status.html" | ||
end | ||
|
||
it "matches using a custom matcher" do | ||
expect(page).to have_status("Status") | ||
expect(page).to have_status(text: "Status") | ||
end | ||
|
||
it "matches using a negated custom matcher" do | ||
expect(page).to have_no_status("foo") | ||
expect(page).to have_no_status(text: "foo") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "status selector" do | ||
before do | ||
visit "/status.html" | ||
end | ||
|
||
it "finds statuses without arguments" do | ||
status = page.find(:css, "[role=status]") | ||
expect(page.find(:status)).to eq status | ||
end | ||
|
||
it "finds statuses with a locator" do | ||
status = page.find(:css, "[role=status]") | ||
expect(page.find(:status, "Status message")).to eq status | ||
end | ||
|
||
it "finds statuses with a text: filter" do | ||
status = page.find(:css, "[role=status]") | ||
expect(page.find(:status, text: "Status message")).to eq status | ||
end | ||
|
||
it "matches selector" do | ||
status = page.find(:css, "[role=status]") | ||
expect(status).to match_selector :status | ||
end | ||
end |