Skip to content

Commit

Permalink
Enabling PredicateMatcher Rubocop rule on RSpec. (#9960)
Browse files Browse the repository at this point in the history
* Enabling PredicateMatcher Rubocop rule on RSpec.

* Fixed syntax to make it appear less awkward. .contains? returns a T::Boolean
  • Loading branch information
GarryHurleyJr committed Jun 13, 2024
1 parent e7c27ec commit 6c54922
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 64 deletions.
17 changes: 0 additions & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,6 @@ RSpec/OverwritingSetup:
- 'terraform/spec/dependabot/terraform/file_parser_spec.rb'
- 'updater/spec/dependabot/dependency_snapshot_spec.rb'

# Offense count: 47
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
# SupportedStyles: inflected, explicit
RSpec/PredicateMatcher:
Exclude:
- 'common/spec/dependabot/dependency_file_spec.rb'
- 'common/spec/dependabot/dependency_group_spec.rb'
- 'common/spec/dependabot/experiments_spec.rb'
- 'common/spec/dependabot/file_updaters/artifact_updater_spec.rb'
- 'common/spec/dependabot/file_updaters/vendor_updater_spec.rb'
- 'common/spec/dependabot/workspace/git_spec.rb'
- 'npm_and_yarn/spec/dependabot/npm_and_yarn/update_checker_spec.rb'
- 'pub/spec/dependabot/pub/update_checker_spec.rb'
- 'python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb'
- 'updater/spec/dependabot/job_spec.rb'

# Offense count: 4
RSpec/RepeatedExample:
Exclude:
Expand Down
14 changes: 7 additions & 7 deletions common/spec/dependabot/dependency_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::UPDATE
end
end
Expand Down Expand Up @@ -129,7 +129,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::UPDATE
end
end
Expand Down Expand Up @@ -159,7 +159,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::CREATE
end
end
Expand Down Expand Up @@ -189,7 +189,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::UPDATE
end
end
Expand Down Expand Up @@ -219,7 +219,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_truthy
expect(file.deleted?).to be_truthy
expect(file).to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::DELETE
end
end
Expand Down Expand Up @@ -249,7 +249,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_truthy
expect(file.deleted?).to be_truthy
expect(file).to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::DELETE
end
end
Expand Down Expand Up @@ -280,7 +280,7 @@

it "has the correct operation properties" do
expect(file.deleted).to be_truthy
expect(file.deleted?).to be_truthy
expect(file).to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::DELETE
end
end
Expand Down
26 changes: 13 additions & 13 deletions common/spec/dependabot/dependency_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@
context "when no dependencies are assigned to the group" do
it "returns true if the dependency matches a pattern" do
expect(dependency_group.dependencies).to eq([])
expect(dependency_group.contains?(test_dependency1)).to be_truthy
expect(dependency_group.contains?(test_dependency1)).to be(true)
end

it "returns false if the dependency is specifically excluded" do
expect(dependency_group.dependencies).to eq([])
expect(dependency_group.contains?(test_dependency2)).to be_falsey
expect(dependency_group.contains?(test_dependency2)).to be(false)
end

it "returns false if the dependency does not match any patterns" do
expect(dependency_group.dependencies).to eq([])
expect(dependency_group.contains?(production_dependency)).to be_falsey
expect(dependency_group.contains?(production_dependency)).to be(false)
end
end

Expand All @@ -138,17 +138,17 @@

it "returns true if the dependency is in the dependency list" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.contains?(test_dependency1)).to be_truthy
expect(dependency_group.contains?(test_dependency1)).to be(true)
end

it "returns false if the dependency is specifically excluded" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.contains?(test_dependency2)).to be_falsey
expect(dependency_group.contains?(test_dependency2)).to be(false)
end

it "returns false if the dependency is not in the dependency list and does not match a pattern" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.contains?(production_dependency)).to be_falsey
expect(dependency_group.contains?(production_dependency)).to be(false)
end
end
end
Expand All @@ -161,12 +161,12 @@
end

it "returns true if the dependency matches the specified type" do
expect(dependency_group.contains?(production_dependency)).to be_truthy
expect(dependency_group.contains?(production_dependency)).to be(true)
end

it "returns false if the dependency does not match the specified type" do
expect(dependency_group.contains?(test_dependency1)).to be_falsey
expect(dependency_group.contains?(test_dependency2)).to be_falsey
expect(dependency_group.contains?(test_dependency1)).to be(false)
expect(dependency_group.contains?(test_dependency2)).to be(false)
end

context "when a dependency is specifically excluded" do
Expand All @@ -178,7 +178,7 @@
end

it "returns false even if the dependency matches the specified type" do
expect(dependency_group.contains?(production_dependency)).to be_falsey
expect(dependency_group.contains?(production_dependency)).to be(false)
end
end
end
Expand All @@ -193,15 +193,15 @@
end

it "returns true if the dependency matches the specified type and a pattern" do
expect(dependency_group.contains?(test_dependency1)).to be_truthy
expect(dependency_group.contains?(test_dependency1)).to be(true)
end

it "returns false if the dependency only matches the pattern" do
expect(dependency_group.contains?(production_dependency)).to be_falsey
expect(dependency_group.contains?(production_dependency)).to be(false)
end

it "returns false if the dependency matches the specified type and pattern but is excluded" do
expect(dependency_group.contains?(test_dependency2)).to be_falsey
expect(dependency_group.contains?(test_dependency2)).to be(false)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions common/spec/dependabot/experiments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
it "can register experiments as enabled" do
described_class.register(:my_test, true)

expect(described_class.enabled?(:my_test)).to be_truthy
expect(described_class).to be_enabled(:my_test)
end

it "works with string names and symbols" do
described_class.register("my_test", true)

expect(described_class.enabled?("my_test")).to be_truthy
expect(described_class.enabled?(:my_test)).to be_truthy
expect(described_class).to be_enabled("my_test")
expect(described_class).to be_enabled(:my_test)
end
end
14 changes: 7 additions & 7 deletions common/spec/dependabot/file_updaters/artifact_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
f.name == "vendor/cache/business-1.5.0.gem"
end

expect(file.binary?).to be_truthy
expect(file).to be_binary
end

it "marks created files as such" do
Expand All @@ -67,7 +67,7 @@
end

expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::CREATE
end

Expand All @@ -77,7 +77,7 @@
end

expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::UPDATE
end

Expand All @@ -87,7 +87,7 @@
end

expect(file.deleted).to be_truthy
expect(file.deleted?).to be_truthy
expect(file).to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::DELETE
end

Expand Down Expand Up @@ -132,15 +132,15 @@
f.name == "vendor/cache/iso8859.txt"
end

expect(file.binary?).to be_truthy
expect(file).to be_binary
end

it "does not mark all files as binary" do
file = updated_files.find do |f|
f.name == "vendor/cache/utf8.txt"
end

expect(file.binary?).to be_falsy
expect(file).not_to be_binary
end
end

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

file = updated_files.find { |f| f.name == "vendor/cache/new_#{name}" }

expect(file.binary?).to be_truthy
expect(file).to be_binary
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions common/spec/dependabot/file_updaters/vendor_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
f.name == "vendor/cache/business-1.5.0.gem"
end

expect(file.binary?).to be_truthy
expect(file).to be_binary
end

it "marks created files as such" do
Expand All @@ -66,7 +66,7 @@
end

expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::CREATE
end

Expand All @@ -76,7 +76,7 @@
end

expect(file.deleted).to be_falsey
expect(file.deleted?).to be_falsey
expect(file).not_to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::UPDATE
end

Expand All @@ -86,7 +86,7 @@
end

expect(file.deleted).to be_truthy
expect(file.deleted?).to be_truthy
expect(file).to be_deleted
expect(file.operation).to eq Dependabot::DependencyFile::Operation::DELETE
end

Expand Down Expand Up @@ -131,15 +131,15 @@
f.name == "vendor/cache/iso8859.txt"
end

expect(file.binary?).to be_truthy
expect(file).to be_binary
end

it "does not mark all files as binary" do
file = updated_files.find do |f|
f.name == "vendor/cache/utf8.txt"
end

expect(file.binary?).to be_falsy
expect(file).not_to be_binary
end
end

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

file = updated_files.find { |f| f.name == "vendor/cache/new_#{name}" }

expect(file.binary?).to be_truthy
expect(file).to be_binary
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions common/spec/dependabot/workspace/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
expect(workspace.change_attempts.first.memo).to eq("timecop")
expect(workspace.change_attempts.first.error).not_to be_nil
expect(workspace.change_attempts.first.error.message).to eq("uh oh")
expect(workspace.change_attempts.first.error?).to be_truthy
expect(workspace.change_attempts.first.success?).to be_falsy
expect(workspace.change_attempts.first).to be_error
expect(workspace.change_attempts.first).not_to be_success
end

context "when there are untracked/ignored files" do
Expand Down Expand Up @@ -243,8 +243,8 @@
)
expect(workspace.change_attempts.first.memo).to eq("Update timecop")
expect(workspace.change_attempts.first.error).to be_nil
expect(workspace.change_attempts.first.error?).to be_falsy
expect(workspace.change_attempts.first.success?).to be_truthy
expect(workspace.change_attempts.first).not_to be_error
expect(workspace.change_attempts.first).to be_success
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
end

it "returns false when there is a newer version available" do
expect(checker.up_to_date?).to be_falsy
expect(checker).not_to be_up_to_date
end
end

Expand All @@ -177,7 +177,7 @@
end

it "is up to date because there's nothing to update" do
expect(checker.up_to_date?).to be_truthy
expect(checker).to be_up_to_date
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion pub/spec/dependabot/pub/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@
end

it "can update" do
expect(checker.vulnerable?).to be_truthy
expect(checker).to be_vulnerable
expect(checker.lowest_resolvable_security_fix_version).to eq("2.0.0")
expect(updated_dependencies).to eq [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
source: nil
}]
)
expect(dependency.production?).to be_truthy
expect(dependency).to be_production
end
end

Expand Down
4 changes: 2 additions & 2 deletions updater/spec/dependabot/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@

it "registers the experiments with Dependabot::Experiments" do
job
expect(Dependabot::Experiments.enabled?(:kebab_case)).to be_truthy
expect(Dependabot::Experiments.enabled?(:simpe)).to be_falsey
expect(Dependabot::Experiments).to be_enabled(:kebab_case)
expect(Dependabot::Experiments).not_to be_enabled(:simpe)
end
end

Expand Down

0 comments on commit 6c54922

Please sign in to comment.