Skip to content

Commit

Permalink
Merge pull request #1138 from publify/update-rubocop-capybara
Browse files Browse the repository at this point in the history
Handle new rubocop-capybara offenses
  • Loading branch information
mvz committed Sep 30, 2023
2 parents 1e11c02 + c855dca commit 8163a7c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ inherit_mode:
- Exclude

require:
- rubocop-capybara
- rubocop-performance
- rubocop-rails
- rubocop-rspec
Expand All @@ -24,6 +25,10 @@ Rails:
Bundler/DuplicatedGem:
Enabled: false

# Doesn't work well yet
Capybara/ClickLinkOrButtonStyle:
Enabled: false

Layout/BeginEndAlignment:
EnforcedStyleAlignWith: begin

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ group :development, :test do
gem "pry-rails", "~> 0.3.4"
gem "rspec-rails", "~> 6.0"
gem "rubocop", "~> 1.56.0", require: false
gem "rubocop-capybara", "~> 2.19.0", require: false
gem "rubocop-performance", "~> 1.19.0", require: false
gem "rubocop-rails", "~> 2.21.0", require: false
gem "rubocop-rspec", "~> 2.23.1", require: false
Expand Down
34 changes: 17 additions & 17 deletions spec/controllers/articles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@

it "has a good title" do
expect(response.body).
to have_selector("title", text: "A big article | test blog",
visible: :all)
to have_css("title", text: "A big article | test blog",
visible: :all)
end
end

Expand Down Expand Up @@ -124,14 +124,14 @@

it "has good link feed rss" do
expect(response.body).
to have_selector('head>link[href="http://test.host/articles.rss"]',
visible: :all)
to have_css('head>link[href="http://test.host/articles.rss"]',
visible: :all)
end

it "has good link feed atom" do
expect(response.body).
to have_selector('head>link[href="http://test.host/articles.atom"]',
visible: :all)
to have_css('head>link[href="http://test.host/articles.atom"]',
visible: :all)
end

it "has a canonical url" do
Expand All @@ -141,7 +141,7 @@

it "has good title" do
expect(response.body).
to have_selector("title", text: "test blog | test subtitle", visible: :all)
to have_css("title", text: "test blog | test subtitle", visible: :all)
end
end

Expand Down Expand Up @@ -174,7 +174,7 @@

it "has a good title" do
expect(response.body).
to have_selector("title", text: "Archives for test blog", visible: :all)
to have_css("title", text: "Archives for test blog", visible: :all)
end
end
end
Expand All @@ -198,7 +198,7 @@

it "renders content with markdown interpreted and html tags removed" do
expect(response.body).
to have_selector(
to have_css(
"div", text: /in markdown format\s+we\s+use\s+ok to define a link/)
end
end
Expand Down Expand Up @@ -230,16 +230,16 @@
get :search, params: { q: "oba" }

expect(response.body).
to have_selector('head>link[href="http://test.host/search/oba.rss"]',
visible: :all)
to have_css('head>link[href="http://test.host/search/oba.rss"]',
visible: :all)
end

it "has good atom feed link" do
get :search, params: { q: "oba" }

expect(response.body).
to have_selector('head>link[href="http://test.host/search/oba.atom"]',
visible: :all)
to have_css('head>link[href="http://test.host/search/oba.atom"]',
visible: :all)
end

it "has a canonical url" do
Expand All @@ -254,8 +254,8 @@
get :search, params: { q: "oba" }

expect(response.body).
to have_selector("title", text: "Results for oba | test blog",
visible: :all)
to have_css("title", text: "Results for oba | test blog",
visible: :all)
end

it "renders feed rss by search" do
Expand Down Expand Up @@ -294,7 +294,7 @@
end

it "does not have h3 tag" do
expect(response.body).to have_selector("h3")
expect(response.body).to have_css("h3")
end
end

Expand All @@ -310,7 +310,7 @@
expect(response.body).
to have_selector("head>link[href='#{blog.base_url}/archives']",
visible: :all).
and have_selector("title", text: "Archives for test blog", visible: :all)
and have_css("title", text: "Archives for test blog", visible: :all)
end

it "shows the current month only once" do
Expand Down
40 changes: 20 additions & 20 deletions spec/views/comments/html_sanitization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@
ActiveSupport::Deprecation.silence do
render partial: "comments/comment", locals: { comment: @comment }
end
expect(rendered).to have_selector(".content")
expect(rendered).to have_selector(".author")
expect(rendered).to have_css(".content")
expect(rendered).to have_css(".author")

expect(rendered).not_to have_selector(".content script")
expect(rendered).not_to have_selector(".content a:not([rel=nofollow])")
expect(rendered).not_to have_css(".content script")
expect(rendered).not_to have_css(".content a:not([rel=nofollow])")
# No links with javascript
expect(rendered).not_to have_selector(".content a[onclick]")
expect(rendered).not_to have_selector('.content a[href^="javascript:"]')
expect(rendered).not_to have_css(".content a[onclick]")
expect(rendered).not_to have_css('.content a[href^="javascript:"]')

expect(rendered).not_to have_selector(".author script")
expect(rendered).not_to have_selector(".author a:not([rel=nofollow])")
expect(rendered).not_to have_css(".author script")
expect(rendered).not_to have_css(".author a:not([rel=nofollow])")
# No links with javascript
expect(rendered).not_to have_selector(".author a[onclick]")
expect(rendered).not_to have_selector('.author a[href^="javascript:"]')
expect(rendered).not_to have_css(".author a[onclick]")
expect(rendered).not_to have_css('.author a[href^="javascript:"]')
end
end
end
Expand Down Expand Up @@ -174,20 +174,20 @@ def comment_options
ActiveSupport::Deprecation.silence do
render partial: "comments/comment", locals: { comment: @comment }
end
expect(rendered).to have_selector(".content")
expect(rendered).to have_selector(".author")
expect(rendered).to have_css(".content")
expect(rendered).to have_css(".author")

expect(rendered).not_to have_selector(".content script")
expect(rendered).not_to have_selector(".content a[rel=nofollow]")
expect(rendered).not_to have_css(".content script")
expect(rendered).not_to have_css(".content a[rel=nofollow]")
# No links with javascript
expect(rendered).not_to have_selector(".content a[onclick]")
expect(rendered).not_to have_selector('.content a[href^="javascript:"]')
expect(rendered).not_to have_css(".content a[onclick]")
expect(rendered).not_to have_css('.content a[href^="javascript:"]')

expect(rendered).not_to have_selector(".author script")
expect(rendered).not_to have_selector(".author a[rel=nofollow]")
expect(rendered).not_to have_css(".author script")
expect(rendered).not_to have_css(".author a[rel=nofollow]")
# No links with javascript
expect(rendered).not_to have_selector(".author a[onclick]")
expect(rendered).not_to have_selector('.author a[href^="javascript:"]')
expect(rendered).not_to have_css(".author a[onclick]")
expect(rendered).not_to have_css('.author a[href^="javascript:"]')
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/views/layouts/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
it "has keyword meta tag when use_meta_keyword set to true" do
create(:blog, use_meta_keyword: true)
render
expect(rendered).to have_selector('head>meta[name="keywords"]', visible: :all)
expect(rendered).to have_css('head>meta[name="keywords"]', visible: :all)
end

it "does not have keyword meta tag when use_meta_keyword set to false" do
create(:blog, use_meta_keyword: false)
render
expect(rendered).not_to have_selector('head>meta[name="keywords"]', visible: :all)
expect(rendered).not_to have_css('head>meta[name="keywords"]', visible: :all)
end
end
end
Expand Down

0 comments on commit 8163a7c

Please sign in to comment.