Add and apply Capybara/VisibilityMatcher rule

This rule was added in rubocop-rspec 1.39.0. The `visible: false` option
is equivalent to `visible: :all`, but we generally use it meaning
`visible: :hidden` for positive expectations and `visible: :all` for
negative expectations.

The only exceptations are tests where we count the number of map icons
present. I'm assuming in this case we care about the number of map icons
independently on whether they are currently shown in the map, so I'm
keeping the `visible: :all` behavior in this case.
This commit is contained in:
Javi Martín
2020-10-13 18:29:37 +02:00
parent 6088334dbf
commit dd7d6440ec
12 changed files with 35 additions and 30 deletions

View File

@@ -26,6 +26,9 @@ Capybara/FeatureMethods:
- scenario
- xscenario
Capybara/VisibilityMatcher:
Enabled: true
FactoryBot/AttributeDefinedStatically:
Enabled: true

View File

@@ -30,7 +30,8 @@ shared_examples "flaggable" do |factory_name, admin: false|
click_link "Flag as inappropriate"
expect(page).to have_css ".flag-active"
expect(page).to have_link "Unflag", visible: false
expect(page).to have_link "Unflag", visible: :hidden
expect(page).not_to have_link "Flag as inappropriate", visible: :all
end
expect(Flag.flagged?(user, flaggable)).to be
@@ -49,7 +50,8 @@ shared_examples "flaggable" do |factory_name, admin: false|
click_link "Unflag"
expect(page).not_to have_css ".flag-active"
expect(page).to have_link "Flag as inappropriate", visible: false
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
expect(Flag.flagged?(user, flaggable)).not_to be

View File

@@ -74,7 +74,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_link "Add new document"
within "#nested-documents" do
document = find(".document input[type=file]", visible: false)
document = find(".document input[type=file]", visible: :hidden)
attach_file(
document[:id],
Rails.root.join("spec/fixtures/files/empty.pdf"),
@@ -106,7 +106,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
within "#nested-documents" do
input = find("input[name$='[title]']")
fill_in input[:id], with: "My Title"
document_input = find("input[type=file]", visible: false)
document_input = find("input[type=file]", visible: :hidden)
attach_file(
document_input[:id],
Rails.root.join("spec/fixtures/files/empty.pdf"),
@@ -314,7 +314,7 @@ def documentable_attach_new_file(path, success = true)
click_link "Add new document"
document = all("#new_document").last
document_input = document.find("input[type=file]", visible: false)
document_input = document.find("input[type=file]", visible: :hidden)
attach_file(document_input[:id], path, make_visible: true)
within document do
@@ -338,7 +338,7 @@ def expect_document_has_cached_attachment(index, extension)
document = all(".document")[index]
within document do
expect(find("input[name$='[cached_attachment]']", visible: false).value).to end_with(extension)
expect(find("input[name$='[cached_attachment]']", visible: :hidden).value).to end_with(extension)
end
end

View File

@@ -34,7 +34,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
click_link "Add image"
image_input = find(".image").find("input[type=file]", visible: false)
image_input = find(".image").find("input[type=file]", visible: :hidden)
attach_file(
image_input[:id],
Rails.root.join("spec/fixtures/files/clippy.jpg"),
@@ -63,7 +63,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Add image"
input_title = find(".image input[name$='[title]']")
fill_in input_title[:id], with: "Title"
image_input = find(".image").find("input[type=file]", visible: false)
image_input = find(".image").find("input[type=file]", visible: :hidden)
attach_file(
image_input[:id],
Rails.root.join("spec/fixtures/files/clippy.jpg"),
@@ -261,7 +261,7 @@ def imageable_attach_new_file(_imageable_factory_name, path, success = true)
click_link "Add image"
within "#nested-image" do
image = find(".image")
image_input = image.find("input[type=file]", visible: false)
image_input = image.find("input[type=file]", visible: :hidden)
attach_file(image_input[:id], path, make_visible: true)
within image do
if success
@@ -299,7 +299,7 @@ def expect_image_has_cached_attachment(extension)
image = find(".image")
within image do
expect(find("input[name$='[cached_attachment]']", visible: false).value).to end_with(extension)
expect(find("input[name$='[cached_attachment]']", visible: :hidden).value).to end_with(extension)
end
end
end

View File

@@ -67,7 +67,7 @@ describe "Admin poll questions" do
expect(page).to have_content("Create question to poll Movies")
expect(page).to have_selector("input[id='poll_question_poll_id'][value='#{poll.id}']",
visible: false)
visible: :hidden)
fill_in "Question", with: title
click_button "Save"

View File

@@ -40,7 +40,7 @@ describe "Admin settings" do
login_as(admin)
visit admin_settings_path
expect(page).not_to have_css("#admin-map.leaflet-container", visible: false)
expect(page).not_to have_css("#admin-map.leaflet-container", visible: :all)
end
scenario "When `Map settings` tab content is shown map should be initialized" do
@@ -101,8 +101,8 @@ describe "Admin settings" do
visit admin_settings_path
expect(find("#latitude", visible: false).value).to eq "51.48"
expect(find("#longitude", visible: false).value).to eq "0.0"
expect(find("#latitude", visible: :hidden).value).to eq "51.48"
expect(find("#longitude", visible: :hidden).value).to eq "0.0"
end
scenario "Should update marker", :js do
@@ -117,7 +117,7 @@ describe "Admin settings" do
click_on "Update"
end
expect(find("#latitude", visible: false).value).not_to eq "51.48"
expect(find("#latitude", visible: :hidden).value).not_to eq "51.48"
expect(page).to have_content "Map configuration updated succesfully"
end
end

View File

@@ -285,7 +285,7 @@ describe "Budgets" do
visit budgets_path
within ".map_location" do
expect(page).to have_css(".map-icon", count: 3, visible: false)
expect(page).to have_css(".map-icon", count: 3, visible: :all)
end
end
@@ -305,7 +305,7 @@ describe "Budgets" do
visit budgets_path
within ".map_location" do
expect(page).to have_css(".map-icon", count: 4, visible: false)
expect(page).to have_css(".map-icon", count: 4, visible: :all)
end
end
@@ -325,7 +325,7 @@ describe "Budgets" do
visit budgets_path
within ".map_location" do
expect(page).to have_css(".map-icon", count: 2, visible: false)
expect(page).to have_css(".map-icon", count: 2, visible: :all)
end
end
@@ -354,7 +354,7 @@ describe "Budgets" do
visit budgets_path
within ".map_location" do
expect(page).to have_css(".map-icon", count: 1, visible: false)
expect(page).to have_css(".map-icon", count: 1, visible: :all)
end
end
end

View File

@@ -1815,7 +1815,7 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id)
within ".map_location" do
expect(page).to have_css(".map-icon", count: 6, visible: false)
expect(page).to have_css(".map-icon", count: 6, visible: :all)
end
end
@@ -1829,7 +1829,7 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id)
within ".map_location" do
expect(page).to have_css(".map-icon", count: 2, visible: false)
expect(page).to have_css(".map-icon", count: 2, visible: :all)
end
end
@@ -1853,7 +1853,7 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id)
within ".map_location" do
expect(page).to have_css(".map-icon", count: 4, visible: false)
expect(page).to have_css(".map-icon", count: 4, visible: :all)
end
end
@@ -1871,7 +1871,7 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id)
within ".map_location" do
expect(page).to have_css(".map-icon", count: 0, visible: false)
expect(page).to have_css(".map-icon", count: 0, visible: :all)
end
end
@@ -1889,7 +1889,7 @@ describe "Budget Investments" do
end
within(".map_location") do
expect(page).to have_css(".map-icon", count: 3, visible: false)
expect(page).to have_css(".map-icon", count: 3, visible: :all)
end
end

View File

@@ -82,8 +82,8 @@ describe "Home" do
visit root_path
expect(page).to have_selector("li[data-slide='0']")
expect(page).to have_selector("li[data-slide='1']", visible: false)
expect(page).to have_selector("li[data-slide='2']", visible: false)
expect(page).to have_selector("li[data-slide='1']", visible: :hidden)
expect(page).to have_selector("li[data-slide='2']", visible: :hidden)
end
scenario "Display recommended show when click on carousel" do

View File

@@ -100,6 +100,6 @@ describe "Account" do
expect(page).to have_content "Password reseted successfully"
expect(page).to have_css("a[href='javascript:window.print();']", text: "Print password")
expect(page).to have_css("div.for-print-only", text: "another_new_password", visible: false)
expect(page).to have_css("div.for-print-only", text: "another_new_password", visible: :hidden)
end
end

View File

@@ -175,7 +175,7 @@ describe "Notifications" do
visit notifications_path
expect(page).to have_content("Notification title")
expect(page).to have_content("Notification body")
expect(page).not_to have_link(notification_path(notification), visible: false)
expect(page).not_to have_link(notification_path(notification), visible: :all)
end
end

View File

@@ -323,8 +323,8 @@ describe "Proposals" do
proposal = create(:proposal)
visit proposal_path(proposal)
expect(page).to have_css "meta[name='twitter:title'][content=\'#{proposal.title}\']", visible: false
expect(page).to have_css "meta[property='og:title'][content=\'#{proposal.title}\']", visible: false
expect(page).to have_css "meta[name='twitter:title'][content=\'#{proposal.title}\']", visible: :hidden
expect(page).to have_css "meta[property='og:title'][content=\'#{proposal.title}\']", visible: :hidden
end
scenario "Create and publish" do