Use have_current_path instead of include

Using `have_current_path`, Capybara waits until the condition is true,
while using `include` the expectation is evaluated immediately and so
tests might fail when using a driver supporting JavaScript.

Besides, using `have_current_path` the error message is more readable
when the test fails.
This commit is contained in:
Javi Martín
2021-03-25 19:47:49 +01:00
parent b7ec9bc20c
commit 7127b46d9f
17 changed files with 49 additions and 48 deletions

View File

@@ -86,7 +86,7 @@ describe "Admin hidden budget investments", :admin do
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -127,7 +127,7 @@ describe "Admin hidden comments", :admin do
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -73,7 +73,7 @@ describe "Admin hidden debates", :admin do
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -83,7 +83,7 @@ describe "Admin hidden proposals", :admin do
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -84,7 +84,7 @@ describe "Admin hidden users", :admin do
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -210,7 +210,7 @@ describe "Admin::Organizations" do
click_on("Verify", match: :first)
expect(current_url).to include("filter=pending")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=pending/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -82,7 +82,7 @@ describe "Admin proposal notifications", :admin do
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
expect(page).to have_current_path(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/)
end
end

View File

@@ -372,8 +372,8 @@ describe "Budget Investments" do
expect(medium_proposal.title).to appear_before(worst_proposal.title)
end
expect(current_url).to include("order=confidence_score")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=confidence_score/)
expect(page).to have_current_path(/page=1/)
end
scenario "Each user has a different and consistent random budget investment order" do
@@ -1192,8 +1192,8 @@ describe "Budget Investments" do
expect(mid_investment.title).to appear_before(low_investment.title)
end
expect(current_url).to include("order=price")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=price/)
expect(page).to have_current_path(/page=1/)
end
scenario "Show" do

View File

@@ -408,8 +408,8 @@ describe "Debates" do
expect(medium_debate.title).to appear_before(worst_debate.title)
end
expect(current_url).to include("order=confidence_score")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=confidence_score/)
expect(page).to have_current_path(/page=1/)
end
scenario "Debates are ordered by newest", :js do
@@ -427,8 +427,8 @@ describe "Debates" do
expect(medium_debate.title).to appear_before(worst_debate.title)
end
expect(current_url).to include("order=created_at")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=created_at/)
expect(page).to have_current_path(/page=1/)
end
context "Recommendations" do
@@ -494,8 +494,8 @@ describe "Debates" do
expect(medium_debate.title).to appear_before(worst_debate.title)
end
expect(current_url).to include("order=recommendations")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=recommendations/)
expect(page).to have_current_path(/page=1/)
end
scenario "are not shown if account setting is disabled" do

View File

@@ -214,8 +214,8 @@ describe "Proposals" do
expect(page).to have_selector(".js-order-selector[data-order='created_at']")
expect(current_url).to include("order=created_at")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=created_at/)
expect(page).to have_current_path(/page=1/)
within(".proposals-list") do
expect(medium_proposal.title).to appear_before(best_proposal.title)

View File

@@ -121,9 +121,9 @@ describe "Moderate budget investments" do
expect(page).to have_selector(".js-order-selector[data-order='created_at']")
expect(current_url).to include("filter=all")
expect(current_url).to include("page=2")
expect(current_url).to include("order=created_at")
expect(page).to have_current_path(/filter=all/)
expect(page).to have_current_path(/page=2/)
expect(page).to have_current_path(/order=created_at/)
end
end

View File

@@ -134,9 +134,9 @@ describe "Moderate comments" do
expect(page).to have_selector(".js-order-selector[data-order='newest']")
expect(current_url).to include("filter=all")
expect(current_url).to include("page=2")
expect(current_url).to include("order=newest")
expect(page).to have_current_path(/filter=all/)
expect(page).to have_current_path(/page=2/)
expect(page).to have_current_path(/order=newest/)
end
end

View File

@@ -107,9 +107,9 @@ describe "Moderate debates" do
expect(page).to have_selector(".js-order-selector[data-order='created_at']")
expect(current_url).to include("filter=all")
expect(current_url).to include("page=2")
expect(current_url).to include("order=created_at")
expect(page).to have_current_path(/filter=all/)
expect(page).to have_current_path(/page=2/)
expect(page).to have_current_path(/order=created_at/)
end
end

View File

@@ -110,9 +110,9 @@ describe "Moderate proposal notifications" do
expect(page).to have_selector(".js-order-selector[data-order='created_at']")
expect(current_url).to include("filter=all")
expect(current_url).to include("page=2")
expect(current_url).to include("order=created_at")
expect(page).to have_current_path(/filter=all/)
expect(page).to have_current_path(/page=2/)
expect(page).to have_current_path(/order=created_at/)
end
end

View File

@@ -106,9 +106,9 @@ describe "Moderate proposals" do
expect(page).to have_selector(".js-order-selector[data-order='created_at']")
expect(current_url).to include("filter=all")
expect(current_url).to include("page=2")
expect(current_url).to include("order=created_at")
expect(page).to have_current_path(/filter=all/)
expect(page).to have_current_path(/page=2/)
expect(page).to have_current_path(/order=created_at/)
end
end

View File

@@ -155,7 +155,8 @@ describe "Notifications" do
expect(page).to have_content("Notification body")
first("#notification_#{notification.id} a").click
expect(page.current_url).to eq("https://www.external.link.dev/")
expect(page).to have_current_path "https://www.external.link.dev/", url: true
end
scenario "With internal link", :js do

View File

@@ -812,8 +812,8 @@ describe "Proposals" do
expect(medium_proposal.title).to appear_before(worst_proposal.title)
end
expect(current_url).to include("order=confidence_score")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=confidence_score/)
expect(page).to have_current_path(/page=1/)
end
scenario "Proposals are ordered by newest", :js do
@@ -830,8 +830,8 @@ describe "Proposals" do
expect(medium_proposal.title).to appear_before(worst_proposal.title)
end
expect(current_url).to include("order=created_at")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=created_at/)
expect(page).to have_current_path(/page=1/)
end
context "Recommendations" do
@@ -897,8 +897,8 @@ describe "Proposals" do
expect(medium_proposal.title).to appear_before(worst_proposal.title)
end
expect(current_url).to include("order=recommendations")
expect(current_url).to include("page=1")
expect(page).to have_current_path(/order=recommendations/)
expect(page).to have_current_path(/page=1/)
end
scenario "are not shown if account setting is disabled" do