Skip to content

Commit

Permalink
enable receive messages (#9935)
Browse files Browse the repository at this point in the history
* Enabling the Rubocop rule for ReceiveMessages
  • Loading branch information
GarryHurleyJr authored Jun 7, 2024
1 parent b645880 commit cc93d42
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 111 deletions.
14 changes: 0 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions common/spec/dependabot/pull_request_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions common/spec/dependabot/registry_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 4 additions & 18 deletions common/spec/dependabot/update_checkers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
97 changes: 42 additions & 55 deletions nuget/spec/dependabot/nuget/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions updater/spec/dependabot/dependency_change_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions updater/spec/dependabot/file_fetcher_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
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)
allow(api_client).to receive(:record_update_job_error)
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
Expand Down
6 changes: 2 additions & 4 deletions updater/spec/dependabot/update_files_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cc93d42

Please sign in to comment.