diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f16b57b7fc..6a9b48d269 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -180,20 +180,6 @@ RSpec/PredicateMatcher: - 'python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb' - 'updater/spec/dependabot/job_spec.rb' -# Offense count: 35 -# This cop supports unsafe autocorrection (--autocorrect-all). -RSpec/ReceiveMessages: - Exclude: - - 'common/spec/dependabot/pull_request_creator/message_builder_spec.rb' - - 'common/spec/dependabot/pull_request_creator_spec.rb' - - 'common/spec/dependabot/registry_client_spec.rb' - - 'common/spec/dependabot/update_checkers/base_spec.rb' - - 'github_actions/spec/dependabot/github_actions/update_checker_spec.rb' - - 'nuget/spec/dependabot/nuget/update_checker_spec.rb' - - 'updater/spec/dependabot/dependency_change_spec.rb' - - 'updater/spec/dependabot/file_fetcher_command_spec.rb' - - 'updater/spec/dependabot/update_files_command_spec.rb' - # Offense count: 4 RSpec/RepeatedExample: Exclude: diff --git a/common/spec/dependabot/pull_request_creator/message_builder_spec.rb b/common/spec/dependabot/pull_request_creator/message_builder_spec.rb index ab9de46e85..c5c9aa74aa 100644 --- a/common/spec/dependabot/pull_request_creator/message_builder_spec.rb +++ b/common/spec/dependabot/pull_request_creator/message_builder_spec.rb @@ -3471,9 +3471,7 @@ def commits_details(base:, head:) pr_message = "PR message" commit_message = "Commit message" before do - allow(builder).to receive(:pr_name).and_return(pr_name) - allow(builder).to receive(:pr_message).and_return(pr_message) - allow(builder).to receive(:commit_message).and_return(commit_message) + allow(builder).to receive_messages(pr_name: pr_name, pr_message: pr_message, commit_message: commit_message) end it "returns a Message" do diff --git a/common/spec/dependabot/pull_request_creator_spec.rb b/common/spec/dependabot/pull_request_creator_spec.rb index 8772d982fb..42198d18dc 100644 --- a/common/spec/dependabot/pull_request_creator_spec.rb +++ b/common/spec/dependabot/pull_request_creator_spec.rb @@ -73,11 +73,8 @@ before do allow(described_class::MessageBuilder) .to receive(:new).once.and_return(dummy_message_builder) - allow(dummy_message_builder) - .to receive(:commit_message) - .and_return("Commit msg") - allow(dummy_message_builder).to receive(:pr_name).and_return("PR name") - allow(dummy_message_builder).to receive(:pr_message).and_return("PR msg") + allow(dummy_message_builder).to receive_messages(commit_message: "Commit msg", pr_name: "PR name", + pr_message: "PR msg") end describe "#create" do diff --git a/common/spec/dependabot/registry_client_spec.rb b/common/spec/dependabot/registry_client_spec.rb index 96313050c1..77f0d5085e 100644 --- a/common/spec/dependabot/registry_client_spec.rb +++ b/common/spec/dependabot/registry_client_spec.rb @@ -14,8 +14,7 @@ end before do - allow(Excon).to receive(:get).and_return(Excon::Response.new) - allow(Excon).to receive(:head).and_return(Excon::Response.new) + allow(Excon).to receive_messages(get: Excon::Response.new, head: Excon::Response.new) end describe "delegation to Excon" do diff --git a/common/spec/dependabot/update_checkers/base_spec.rb b/common/spec/dependabot/update_checkers/base_spec.rb index c30203bdac..f0813a6908 100644 --- a/common/spec/dependabot/update_checkers/base_spec.rb +++ b/common/spec/dependabot/update_checkers/base_spec.rb @@ -48,24 +48,10 @@ before do allow(updater_instance) - .to receive(:latest_version) - .and_return(latest_version) - - allow(updater_instance) - .to receive(:latest_resolvable_version) - .and_return(latest_resolvable_version) - - allow(updater_instance) - .to receive(:latest_resolvable_version_with_no_unlock) - .and_return(latest_resolvable_version_with_no_unlock) - - allow(updater_instance) - .to receive(:latest_resolvable_previous_version) - .and_return(latest_resolvable_previous_version) - - allow(updater_instance) - .to receive(:updated_requirements) - .and_return(updated_requirements) + .to receive_messages(latest_version: latest_version, latest_resolvable_version: latest_resolvable_version, + latest_resolvable_version_with_no_unlock: latest_resolvable_version_with_no_unlock, + latest_resolvable_previous_version: latest_resolvable_previous_version, + updated_requirements: updated_requirements) end describe "#up_to_date?" do diff --git a/github_actions/spec/dependabot/github_actions/update_checker_spec.rb b/github_actions/spec/dependabot/github_actions/update_checker_spec.rb index 5e6d1483f5..5dcc7b2895 100644 --- a/github_actions/spec/dependabot/github_actions/update_checker_spec.rb +++ b/github_actions/spec/dependabot/github_actions/update_checker_spec.rb @@ -480,8 +480,8 @@ before do checker.instance_variable_set(:@git_commit_checker, git_commit_checker) - allow(git_commit_checker).to receive(:branch_or_ref_in_release?).and_return(false) - allow(git_commit_checker).to receive(:head_commit_for_current_branch).and_return(reference) + allow(git_commit_checker).to receive_messages(branch_or_ref_in_release?: false, + head_commit_for_current_branch: reference) allow(Dir).to receive(:chdir).and_yield diff --git a/nuget/spec/dependabot/nuget/update_checker_spec.rb b/nuget/spec/dependabot/nuget/update_checker_spec.rb index 5176f73498..8b99530899 100644 --- a/nuget/spec/dependabot/nuget/update_checker_spec.rb +++ b/nuget/spec/dependabot/nuget/update_checker_spec.rb @@ -169,27 +169,22 @@ def registration_index_url(name) context "when all dependencies can update to the latest version" do before do - allow(checker).to receive(:all_property_based_dependencies).and_return( - [ - Dependabot::Dependency.new( - name: "Nuke.Common", - version: "0.1.434", - requirements: dependency_requirements, - package_manager: "nuget" - ), - Dependabot::Dependency.new( - name: "Nuke.CodeGeneration", - version: "0.1.434", - requirements: dependency_requirements, - package_manager: "nuget" - ) - ] - ) - property_updater_class = described_class::PropertyUpdater dummy_property_updater = instance_double(property_updater_class) - allow(checker).to receive(:latest_version).and_return("0.9.0") - allow(checker).to receive(:property_updater).and_return(dummy_property_updater) + allow(checker).to receive_messages(all_property_based_dependencies: [ + Dependabot::Dependency.new( + name: "Nuke.Common", + version: "0.1.434", + requirements: dependency_requirements, + package_manager: "nuget" + ), + Dependabot::Dependency.new( + name: "Nuke.CodeGeneration", + version: "0.1.434", + requirements: dependency_requirements, + package_manager: "nuget" + ) + ], latest_version: "0.9.0", property_updater: dummy_property_updater) allow(dummy_property_updater).to receive(:update_possible?).and_return(true) end @@ -198,27 +193,22 @@ def registration_index_url(name) context "when all dependencies cannot update to the latest version" do before do - allow(checker).to receive(:all_property_based_dependencies).and_return( - [ - Dependabot::Dependency.new( - name: "Nuke.Common", - version: "0.1.434", - requirements: dependency_requirements, - package_manager: "nuget" - ), - Dependabot::Dependency.new( - name: "Nuke.CodeGeneration", - version: "0.1.434", - requirements: dependency_requirements, - package_manager: "nuget" - ) - ] - ) - property_updater_class = described_class::PropertyUpdater dummy_property_updater = instance_double(property_updater_class) - allow(checker).to receive(:latest_version).and_return("0.9.0") - allow(checker).to receive(:property_updater).and_return(dummy_property_updater) + allow(checker).to receive_messages(all_property_based_dependencies: [ + Dependabot::Dependency.new( + name: "Nuke.Common", + version: "0.1.434", + requirements: dependency_requirements, + package_manager: "nuget" + ), + Dependabot::Dependency.new( + name: "Nuke.CodeGeneration", + version: "0.1.434", + requirements: dependency_requirements, + package_manager: "nuget" + ) + ], latest_version: "0.9.0", property_updater: dummy_property_updater) allow(dummy_property_updater).to receive(:update_possible?).and_return(false) end @@ -412,23 +402,20 @@ def registration_index_url(name) context "when all dependencies can update to the latest version" do before do - allow(checker).to receive(:latest_version).and_return("0.9.0") - allow(checker).to receive(:all_property_based_dependencies).and_return( - [ - Dependabot::Dependency.new( - name: "Nuke.Common", - version: "0.1.434", - requirements: dependency_requirements, - package_manager: "nuget" - ), - Dependabot::Dependency.new( - name: "Nuke.CodeGeneration", - version: "0.1.434", - requirements: dependency_requirements, - package_manager: "nuget" - ) - ] - ) + allow(checker).to receive_messages(latest_version: "0.9.0", all_property_based_dependencies: [ + Dependabot::Dependency.new( + name: "Nuke.Common", + version: "0.1.434", + requirements: dependency_requirements, + package_manager: "nuget" + ), + Dependabot::Dependency.new( + name: "Nuke.CodeGeneration", + version: "0.1.434", + requirements: dependency_requirements, + package_manager: "nuget" + ) + ]) end it "delegates to PropertyUpdater" do diff --git a/updater/spec/dependabot/dependency_change_spec.rb b/updater/spec/dependabot/dependency_change_spec.rb index e8c26f850f..025a8beb07 100644 --- a/updater/spec/dependabot/dependency_change_spec.rb +++ b/updater/spec/dependabot/dependency_change_spec.rb @@ -97,9 +97,8 @@ end before do - allow(job).to receive(:source).and_return(github_source) - allow(job).to receive(:credentials).and_return(job_credentials) - allow(job).to receive(:commit_message_options).and_return(commit_message_options) + allow(job).to receive_messages(source: github_source, credentials: job_credentials, + commit_message_options: commit_message_options) allow(Dependabot::PullRequestCreator::MessageBuilder).to receive(:new).and_return(message_builder_mock) end diff --git a/updater/spec/dependabot/file_fetcher_command_spec.rb b/updater/spec/dependabot/file_fetcher_command_spec.rb index 3267a6c260..2d855cef07 100644 --- a/updater/spec/dependabot/file_fetcher_command_spec.rb +++ b/updater/spec/dependabot/file_fetcher_command_spec.rb @@ -17,8 +17,6 @@ let(:job_id) { "123123" } before do - allow(Dependabot::Environment).to receive(:job_id).and_return(job_id) - allow(Dependabot::Environment).to receive(:job_token).and_return("job_token") allow(Dependabot::ApiClient).to receive(:new).and_return(api_client) allow(api_client).to receive(:mark_job_as_processed) @@ -26,9 +24,11 @@ allow(api_client).to receive(:record_ecosystem_versions) allow(api_client).to receive(:is_a?).with(Dependabot::ApiClient).and_return(true) - allow(Dependabot::Environment).to receive(:output_path).and_return(File.join(Dir.mktmpdir, "output.json")) - allow(Dependabot::Environment).to receive(:job_definition).and_return(job_definition) - allow(Dependabot::Environment).to receive(:job_path).and_return(nil) + allow(Dependabot::Environment).to receive_messages(job_id: job_id, job_token: "job_token", + output_path: File.join(Dir.mktmpdir, + "output.json"), + job_definition: job_definition, + job_path: nil) end describe "#perform_job" do diff --git a/updater/spec/dependabot/update_files_command_spec.rb b/updater/spec/dependabot/update_files_command_spec.rb index ac24d23b1c..20a31a0614 100644 --- a/updater/spec/dependabot/update_files_command_spec.rb +++ b/updater/spec/dependabot/update_files_command_spec.rb @@ -25,10 +25,8 @@ before do allow(Dependabot::Service).to receive(:new).and_return(service) - allow(Dependabot::Environment).to receive(:job_id).and_return(job_id) - allow(Dependabot::Environment).to receive(:job_token).and_return("mock_token") - allow(Dependabot::Environment).to receive(:job_definition).and_return(job_definition) - allow(Dependabot::Environment).to receive(:repo_contents_path).and_return(nil) + allow(Dependabot::Environment).to receive_messages(job_id: job_id, job_token: "mock_token", + job_definition: job_definition, repo_contents_path: nil) end describe "#perform_job" do