From b3060bc475ce2b8cdab7f1a70aff0fc6df83d5a3 Mon Sep 17 00:00:00 2001 From: rhymes Date: Fri, 10 Jul 2020 11:23:02 +0200 Subject: [PATCH] Fix Style/SingleLineBlockParams, RSpec/MultipleExpectations and remaining Layout/LineLength (#9204) * Fix Style/SingleLineBlockParams * Fix RSpec/MultipleExpectations and Layout/LineLength * Restore test to previous version for speed * Remove useless params --- .rubocop.yml | 6 ++++++ .rubocop_todo.yml | 11 ----------- app/labor/markdown_fixer.rb | 6 +++--- ...ex_feed_content_and_users_to_elasticsearch_spec.rb | 7 ++++--- .../broadcasts/welcome_notification/generator_spec.rb | 2 ++ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 429518d7a..13d9d2c4e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -452,3 +452,9 @@ RSpec/ExampleLength: Enabled: true Max: 15 StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleLength + +RSpec/MultipleExpectations: + Description: Checks if examples contain too many `expect` calls. + Enabled: true + Max: 8 + StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5594d28b2..7a0336edc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,10 +37,6 @@ Performance/OpenStruct: - 'spec/models/github_repo_spec.rb' - 'spec/requests/github_repos_spec.rb' -# Offense count: 930 -RSpec/MultipleExpectations: - Max: 12 - # Offense count: 16 Rails/OutputSafety: Exclude: @@ -58,10 +54,3 @@ Rails/OutputSafety: Rails/UniqueValidationWithoutIndex: Exclude: - 'app/models/article.rb' - -# Offense count: 3 -# Configuration parameters: Methods. -# Methods: {"reduce"=>["acc", "elem"]}, {"inject"=>["acc", "elem"]} -Style/SingleLineBlockParams: - Exclude: - - 'app/labor/markdown_fixer.rb' diff --git a/app/labor/markdown_fixer.rb b/app/labor/markdown_fixer.rb index 32887684e..9c401976d 100644 --- a/app/labor/markdown_fixer.rb +++ b/app/labor/markdown_fixer.rb @@ -7,17 +7,17 @@ class MarkdownFixer add_quotes_to_title add_quotes_to_description modify_hr_tags convert_new_lines split_tags underscores_in_usernames ] - methods.reduce(markdown) { |result, method| send(method, result) } + methods.reduce(markdown) { |acc, elem| send(elem, acc) } end def fix_for_preview(markdown) methods = %i[add_quotes_to_title add_quotes_to_description modify_hr_tags underscores_in_usernames] - methods.reduce(markdown) { |result, method| send(method, result) } + methods.reduce(markdown) { |acc, elem| send(elem, acc) } end def fix_for_comment(markdown) methods = %I[modify_hr_tags underscores_in_usernames] - methods.reduce(markdown) { |result, method| send(method, result) } + methods.reduce(markdown) { |acc, elem| send(elem, acc) } end def add_quotes_to_title(markdown) diff --git a/spec/lib/data_update_scripts/re_index_feed_content_and_users_to_elasticsearch_spec.rb b/spec/lib/data_update_scripts/re_index_feed_content_and_users_to_elasticsearch_spec.rb index 4e7cf15eb..7abc89311 100644 --- a/spec/lib/data_update_scripts/re_index_feed_content_and_users_to_elasticsearch_spec.rb +++ b/spec/lib/data_update_scripts/re_index_feed_content_and_users_to_elasticsearch_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/ExampleLength require "rails_helper" require Rails.root.join("lib/data_update_scripts/20200519142908_re_index_feed_content_and_users_to_elasticsearch.rb") @@ -8,7 +7,8 @@ describe DataUpdateScripts::ReIndexFeedContentAndUsersToElasticsearch do Search::User.refresh_index end - it "indexes feed content(articles, comments, podcast episodes) and users to Elasticsearch" do + # rubocop:disable RSpec/ExampleLength + it "indexes feed content(articles, comments, podcast episodes) and users to Elasticsearch", :aggregate_failures do article = create(:article) podcast_episode = create(:podcast_episode) comment = create(:comment) @@ -20,6 +20,7 @@ describe DataUpdateScripts::ReIndexFeedContentAndUsersToElasticsearch do expect { user.elasticsearch_doc }.to raise_error(Search::Errors::Transport::NotFound) sidekiq_perform_enqueued_jobs { described_class.new.run } + expect(article.elasticsearch_doc).not_to be_nil expect(podcast_episode.elasticsearch_doc).not_to be_nil expect(comment.elasticsearch_doc).not_to be_nil @@ -30,5 +31,5 @@ describe DataUpdateScripts::ReIndexFeedContentAndUsersToElasticsearch do expect(comment.elasticsearch_doc["_source"].keys).to include "public_reactions_count" expect(user.elasticsearch_doc["_source"].keys).to include "public_reactions_count" end + # rubocop:enable RSpec/ExampleLength end -# rubocop:enable RSpec/ExampleLength diff --git a/spec/services/broadcasts/welcome_notification/generator_spec.rb b/spec/services/broadcasts/welcome_notification/generator_spec.rb index 9ac72065d..9fa97471a 100644 --- a/spec/services/broadcasts/welcome_notification/generator_spec.rb +++ b/spec/services/broadcasts/welcome_notification/generator_spec.rb @@ -42,6 +42,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do end # rubocop:disable RSpec/ExampleLength + # rubocop:disable RSpec/MultipleExpectations it "sends only 1 notification at a time, in the correct order" do user.update!(created_at: 1.day.ago) @@ -93,6 +94,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do expect(user.notifications.last.notifiable).to eq(download_app_broadcast) Timecop.return end + # rubocop:enable RSpec/MultipleExpectations # rubocop:enable RSpec/ExampleLength end