From 13bf8117e4d1731a64a3d2bf8d1f56a000b4bfb0 Mon Sep 17 00:00:00 2001 From: Rob Aiken Date: Thu, 23 May 2024 17:43:01 +0100 Subject: [PATCH] Enable All RSpec empty line cops (#9791) * Enable RSpec/EmptyLineAfterExample * Enable RSpec/EmptyLineAfterExampleGroup * Enable RSpec/EmptyLineAfterFinalLet * Enable RSpec/EmptyLineAfterHook * Enable RSpec/EmptyLineAfterSubject --- .rubocop_todo.yml | 37 ------- bundler/helpers/v2/spec/functions_spec.rb | 1 + bundler/helpers/v2/spec/ruby_version_spec.rb | 2 + .../file_fetcher/child_gemfile_finder_spec.rb | 2 + .../file_fetcher/gemspec_finder_spec.rb | 2 + .../file_fetcher/path_gemspec_finder_spec.rb | 2 + .../require_relative_finder_spec.rb | 5 + .../dependabot/bundler/file_fetcher_spec.rb | 1 + .../bundler/file_parser/file_preparer_spec.rb | 1 + .../gemfile_declaration_finder_spec.rb | 6 + .../gemspec_declaration_finder_spec.rb | 5 + .../dependabot/bundler/file_parser_spec.rb | 32 ++++++ .../file_updater/gemfile_updater_spec.rb | 14 +++ .../gemspec_dependency_name_finder_spec.rb | 1 + .../file_updater/gemspec_sanitizer_spec.rb | 32 ++++++ .../file_updater/git_pin_replacer_spec.rb | 4 + .../file_updater/git_source_remover_spec.rb | 7 ++ .../file_updater/requirement_replacer_spec.rb | 25 +++++ .../ruby_requirement_setter_spec.rb | 11 ++ .../dependabot/bundler/file_updater_spec.rb | 4 + .../bundler/metadata_finder_spec.rb | 7 ++ .../dependabot/bundler/requirement_spec.rb | 2 + .../update_checker/file_preparer_spec.rb | 21 ++++ .../latest_version_finder_spec.rb | 14 +++ .../requirements_updater_spec.rb | 61 ++++++++++ .../update_checker/version_resolver_spec.rb | 19 ++++ .../dependabot/bundler/update_checker_spec.rb | 6 + .../dependabot/cargo/file_fetcher_spec.rb | 10 ++ .../spec/dependabot/cargo/file_parser_spec.rb | 5 + .../file_updater/manifest_updater_spec.rb | 1 + .../dependabot/cargo/metadata_finder_spec.rb | 3 + .../spec/dependabot/cargo/requirement_spec.rb | 24 ++++ .../update_checker/file_preparer_spec.rb | 3 + .../latest_version_finder_spec.rb | 34 ++++++ .../requirements_updater_spec.rb | 42 +++++++ .../update_checker/version_resolver_spec.rb | 3 + .../dependabot/cargo/update_checker_spec.rb | 10 ++ cargo/spec/dependabot/cargo/version_spec.rb | 15 +++ common/spec/dependabot/clients/azure_spec.rb | 2 + .../spec/dependabot/clients/bitbucket_spec.rb | 2 + .../dependabot/clients/codecommit_spec.rb | 2 + .../clients/github_with_retries_spec.rb | 1 + .../dependabot/config/file_fetcher_spec.rb | 2 + .../config/ignore_condition_spec.rb | 7 ++ .../dependabot/config/update_config_spec.rb | 2 + .../spec/dependabot/dependency_file_spec.rb | 5 + common/spec/dependabot/errors_spec.rb | 6 + .../dependabot/file_fetchers/base_spec.rb | 13 +++ .../shared_examples_for_file_fetchers.rb | 1 + .../file_parsers/base/dependency_set_spec.rb | 3 + .../spec/dependabot/file_parsers/base_spec.rb | 2 + .../shared_examples_for_file_parsers.rb | 1 + .../dependabot/file_updaters/base_spec.rb | 3 + .../shared_examples_for_file_updaters.rb | 1 + .../dependabot/git_commit_checker_spec.rb | 59 ++++++++++ .../dependabot/git_metadata_fetcher_spec.rb | 9 ++ .../base/changelog_finder_spec.rb | 16 +++ .../base/changelog_pruner_spec.rb | 5 + .../base/commits_finder_spec.rb | 8 ++ .../base/release_finder_spec.rb | 9 ++ .../dependabot/metadata_finders/base_spec.rb | 11 ++ .../shared_examples_for_metadata_finders.rb | 1 + .../pull_request_creator/azure_spec.rb | 2 + .../branch_namer/solo_strategy_spec.rb | 2 + .../pull_request_creator/branch_namer_spec.rb | 2 + .../pull_request_creator/github_spec.rb | 6 + .../pull_request_creator/labeler_spec.rb | 38 +++++++ .../message_builder/issue_linker_spec.rb | 4 + .../link_and_mention_sanitizer_spec.rb | 13 +++ .../message_builder_spec.rb | 19 ++++ .../pr_name_prefixer_spec.rb | 15 +++ .../dependabot/pull_request_creator_spec.rb | 1 + .../pull_request_updater/github_spec.rb | 2 + .../spec/dependabot/security_advisory_spec.rb | 24 ++++ common/spec/dependabot/shared_helpers_spec.rb | 5 + common/spec/dependabot/source_spec.rb | 40 +++++++ .../dependabot/update_checkers/base_spec.rb | 44 ++++++++ .../shared_examples_for_update_checkers.rb | 1 + .../spec/dependabot/wildcard_matcher_spec.rb | 27 +++++ .../path_dependency_builder_spec.rb | 2 + .../dependabot/composer/file_fetcher_spec.rb | 2 + .../dependabot/composer/file_parser_spec.rb | 17 +++ .../composer/metadata_finder_spec.rb | 2 + .../dependabot/composer/requirement_spec.rb | 15 +++ .../latest_version_finder_spec.rb | 19 ++++ .../requirements_updater_spec.rb | 104 ++++++++++++++++++ .../composer/update_checker_spec.rb | 15 +++ .../spec/dependabot/composer/version_spec.rb | 7 ++ .../devcontainers/file_fetcher_spec.rb | 1 + .../dependabot/docker/file_parser_spec.rb | 49 +++++++++ .../dependabot/docker/file_updater_spec.rb | 12 ++ .../dependabot/docker/requirement_spec.rb | 5 + .../dependabot/docker/update_checker_spec.rb | 40 +++++++ .../docker/utils/credentials_finder_spec.rb | 3 + elm/spec/dependabot/elm/file_fetcher_spec.rb | 2 + elm/spec/dependabot/elm/file_parser_spec.rb | 1 + .../dependabot/elm/metadata_finder_spec.rb | 1 + elm/spec/dependabot/elm/requirement_spec.rb | 11 ++ .../elm_19_version_resolver_spec.rb | 3 + .../requirements_updater_spec.rb | 4 + .../dependabot/elm/update_checker_spec.rb | 12 ++ elm/spec/dependabot/elm/version_spec.rb | 11 ++ .../git_submodules/metadata_finder_spec.rb | 9 ++ .../git_submodules/requirement_spec.rb | 2 + .../git_submodules/update_checker_spec.rb | 5 + .../github_actions/file_parser_spec.rb | 15 +++ .../github_actions/file_updater_spec.rb | 4 + .../github_actions/metadata_finder_spec.rb | 1 + .../github_actions/requirement_spec.rb | 2 + .../github_actions/update_checker_spec.rb | 25 +++++ .../go_modules/file_fetcher_spec.rb | 1 + .../file_updater/go_mod_updater_spec.rb | 5 + .../go_modules/metadata_finder_spec.rb | 2 + .../go_modules/path_converter_spec.rb | 7 ++ .../go_modules/replace_stubber_spec.rb | 3 + .../dependabot/go_modules/requirement_spec.rb | 36 ++++++ .../dependabot/go_modules/version_spec.rb | 19 ++++ .../file_parser/property_value_finder_spec.rb | 59 ++++++++++ .../file_parser/repositories_finder_spec.rb | 1 + .../dependabot/gradle/file_parser_spec.rb | 2 + .../dependabot/gradle/file_updater_spec.rb | 8 ++ .../dependabot/gradle/metadata_finder_spec.rb | 10 ++ .../dependabot/gradle/requirement_spec.rb | 25 +++++ .../multi_dependency_updater_spec.rb | 2 + .../requirements_updater_spec.rb | 10 ++ .../update_checker/version_finder_spec.rb | 38 +++++++ .../dependabot/gradle/update_checker_spec.rb | 13 +++ gradle/spec/dependabot/gradle/version_spec.rb | 54 +++++++++ gradle/spec/dependabot/gradle_spec.rb | 1 + .../dependabot/hex/metadata_finder_spec.rb | 2 + hex/spec/dependabot/hex/requirement_spec.rb | 11 ++ .../hex/update_checker/file_preparer_spec.rb | 1 + .../requirements_updater_spec.rb | 16 +++ .../dependabot/hex/update_checker_spec.rb | 24 ++++ hex/spec/dependabot/hex/version_spec.rb | 29 +++++ .../dependabot/maven/file_fetcher_spec.rb | 13 +++ .../maven/file_parser/pom_fetcher_spec.rb | 1 + .../file_parser/property_value_finder_spec.rb | 15 +++ .../file_parser/repositories_finder_spec.rb | 4 + .../dependabot/maven/file_updater_spec.rb | 3 + .../dependabot/maven/metadata_finder_spec.rb | 13 +++ .../spec/dependabot/maven/requirement_spec.rb | 25 +++++ .../update_checker/property_updater_spec.rb | 3 + .../requirements_updater_spec.rb | 8 ++ .../update_checker/version_finder_spec.rb | 31 ++++++ .../dependabot/maven/update_checker_spec.rb | 16 +++ .../maven/utils/auth_headers_finder_spec.rb | 2 + maven/spec/dependabot/maven/version_spec.rb | 58 ++++++++++ maven/spec/dependabot/maven_spec.rb | 1 + .../npm_and_yarn/file_fetcher_spec.rb | 2 + .../file_parser/lockfile_parser_spec.rb | 6 + .../npm_and_yarn/file_parser_spec.rb | 59 ++++++++++ .../file_updater/npmrc_builder_spec.rb | 11 ++ .../file_updater/package_json_updater_spec.rb | 1 + .../npm_and_yarn/file_updater_spec.rb | 5 + .../npm_and_yarn/metadata_finder_spec.rb | 6 + .../npm_and_yarn/requirement_spec.rb | 49 +++++++++ .../dependency_files_builder_spec.rb | 10 ++ .../latest_version_finder_spec.rb | 17 +++ .../update_checker/library_detector_spec.rb | 11 ++ .../update_checker/registry_finder_spec.rb | 7 ++ .../requirements_updater_spec.rb | 61 ++++++++++ .../update_checker/version_resolver_spec.rb | 27 +++++ .../npm_and_yarn/update_checker_spec.rb | 33 ++++++ .../dependabot/npm_and_yarn/version_spec.rb | 32 ++++++ .../file_fetcher/import_paths_finder_spec.rb | 5 + .../dependabot/nuget/file_fetcher_spec.rb | 1 + .../spec/dependabot/nuget/file_parser_spec.rb | 3 + .../dependabot/nuget/metadata_finder_spec.rb | 2 + .../nuget_config_credential_helpers_spec.rb | 1 + .../spec/dependabot/nuget/requirement_spec.rb | 12 ++ .../compatibility_checker_spec.rb | 1 + .../update_checker/dependency_finder_spec.rb | 2 + .../update_checker/nupkg_fetcher_spec.rb | 2 + .../update_checker/nuspec_fetcher_spec.rb | 6 + .../update_checker/repository_finder_spec.rb | 4 + .../requirements_updater_spec.rb | 9 ++ .../update_checker/version_finder_spec.rb | 18 +++ .../dependabot/nuget/update_checker_spec.rb | 3 + nuget/spec/dependabot/nuget/version_spec.rb | 17 +++ pub/spec/dependabot/pub/file_fetcher_spec.rb | 2 + pub/spec/dependabot/pub/file_parser_spec.rb | 3 + pub/spec/dependabot/pub/file_updater_spec.rb | 4 + .../dependabot/pub/infer_sdk_versions_spec.rb | 4 + .../dependabot/pub/metadata_finder_spec.rb | 3 + pub/spec/dependabot/pub/requirements_spec.rb | 13 +++ .../dependabot/pub/update_checker_spec.rb | 45 ++++++++ pub/spec/dependabot/pub/version_spec.rb | 13 +++ .../dependabot/python/file_fetcher_spec.rb | 20 ++++ .../file_parser/pipfile_files_parser_spec.rb | 19 ++++ .../pyproject_files_parser_spec.rb | 6 + .../python_requirement_parser_spec.rb | 6 + .../file_parser/setup_file_parser_spec.rb | 8 ++ .../dependabot/python/file_parser_spec.rb | 14 +++ .../pip_compile_file_updater_spec.rb | 1 + .../file_updater/pipfile_file_updater_spec.rb | 1 + .../pipfile_manifest_updater_spec.rb | 1 + .../file_updater/poetry_file_updater_spec.rb | 2 + .../file_updater/pyproject_preparer_spec.rb | 4 + .../requirement_file_updater_spec.rb | 7 ++ .../file_updater/requirement_replacer_spec.rb | 7 ++ .../file_updater/setup_file_sanitizer_spec.rb | 1 + .../dependabot/python/metadata_finder_spec.rb | 8 ++ .../python/requirement_parser_spec.rb | 31 ++++++ .../dependabot/python/requirement_spec.rb | 35 ++++++ .../update_checker/index_finder_spec.rb | 1 + .../latest_version_finder_spec.rb | 42 +++++++ .../pip_compile_version_resolver_spec.rb | 9 ++ .../pip_version_resolver_spec.rb | 5 + .../pipenv_version_resolver_spec.rb | 14 +++ .../poetry_version_resolver_spec.rb | 11 ++ .../requirements_updater_spec.rb | 99 +++++++++++++++++ .../dependabot/python/update_checker_spec.rb | 10 ++ python/spec/dependabot/python/version_spec.rb | 22 ++++ .../dependabot/terraform/file_parser_spec.rb | 9 ++ .../terraform/metadata_finder_spec.rb | 2 + .../terraform/registry_client_spec.rb | 1 + .../dependabot/terraform/requirement_spec.rb | 4 + .../terraform/requirements_updater_spec.rb | 10 ++ .../terraform/update_checker_spec.rb | 7 ++ .../spec/dependabot/terraform/version_spec.rb | 4 + updater/spec/dependabot/api_client_spec.rb | 7 ++ updater/spec/dependabot/job_spec.rb | 11 ++ .../dependabot/update_files_command_spec.rb | 1 + 224 files changed, 2776 insertions(+), 37 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3c06a16e31..bd7e2ce612 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -90,43 +90,6 @@ RSpec/DescribedClass: - 'updater/spec/dependabot/api_client_spec.rb' - 'updater/spec/dependabot/job_spec.rb' -# Offense count: 173 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterExample: - Enabled: false - -# Offense count: 25 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterExampleGroup: - Exclude: - - 'common/spec/dependabot/pull_request_creator/message_builder_spec.rb' - - 'composer/spec/dependabot/composer/file_fetcher_spec.rb' - - 'docker/spec/dependabot/docker/file_updater_spec.rb' - - 'github_actions/spec/dependabot/github_actions/file_updater_spec.rb' - - 'gradle/spec/dependabot/gradle/file_updater_spec.rb' - - 'npm_and_yarn/spec/dependabot/npm_and_yarn/update_checker_spec.rb' - - 'pub/spec/dependabot/pub/requirements_spec.rb' - - 'pub/spec/dependabot/pub/update_checker_spec.rb' - - 'terraform/spec/dependabot/terraform/requirement_spec.rb' - - 'terraform/spec/dependabot/terraform/requirements_updater_spec.rb' - -# Offense count: 2162 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterFinalLet: - Enabled: false - -# Offense count: 114 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterHook: - Enabled: false - -# Offense count: 288 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterSubject: - Enabled: false - # Offense count: 1286 # Configuration parameters: CountAsOne. RSpec/ExampleLength: diff --git a/bundler/helpers/v2/spec/functions_spec.rb b/bundler/helpers/v2/spec/functions_spec.rb index a8e84ad280..92aba9eec1 100644 --- a/bundler/helpers/v2/spec/functions_spec.rb +++ b/bundler/helpers/v2/spec/functions_spec.rb @@ -25,6 +25,7 @@ describe "#git_specs" do let(:project_name) { "git_source" } + subject(:git_specs) do in_tmp_folder do Functions.git_specs( diff --git a/bundler/helpers/v2/spec/ruby_version_spec.rb b/bundler/helpers/v2/spec/ruby_version_spec.rb index 6e68b88276..6acf0e3660 100644 --- a/bundler/helpers/v2/spec/ruby_version_spec.rb +++ b/bundler/helpers/v2/spec/ruby_version_spec.rb @@ -9,10 +9,12 @@ include_context "when stubbing rubygems compact index" let(:project_name) { "ruby_version_implied" } + before do @ui = Bundler.ui Bundler.ui = Bundler::UI::Silent.new end + after { Bundler.ui = @ui } it "updates to the most recent version" do diff --git a/bundler/spec/dependabot/bundler/file_fetcher/child_gemfile_finder_spec.rb b/bundler/spec/dependabot/bundler/file_fetcher/child_gemfile_finder_spec.rb index 0aff061ff8..443d83488c 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher/child_gemfile_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher/child_gemfile_finder_spec.rb @@ -16,11 +16,13 @@ context "when the file does not include any child Gemfiles" do let(:gemfile) { bundler_project_dependency_file("gemfile", filename: "Gemfile") } + it { is_expected.to eq([]) } end context "when the file does include a child Gemfile" do let(:gemfile) { bundler_project_dependency_file("eval_gemfile_gemfile", filename: "Gemfile") } + it { is_expected.to eq(["backend/Gemfile"]) } context "when path must be eval-ed" do diff --git a/bundler/spec/dependabot/bundler/file_fetcher/gemspec_finder_spec.rb b/bundler/spec/dependabot/bundler/file_fetcher/gemspec_finder_spec.rb index fd7ce05cec..4e4902c950 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher/gemspec_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher/gemspec_finder_spec.rb @@ -14,6 +14,7 @@ context "when the file does not include any gemspecs" do let(:gemfile) { bundler_project_dependency_file("gemfile", filename: "Gemfile") } + it { is_expected.to eq([]) } end @@ -32,6 +33,7 @@ context "when the file does include a gemspec reference" do let(:gemfile) { bundler_project_dependency_file("imports_gemspec", filename: "Gemfile") } + it { is_expected.to eq([Pathname.new(".")]) } context "when that has a path specified" do diff --git a/bundler/spec/dependabot/bundler/file_fetcher/path_gemspec_finder_spec.rb b/bundler/spec/dependabot/bundler/file_fetcher/path_gemspec_finder_spec.rb index 200cb865b6..b7e310704a 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher/path_gemspec_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher/path_gemspec_finder_spec.rb @@ -33,6 +33,7 @@ context "when the file does include a path gemspec" do let(:gemfile) { bundler_project_dependency_file("path_source", filename: "Gemfile") } + it { is_expected.to eq([Pathname.new("plugins/example")]) } context "when the path must be eval-ed" do @@ -56,6 +57,7 @@ context "when that is behind a conditional that is false" do let(:gemfile) { bundler_project_dependency_file("path_source_if", filename: "Gemfile") } + it { is_expected.to eq([Pathname.new("plugins/example")]) } end end diff --git a/bundler/spec/dependabot/bundler/file_fetcher/require_relative_finder_spec.rb b/bundler/spec/dependabot/bundler/file_fetcher/require_relative_finder_spec.rb index 99ded4984e..effa20b816 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher/require_relative_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher/require_relative_finder_spec.rb @@ -19,6 +19,7 @@ context "when the file does not include any relative paths" do let(:file_body) { bundler_project_dependency_file("gemfile", filename: "Gemfile").content } + it { is_expected.to eq([]) } end @@ -46,6 +47,7 @@ let(:file_body) do 'require_relative "../some_other_file.rb"' end + it { is_expected.to eq(["../some_other_file.rb"]) } end @@ -54,12 +56,14 @@ let(:file_body) do 'require_relative "./my_file_#{raise %(hell)}"' end + it { is_expected.to eq([]) } context "when it can't be" do let(:file_body) do 'require_relative "./my_file_#{unknown_var}"' end + it { is_expected.to eq([]) } end end @@ -67,6 +71,7 @@ context "when dealing with a file that is already nested" do let(:file_name) { "deeply/nested/Gemfile" } + it { is_expected.to eq(["deeply/some_other_file.rb"]) } end end diff --git a/bundler/spec/dependabot/bundler/file_fetcher_spec.rb b/bundler/spec/dependabot/bundler/file_fetcher_spec.rb index 3a0be7a0f9..cd7fa34105 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher_spec.rb @@ -31,6 +31,7 @@ end before { allow(file_fetcher_instance).to receive(:commit).and_return("sha") } + before do stub_request(:get, File.join(url, ".ruby-version?ref=sha")) .with(headers: { "Authorization" => "token token" }) diff --git a/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb b/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb index 4021f2ee94..597b2ef6b6 100644 --- a/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb +++ b/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb @@ -15,6 +15,7 @@ describe "the updated Gemfile" do subject { prepared_dependency_files.find { |f| f.name == "Gemfile" } } + its(:content) { is_expected.to include('gem "business", "~> 1.4.0"') } end diff --git a/bundler/spec/dependabot/bundler/file_parser/gemfile_declaration_finder_spec.rb b/bundler/spec/dependabot/bundler/file_parser/gemfile_declaration_finder_spec.rb index b894a8e2d9..5942c4bb49 100644 --- a/bundler/spec/dependabot/bundler/file_parser/gemfile_declaration_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_parser/gemfile_declaration_finder_spec.rb @@ -31,6 +31,7 @@ context "when the file does not include the dependency" do let(:dependency_name) { "dependabot-core" } + it { is_expected.to eq(false) } end @@ -38,11 +39,13 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: "#Lol this is just a comment", name: "Gemfile") end + it { is_expected.to eq(false) } end context "when the file does include the dependency" do let(:dependency_name) { "business" } + it { is_expected.to eq(true) } context "when it's in a source block" do @@ -66,6 +69,7 @@ context "when the file does not include the dependency" do let(:dependency_name) { "dependabot-core" } + it { is_expected.to be_nil } end @@ -80,6 +84,7 @@ context "when the file does include the dependency" do let(:dependency_name) { "business" } let(:dependency_requirement_sting) { "~> 1.4.0" } + it { is_expected.to eq("~> 1.4.0") } context "when doesn't specify a requirement" do @@ -109,6 +114,7 @@ context "when doesn't match the original string" do let(:dependency_requirement_sting) { "~> 1.4.0.pre.rc2" } + it { is_expected.to eq("~> 1.4.0.pre.rc2") } end end diff --git a/bundler/spec/dependabot/bundler/file_parser/gemspec_declaration_finder_spec.rb b/bundler/spec/dependabot/bundler/file_parser/gemspec_declaration_finder_spec.rb index 6f5ff76fd2..901bd12999 100644 --- a/bundler/spec/dependabot/bundler/file_parser/gemspec_declaration_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_parser/gemspec_declaration_finder_spec.rb @@ -31,26 +31,31 @@ context "when the file does not include the dependency" do let(:dependency_name) { "dependabot-core" } + it { is_expected.to eq(false) } end context "when the file does include the dependency as `add_dependency`" do let(:dependency_name) { "excon" } + it { is_expected.to eq(true) } end context "when the file does include the dependency as `add_runtime_dependency`" do let(:dependency_name) { "bundler" } + it { is_expected.to eq(true) } end context "when the file does include the dependency as `add_development_dependency`" do let(:dependency_name) { "webmock" } + it { is_expected.to eq(true) } end context "when the file loads the dependency dynamically" do let(:dependency_name) { "rake" } + it { is_expected.to eq(false) } end end diff --git a/bundler/spec/dependabot/bundler/file_parser_spec.rb b/bundler/spec/dependabot/bundler/file_parser_spec.rb index f38b256f29..f4a1c27897 100644 --- a/bundler/spec/dependabot/bundler/file_parser_spec.rb +++ b/bundler/spec/dependabot/bundler/file_parser_spec.rb @@ -35,6 +35,7 @@ describe "the first dependency" do subject { dependencies.first } + let(:expected_requirements) do [{ requirement: "~> 1.4.0", @@ -57,6 +58,7 @@ describe "the first dependency" do subject { dependencies.first } + let(:expected_requirements) do [{ requirement: "~> 1.4.0-rc1", @@ -78,6 +80,7 @@ describe "the first dependency" do let(:dependency_files) { bundler_project_dependency_files("version_not_specified") } subject { dependencies.first } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -101,6 +104,7 @@ describe "the first dependency" do subject { dependencies.first } + let(:expected_requirements) do [{ requirement: "> 1.0.0, < 1.5.0", @@ -116,10 +120,12 @@ context "with development dependencies" do let(:dependency_files) { bundler_project_dependency_files("development_dependencies") } + its(:length) { is_expected.to eq(2) } describe "the last dependency" do subject { dependencies.last } + let(:expected_requirements) do [{ requirement: "~> 1.4.0", @@ -143,6 +149,7 @@ describe "the first dependency" do subject { dependencies.first } + let(:expected_requirements) do [{ requirement: "~> 1.4.0", @@ -166,6 +173,7 @@ describe "an untagged dependency", :bundler_v1_only do subject { dependencies.find { |d| d.name == "uk_phone_numbers" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -182,6 +190,7 @@ it { is_expected.to be_a(Dependabot::Dependency) } its(:requirements) { is_expected.to eq(expected_requirements) } + its(:version) do is_expected.to eq("1530024bd6a68d36ac18e04836ce110e0d433c36") end @@ -189,6 +198,7 @@ describe "an untagged dependency", :bundler_v2_only do subject { dependencies.find { |d| d.name == "uk_phone_numbers" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -205,6 +215,7 @@ it { is_expected.to be_a(Dependabot::Dependency) } its(:requirements) { is_expected.to eq(expected_requirements) } + its(:version) do is_expected.to eq("1530024bd6a68d36ac18e04836ce110e0d433c36") end @@ -212,6 +223,7 @@ describe "a tagged dependency" do subject { dependencies.find { |d| d.name == "que" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -228,6 +240,7 @@ it { is_expected.to be_a(Dependabot::Dependency) } its(:requirements) { is_expected.to eq(expected_requirements) } + its(:version) do is_expected.to eq("997d1a6ee76a1f254fd72ce16acbc8d347fcaee3") end @@ -237,6 +250,7 @@ let(:dependency_files) { bundler_project_dependency_files("github_source") } subject { dependencies.find { |d| d.name == "business" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -253,6 +267,7 @@ it { is_expected.to be_a(Dependabot::Dependency) } its(:requirements) { is_expected.to eq(expected_requirements) } + its(:version) do is_expected.to eq("d31e445215b5af70c1604715d97dd953e868380e") end @@ -262,6 +277,7 @@ let(:dependency_files) { bundler_project_dependency_files("github_source") } subject { dependencies.find { |d| d.name == "business" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -278,6 +294,7 @@ it { is_expected.to be_a(Dependabot::Dependency) } its(:requirements) { is_expected.to eq(expected_requirements) } + its(:version) do is_expected.to eq("d31e445215b5af70c1604715d97dd953e868380e") end @@ -287,6 +304,7 @@ let(:dependency_files) { bundler_project_dependency_files("git_source_undeclared") } subject { dependencies.find { |d| d.name == "kaminari-actionview" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -310,6 +328,7 @@ let(:dependency_files) { bundler_project_dependency_files("git_source_undeclared") } subject { dependencies.find { |d| d.name == "kaminari-actionview" } } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -362,6 +381,7 @@ let(:dependency_files) { bundler_project_dependency_files("subdependency") } its(:length) { is_expected.to eq(2) } + it "is included" do expect(dependencies.map(&:name)).to include("i18n") end @@ -371,6 +391,7 @@ let(:dependency_files) { bundler_project_dependency_files("platform_windows") } its(:length) { is_expected.to eq(1) } + it "is not included" do expect(dependencies.map(&:name)).to_not include("statesman") end @@ -413,6 +434,7 @@ context "with a gem from a private gem source" do let(:dependency_files) { bundler_project_dependency_files("specified_source") } + its(:length) { is_expected.to eq(2) } describe "the private dependency" do @@ -451,6 +473,7 @@ context "with a gem from the default source, specified as a block" do let(:dependency_files) { bundler_project_dependency_files("block_source_rubygems") } + its(:length) { is_expected.to eq(2) } describe "the first dependency" do @@ -659,6 +682,7 @@ describe "a runtime gemspec dependency" do subject { dependencies.find { |dep| dep.name == "gitlab" } } + let(:expected_requirements) do [{ requirement: "~> 4.1", @@ -676,6 +700,7 @@ describe "a development gemspec dependency" do subject { dependencies.find { |dep| dep.name == "webmock" } } + let(:expected_requirements) do [{ requirement: "~> 2.3.1", @@ -726,6 +751,7 @@ context "with a gemspec and Gemfile (no lockfile)" do let(:dependency_files) { bundler_project_dependency_files("imports_gemspec_no_lockfile") } + its(:length) { is_expected.to eq(13) } context "when a dependency appears in both" do @@ -735,6 +761,7 @@ describe "the first dependency" do subject { dependencies.first } + let(:expected_requirements) do [ { @@ -760,6 +787,7 @@ it { is_expected.to be_a(Dependabot::Dependency) } its(:name) { is_expected.to eq("business") } its(:version) { is_expected.to be_nil } + its(:requirements) do is_expected.to match_array(expected_requirements) end @@ -774,6 +802,7 @@ describe "the last dependency" do subject { dependencies.last } + let(:expected_requirements) do [{ requirement: ">= 0", @@ -791,6 +820,7 @@ context "when that needs to be sanitized" do let(:dependency_files) { bundler_project_dependency_files("gemspec_with_require_no_lockfile") } + its(:length) { is_expected.to eq(11) } end end @@ -802,6 +832,7 @@ describe "the first dependency" do subject { dependencies.first } + let(:expected_requirements) do [{ requirement: "~> 1.4.0", @@ -821,6 +852,7 @@ let(:dependency_files) { bundler_project_dependency_files("platform_windows_no_lockfile") } its(:length) { is_expected.to eq(1) } + it "is not included" do expect(dependencies.map(&:name)).to_not include("statesman") end diff --git a/bundler/spec/dependabot/bundler/file_updater/gemfile_updater_spec.rb b/bundler/spec/dependabot/bundler/file_updater/gemfile_updater_spec.rb index 422fd5a4f4..97c9a07cd5 100644 --- a/bundler/spec/dependabot/bundler/file_updater/gemfile_updater_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/gemfile_updater_spec.rb @@ -50,6 +50,7 @@ let(:previous_requirements) do [{ file: "Gemfile", requirement: ">= 0", groups: [], source: nil }] end + it { is_expected.to eq(gemfile.content) } end @@ -126,6 +127,7 @@ source: nil }] end + it { is_expected.to include "\"business\", \"~> 1.5.0\"" } end @@ -139,6 +141,7 @@ let(:previous_requirements) do [{ file: "Gemfile", requirement: "~> 1.4", groups: [], source: nil }] end + it { is_expected.to include "\"business\", \"~> 1.5\"" } it { is_expected.to include "\"statesman\", \"~> 1.2\"" } end @@ -166,6 +169,7 @@ package_manager: "bundler" ) end + it { is_expected.to include "\"i18n\", \"~> 0.5.0\"" } end @@ -173,6 +177,7 @@ let(:gemfile) do bundler_project_dependency_file("comments_no_lockfile", filename: "Gemfile") end + it do is_expected.to include "\"business\", \"~> 1.5.0\" # Business time" end @@ -182,6 +187,7 @@ let(:gemfile) do bundler_project_dependency_file("interpolated_version_no_lockfile", filename: "Gemfile") end + it { is_expected.to include "\"business\", \"~> #" } end @@ -189,6 +195,7 @@ let(:gemfile) do bundler_project_dependency_file("function_version_gemfile", filename: "Gemfile") end + it { is_expected.to include "\"business\", version" } end @@ -357,6 +364,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it { is_expected.to eq(%(gem "dependabot-test-ruby-package")) } end @@ -368,6 +376,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it do is_expected.to eq( %(gem "dependabot-test-ruby-package", "~> 1.1.0", require: false) @@ -383,6 +392,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it do is_expected.to eq( %(gem "dependabot-test-ruby-package", "~> 1.1.0", require: false) @@ -398,6 +408,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it do is_expected.to eq( %(gem("dependabot-test-ruby-package", "~> 1.1.0", require: false)) @@ -413,6 +424,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it do is_expected.to eq( %(gem "dependabot-test-ruby-package", '~> 1.1.0', require: false) @@ -427,6 +439,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it do is_expected.to eq(%(gem "dependabot-test-ruby-package", "~> 1.1.0")) end @@ -439,6 +452,7 @@ let(:gemfile) do Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") end + it do is_expected.to eq(%(gem "dependabot-test-ruby-package" # My gem)) end diff --git a/bundler/spec/dependabot/bundler/file_updater/gemspec_dependency_name_finder_spec.rb b/bundler/spec/dependabot/bundler/file_updater/gemspec_dependency_name_finder_spec.rb index a60f01cd15..8edc36b7de 100644 --- a/bundler/spec/dependabot/bundler/file_updater/gemspec_dependency_name_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/gemspec_dependency_name_finder_spec.rb @@ -20,6 +20,7 @@ let(:gemspec_content) do bundler_project_dependency_file("gemfile_function_name", filename: "example.gemspec").content end + it { is_expected.to be_nil } end end diff --git a/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb b/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb index bba66e0588..b8ab59ad2b 100644 --- a/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb @@ -14,6 +14,7 @@ describe "#rewrite" do subject(:rewrite) { sanitizer.rewrite(content) } + let(:content) do bundler_project_dependency_file("gemfile_with_require", filename: "example.gemspec").content end @@ -54,12 +55,14 @@ let(:content) do %(version = File.read("something").strip\ncode = "require") end + it { is_expected.to eq(%(version = "1.5.0".strip\ncode = "require")) } context "when that uses File.readlines" do let(:content) do %(version = File.readlines("something").grep(/\S+/)\ncode = "require") end + it do is_expected .to eq(%(version = ["1.5.0"].grep(/\S+/)\ncode = "require")) @@ -71,12 +74,14 @@ let(:content) do %(pkg = JSON.parse(File.read("something").strip)\ncode = "req") end + it { is_expected.to eq(%(pkg = { "version" => "1.5.0" }\ncode = "req")) } context "when that uses File.readlines" do let(:content) do %(version = File.readlines("something").grep(/\S+/)\ncode = "require") end + it do is_expected .to eq(%(version = ["1.5.0"].grep(/\S+/)\ncode = "require")) @@ -88,6 +93,7 @@ let(:content) do %(Find.find("lib", "whatever")\ncode = "require") end + it { is_expected.to eq(%(Find.find()\ncode = "require")) } end @@ -95,6 +101,7 @@ let(:content) do %(Spec.new { |s| s.version = "0.1.0"\n s.post_install_message = "a" }) end + it do is_expected.to eq(%(Spec.new { |s| s.version = "0.1.0"\n "sanitized" })) end @@ -104,6 +111,7 @@ "Spec.new { |s| s.version = '0.1.0'\n " \ "s.post_install_message = \"a\" if true }" end + it "maintains a valid conditional" do expect(rewrite).to eq( %(Spec.new { |s| s.version = '0.1.0'\n "sanitized" if true }) @@ -116,6 +124,7 @@ "Spec.new { |s| s.version = '0.1.0'\n " \ "s.metadata['homepage'] = \"a\" }" end + it "removes the assignment" do expect(rewrite).to eq( %(Spec.new { |s| s.version = '0.1.0'\n "sanitized" }) @@ -132,6 +141,7 @@ DESCRIPTION end) end + it "removes the whole heredoc" do expect(rewrite).to eq( "Spec.new do |s|\n s.version = \"0.1.0\"" \ @@ -149,6 +159,7 @@ DESCRIPTION end) end + it "removes the whole heredoc" do expect(rewrite).to eq( "Spec.new do |s|\n s.version = \"0.1.0\"" \ @@ -161,15 +172,18 @@ describe "version assignment" do context "with an assignment to a constant" do let(:content) { %(Spec.new { |s| s.version = Example::Version }) } + it { is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) } context "when that is fully capitalised" do let(:content) { %(Spec.new { |s| s.version = Example::VERSION }) } + it { is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) } end context "when that is dup-ed" do let(:content) { %(Spec.new { |s| s.version = Example::VERSION.dup }) } + it { is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) } end @@ -177,6 +191,7 @@ let(:content) do %(Spec.new { |s| s.version = Example::VERSION.dup }.tap { |a| "h" }) end + it do is_expected.to eq( %(Spec.new { |s| s.version = "1.5.0" }.tap { |a| "h" }) @@ -187,6 +202,7 @@ context "with an assignment to a variable" do let(:content) { "v = 'a'\n\nSpec.new { |s| s.version = v }" } + it do is_expected.to eq(%(v = 'a'\n\nSpec.new { |s| s.version = "1.5.0" })) end @@ -196,21 +212,25 @@ let(:content) do "Spec.new { |s| s.version = if true\n1\nelse\n2\nend }" end + it { is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) } end context "with an assignment to an int" do let(:content) { "Spec.new { |s| s.version = 1 }" } + it { is_expected.to eq(%(Spec.new { |s| s.version = 1 })) } end context "with an assignment to a float" do let(:content) { "Spec.new { |s| s.version = 1.0 }" } + it { is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) } end context "with an assignment to a File.read" do let(:content) { "Spec.new { |s| s.version = File.read('something') }" } + it do is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) end @@ -218,11 +238,13 @@ context "with an assignment to a variable" do let(:content) { %(Spec.new { |s| s.version = gem_version }) } + it { is_expected.to eq(%(Spec.new { |s| s.version = "1.5.0" })) } end context "with an assignment to a string" do let(:content) { %(Spec.new { |s| s.version = "1.4.0" }) } + # Don't actually do the replacement it { is_expected.to eq(%(Spec.new { |s| s.version = "1.4.0" })) } end @@ -230,27 +252,32 @@ # rubocop:disable Lint/InterpolationCheck context "with an assignment to a string-interpolated constant" do let(:content) { 'Spec.new { |s| s.version = "#{Example::Version}" }' } + it { is_expected.to eq('Spec.new { |s| s.version = "1.5.0" }') } end context "with an assignment to a string-interpolated constant with multiple values" do let(:content) { 'Spec.new { |s| s.version = "#{Example::Version}-#{git_commit}" }' } + it { is_expected.to eq('Spec.new { |s| s.version = "1.5.0" }') } end context "with a version constant used elsewhere in the file" do let(:content) { 'Spec.new { |s| something == "v#{Example::Version}" }' } + it { is_expected.to eq('Spec.new { |s| something == "v#{"1.5.0"}" }') } end context "with a version constant used in assignment in the file" do let(:content) { 'Spec.new { |s| something = "v#{Example::Version}" }' } + it { is_expected.to eq('Spec.new { |s| something = "v#{"1.5.0"}" }') } end # rubocop:enable Lint/InterpolationCheck context "with a version constant used outside of a string" do let(:content) { 'Spec.new { |s| Gem::Version.new("1.0.0") }' } + it { is_expected.to eq(content) } end @@ -258,6 +285,7 @@ let(:content) do bundler_project_dependency_file("gemfile_with_nested_block", filename: "example.gemspec").content end + specify { expect { sanitizer.rewrite(content) }.to_not raise_error } end end @@ -265,6 +293,7 @@ describe "files assignment" do context "with an assignment to a method call (File.open)" do let(:content) { "Spec.new { |s| s.files = File.open('file.txt') }" } + it { is_expected.to eq("Spec.new { |s| s.files = [] }") } end @@ -272,6 +301,7 @@ let(:content) do 'Spec.new { |s| s.files = Dir.chdir("path") { `ls`.split("\n") } }' end + it { is_expected.to eq("Spec.new { |s| s.files = [] }") } end @@ -279,6 +309,7 @@ let(:content) do bundler_project_dependency_file("gemfile_example", filename: "example.gemspec").content end + it { is_expected.to include("spec.files = []") } end end @@ -286,6 +317,7 @@ describe "require_path assignment" do context "with an assignment to Dir[..]" do let(:content) { "Spec.new { |s| s.require_paths = Dir['lib'] }" } + it { is_expected.to eq("Spec.new { |s| s.require_paths = ['lib'] }") } end end diff --git a/bundler/spec/dependabot/bundler/file_updater/git_pin_replacer_spec.rb b/bundler/spec/dependabot/bundler/file_updater/git_pin_replacer_spec.rb index 9480eeca7c..956d2d3819 100644 --- a/bundler/spec/dependabot/bundler/file_updater/git_pin_replacer_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/git_pin_replacer_spec.rb @@ -31,6 +31,7 @@ context "with a dependency that specifies a ref" do let(:dependency_name) { "business" } + it "replaces the ref" do expect(rewrite).to include(%(ref: "new_ref"\n)) end @@ -42,6 +43,7 @@ context "with a dependency that specifies a tag" do let(:dependency_name) { "que" } + it "replaces the tag" do expect(rewrite).to include(%(tag: "new_ref")) end @@ -53,6 +55,7 @@ context "with a dependency that uses single quotes" do let(:content) { %(gem "business", git: "https://x.com", tag: 'v1') } + it "replaces the tag" do expect(rewrite).to include(%(tag: 'new_ref')) end @@ -60,6 +63,7 @@ context "with a dependency that uses quote brackets" do let(:content) { %(gem "business", git: "https://x.com", tag: %(v1)) } + it "replaces the tag" do expect(rewrite).to include(%(tag: %(new_ref))) end diff --git a/bundler/spec/dependabot/bundler/file_updater/git_source_remover_spec.rb b/bundler/spec/dependabot/bundler/file_updater/git_source_remover_spec.rb index 43435082a3..7cea27ad7e 100644 --- a/bundler/spec/dependabot/bundler/file_updater/git_source_remover_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/git_source_remover_spec.rb @@ -28,6 +28,7 @@ context "with a dependency that specifies a ref" do let(:dependency_name) { "business" } + it "replaces the ref" do expect(rewrite).to include(%(gem "business", "~> 1.6.0"\ngem)) end @@ -41,6 +42,7 @@ let(:content) do %(gem "business", "1.0.0", require: false, git: "git_url") end + it { is_expected.to eq(%(gem "business", "1.0.0", require: false)) } end @@ -48,6 +50,7 @@ let(:content) do %(gem "business", "1.0.0", git: "git_url", require: false) end + it { is_expected.to eq(%(gem "business", "1.0.0", require: false)) } end @@ -55,6 +58,7 @@ let(:content) do %(gem "business", "1.0.0", git: "git_url",\nrequire: false) end + it { is_expected.to eq(%(gem "business", "1.0.0", require: false)) } end @@ -62,16 +66,19 @@ let(:content) do %(gem "business", "1.0.0", require: false,\ngit: "git_url") end + it { is_expected.to eq(%(gem "business", "1.0.0", require: false)) } end context "with a custom tag" do let(:content) { %(gem "business", "1.0.0", github: "git_url") } + it { is_expected.to eq(%(gem "business", "1.0.0")) } end context "with a comment" do let(:content) { %(gem "business", "1.0.0", git: "git_url" # My gem) } + it { is_expected.to eq(%(gem "business", "1.0.0" # My gem)) } end end diff --git a/bundler/spec/dependabot/bundler/file_updater/requirement_replacer_spec.rb b/bundler/spec/dependabot/bundler/file_updater/requirement_replacer_spec.rb index d6581bbe8e..c514f770f6 100644 --- a/bundler/spec/dependabot/bundler/file_updater/requirement_replacer_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/requirement_replacer_spec.rb @@ -48,12 +48,14 @@ let(:content) do bundler_project_dependency_file("git_source", filename: "Gemfile").content end + it { is_expected.to include(%(gem "business", "~> 1.5.0",\n git: )) } it { is_expected.to include(%(gem "statesman", "~> 1.2.0")) } end context "when the declaration uses a symbol" do let(:content) { %(gem "business", :"~> 1.0", require: true) } + it { is_expected.to include(%(gem "business", :"~> 1.5.0", require:)) } end @@ -73,20 +75,24 @@ " gem \"business\", \"~> 1.0\", require: true\n" \ "end" end + it { is_expected.to include(%(gem "business", "~> 1.5.0", require:)) } end context "with multiple requirements" do let(:content) { %(gem "business", "~> 1.0", ">= 1.0.1") } + it { is_expected.to eq(%(gem "business", "~> 1.5.0")) } context "when given as an array" do let(:content) { %(gem "business", [">= 1", "<3"], require: true) } + it { is_expected.to eq(%(gem "business", "~> 1.5.0", require: true)) } end context "when dealing with the new requirement" do let(:updated_requirement) { ">= 1.0, < 3.0" } + it { is_expected.to eq(%(gem "business", ">= 1.0", "< 3.0")) } end end @@ -136,6 +142,7 @@ context "when a change is required" do let(:updated_requirement) { "2.0.0" } + it "handles the change in required spaces" do expect(rewrite) .to eq("gem \"business\", \"2.0.0\" # description\n") @@ -146,18 +153,21 @@ context "with a function requirement" do let(:content) { %(version = "1.0.0"\ngem "business", version) } + it { is_expected.to eq(content) } context "when in an || condition" do let(:content) do %(version = "1.0.0"\ngem "business", ENV["a"] || version) end + it { is_expected.to eq(content) } end end context "with no requirement" do let(:content) { %(gem "business") } + it { is_expected.to eq(content) } context "when asked to insert if required" do @@ -177,43 +187,51 @@ context "with a ternary requirement" do let(:content) { %(gem "business", (true ? "1.0.0" : "1.2.0")) } + it { is_expected.to eq(content) } context "when that uses an expression" do let(:content) do %(gem "business", RUBY_VERSION >= "2.2" ? "1.0.0" : "1.2.0") end + it { is_expected.to eq(content) } end end context "with a case statement" do let(:content) { %(gem "business", case true\n when true\n "1.0.0"\n else\n "1.2.0"\n end) } + it { is_expected.to eq(content) } end context "with a conditional" do let(:content) { %(gem "business", ENV["ROUGE"] if ENV["ROUGE"]) } + it { is_expected.to eq(content) } end context "with a constant" do let(:content) { %(gem "business", MyModule::VERSION) } + it { is_expected.to eq(content) } end context "with a dependency that uses single quotes" do let(:content) { %(gem "business", '~> 1.0') } + it { is_expected.to eq(%(gem "business", '~> 1.5.0')) } end context "with a dependency that uses quote brackets" do let(:content) { %(gem "business", %(1.0)) } + it { is_expected.to eq(%(gem "business", %(~> 1.5.0))) } end context "with a dependency that uses doesn't have a space" do let(:content) { %(gem "business", "~>1.0") } + it { is_expected.to eq(%(gem "business", "~>1.5.0")) } end end @@ -226,16 +244,19 @@ context "when declared with `add_runtime_dependency`" do let(:dependency_name) { "bundler" } + it { is_expected.to include(%(time_dependency "bundler", "~> 1.5.0")) } end context "when declared with `add_dependency`" do let(:dependency_name) { "excon" } + it { is_expected.to include(%(add_dependency "excon", "~> 1.5.0")) } end context "when declared without a version" do let(:dependency_name) { "rake" } + it { is_expected.to include(%(ent_dependency "rake"\n)) } end @@ -243,6 +264,7 @@ let(:content) do %(s.add_runtime_dependency("business", *rouge_versions)) end + it { is_expected.to eq(content) } end @@ -255,6 +277,7 @@ let(:dependency_name) { "statesman" } let(:updated_requirement) { "= 1.5.0" } let(:previous_requirement) { "= 1.0.0" } + it { is_expected.to include(%(d_dependency 'statesman', '= 1.5.0')) } end @@ -262,6 +285,7 @@ let(:dependency_name) { "business" } let(:updated_requirement) { "= 1.5.0" } let(:previous_requirement) { "= 1.0.0" } + it { is_expected.to include(%(d_dependency 'business', '1.5.0')) } end end @@ -278,6 +302,7 @@ context "when declared with `add_development_dependency`" do let(:dependency_name) { "rspec" } + it { is_expected.to include(%(ent_dependency "rspec", "~> 1.5.0"\n)) } end end diff --git a/bundler/spec/dependabot/bundler/file_updater/ruby_requirement_setter_spec.rb b/bundler/spec/dependabot/bundler/file_updater/ruby_requirement_setter_spec.rb index 7d8d065983..3a506fe13f 100644 --- a/bundler/spec/dependabot/bundler/file_updater/ruby_requirement_setter_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/ruby_requirement_setter_spec.rb @@ -23,6 +23,7 @@ let(:content) do bundler_project_dependency_file("gemfile", filename: "Gemfile").content end + it { is_expected.to eq(content) } end @@ -30,6 +31,7 @@ let(:content) do bundler_project_dependency_file("explicit_ruby", filename: "Gemfile").content end + it { is_expected.to eq(content) } end end @@ -46,6 +48,7 @@ let(:content) do bundler_project_dependency_file("gemspec_required_ruby_version_range", filename: "Gemfile").content end + it { is_expected.to include("ruby '2.2.10'\n") } it { is_expected.to include(%(gem "statesman", "~> 1.2.0")) } end @@ -57,6 +60,7 @@ let(:content) do bundler_project_dependency_file("gemspec_required_ruby_version_range_array", filename: "Gemfile").content end + it { is_expected.to include("ruby '2.2.10'\n") } it { is_expected.to include(%(gem "statesman", "~> 1.2.0")) } end @@ -70,6 +74,7 @@ bundler_project_dependency_file("gemspec_required_ruby_version_requirement_class", filename: "Gemfile").content end + it { is_expected.to include("ruby '2.1.10'\n") } it { is_expected.to include(%(gem "statesman", "~> 1.2.0")) } end @@ -78,6 +83,7 @@ let(:content) do bundler_project_dependency_file("gemfile", filename: "Gemfile").content end + it { is_expected.to include("ruby '1.9.3'\n") } it { is_expected.to include(%(gem "business", "~> 1.4.0")) } end @@ -100,6 +106,7 @@ let(:content) do bundler_project_dependency_file("gemfile", filename: "Gemfile").content end + it { is_expected.to include("ruby '3.0.6'\n") } it { is_expected.to include(%(gem "business", "~> 1.4.0")) } end @@ -111,6 +118,7 @@ let(:content) do bundler_project_dependency_file("gemfile", filename: "Gemfile").content end + it { is_expected.to include("ruby '3.1.4'\n") } it { is_expected.to include(%(gem "business", "~> 1.4.0")) } end @@ -122,6 +130,7 @@ let(:content) do bundler_project_dependency_file("gemfile", filename: "Gemfile").content end + it { is_expected.to include("ruby '3.2.2'\n") } it { is_expected.to include(%(gem "business", "~> 1.4.0")) } end @@ -133,6 +142,7 @@ let(:content) do bundler_project_dependency_file("gemfile", filename: "Gemfile").content end + it { is_expected.to include("ruby '3.3.1'\n") } it { is_expected.to include(%(gem "business", "~> 1.4.0")) } end @@ -165,6 +175,7 @@ " ruby \"2.2.0\"\n" \ "end" end + it { is_expected.to include("ruby '1.9.3'\n") } it { is_expected.to_not include(%(ruby "2.2.0")) } end diff --git a/bundler/spec/dependabot/bundler/file_updater_spec.rb b/bundler/spec/dependabot/bundler/file_updater_spec.rb index 4d8234137f..0153bdcdbf 100644 --- a/bundler/spec/dependabot/bundler/file_updater_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater_spec.rb @@ -81,6 +81,7 @@ let(:previous_requirements) do [{ file: "Gemfile", requirement: ">= 0", groups: [], source: nil }] end + it { is_expected.to be_nil } end @@ -204,6 +205,7 @@ source: nil }] end + it { is_expected.to be_nil } end @@ -235,6 +237,7 @@ source: nil }] end + its(:content) { is_expected.to include "\"business\", \"~> 1.5.0\"" } its(:content) { is_expected.to include "\"statesman\", \"~> 1.2.0\"" } end @@ -878,6 +881,7 @@ } }] end + its(:content) do is_expected.to include "dependabot-test-ruby-package (~> 1.0.1)!" end diff --git a/bundler/spec/dependabot/bundler/metadata_finder_spec.rb b/bundler/spec/dependabot/bundler/metadata_finder_spec.rb index f76abf2281..d0d312c479 100644 --- a/bundler/spec/dependabot/bundler/metadata_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/metadata_finder_spec.rb @@ -25,6 +25,7 @@ subject(:finder) do described_class.new(dependency: dependency, credentials: credentials) end + let(:credentials) do [{ "type" => "git_source", @@ -82,6 +83,7 @@ fixture("rubygems_responses", "business-1.0.0.gemspec.rz") end let(:rubygems_response) { fixture("ruby", "rubygems_response.json") } + before do stub_request(:get, rubygems_api_url) .with(headers: { "Authorization" => "Basic U0VDUkVUX0NPREVTOg==" }) @@ -117,6 +119,7 @@ let(:rubygems_api_url) do "https://gems.greysteil.com/api/v1/gems/business.json" end + before do stub_request(:get, rubygems_api_url) .with(headers: { "Authorization" => "Basic c2VjcmV0OnRva2Vu" }) @@ -324,6 +327,7 @@ "https://rubygems.org/api/v1/gems/business.json" end let(:rubygems_response_code) { 200 } + before do stub_request(:get, rubygems_api_url) .to_return(status: rubygems_response_code, body: rubygems_response) @@ -418,6 +422,7 @@ describe "#homepage_url" do subject(:homepage_url) { finder.homepage_url } + let(:rubygems_api_url) { "https://rubygems.org/api/v1/gems/business.json" } let(:rubygems_response_code) { 200 } @@ -445,6 +450,7 @@ "https://rubygems.org/api/v1/gems/business.json" end let(:rubygems_response_code) { 200 } + before do stub_request(:get, rubygems_api_url) .to_return(status: rubygems_response_code, body: rubygems_response) @@ -465,6 +471,7 @@ context "when there is no changelog link in the rubygems response" do let(:rubygems_response) { fixture("ruby", "rubygems_response.json") } + it { is_expected.to be_nil } end end diff --git a/bundler/spec/dependabot/bundler/requirement_spec.rb b/bundler/spec/dependabot/bundler/requirement_spec.rb index 9e2af2283c..e95ae788f0 100644 --- a/bundler/spec/dependabot/bundler/requirement_spec.rb +++ b/bundler/spec/dependabot/bundler/requirement_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Dependabot::Bundler::Requirement do subject(:requirement) { described_class.new(requirement_string) } + let(:requirement_string) { ">=1.0.0" } describe ".new" do @@ -13,6 +14,7 @@ context "with a comma-separated string" do let(:requirement_string) { "~> 4.2.5, >= 4.2.5.1" } + it { is_expected.to eq(Gem::Requirement.new("~> 4.2.5", ">= 4.2.5.1")) } end end diff --git a/bundler/spec/dependabot/bundler/update_checker/file_preparer_spec.rb b/bundler/spec/dependabot/bundler/update_checker/file_preparer_spec.rb index ac2cffe4c4..a311d832cc 100644 --- a/bundler/spec/dependabot/bundler/update_checker/file_preparer_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker/file_preparer_spec.rb @@ -59,6 +59,7 @@ context "when that is a git SHA" do let(:latest_allowable_version) { "d12ca5e" } + its(:content) do is_expected.to include(%("business", ">= 1.4.3"\n)) end @@ -67,6 +68,7 @@ context "with a gems.rb and gems.locked setup" do let(:dependency_files) { bundler_project_dependency_files("gems_rb") } + subject { prepared_dependency_files.find { |f| f.name == "gems.rb" } } it "returns the right files" do @@ -80,6 +82,7 @@ context "when asked not to unlock the requirement" do let(:unlock_requirement) { false } + its(:content) { is_expected.to include(%("business", "~> 1.4.0"\n)) } context "with a latest allowable version" do @@ -102,12 +105,14 @@ context "with multiple requirements" do let(:dependency_files) { bundler_project_dependency_files("gemfile_multiple_requirements") } let(:version) { "1.4.3" } + its(:content) do is_expected.to eq(%(gem "business", ">= 1.4.3", require: true\n)) end context "when given as an array" do let(:dependency_files) { bundler_project_dependency_files("gemfile_multiple_requirements_array") } + its(:content) do is_expected.to eq(%(gem "business", ">= 1.4.3", require: true\n)) end @@ -134,17 +139,20 @@ context "when that should be removed" do let(:remove_git_source) { true } + its(:content) { is_expected.to include(%("prius", ">= 0"\n)) } its(:content) { is_expected.to include(%("que", git:)) } context "with a tag (i.e., multiple git-related arguments)" do let(:dependency_files) { bundler_project_dependency_files("git_source_gemfile") } let(:dependency_name) { "que" } + its(:content) { is_expected.to include(%("que", ">= 0"\n)) } end context "with non-git tags at the start" do let(:dependency_files) { bundler_project_dependency_files("non_git_tags_at_start_gemfile") } + its(:content) do is_expected.to eq(%(gem "prius", ">= 0", require: false\n)) end @@ -152,6 +160,7 @@ context "with non-git tags at the end" do let(:dependency_files) { bundler_project_dependency_files("non_git_tags_at_end_gemfile") } + its(:content) do is_expected.to eq(%(gem "prius", ">= 0", require: false\n)) end @@ -159,6 +168,7 @@ context "with non-git tags on a subsequent line" do let(:dependency_files) { bundler_project_dependency_files("non_git_tags_on_newline_gemfile") } + its(:content) do is_expected.to eq(%(gem "prius", ">= 0", require: false\n)) end @@ -166,6 +176,7 @@ context "with git tags on a subsequent line" do let(:dependency_files) { bundler_project_dependency_files("git_tags_on_newline_gemfile") } + its(:content) do is_expected.to eq(%(gem "prius", ">= 0", require: false\n)) end @@ -173,11 +184,13 @@ context "with a custom tag" do let(:dependency_files) { bundler_project_dependency_files("custom_tag_gemfile") } + its(:content) { is_expected.to eq(%(gem "prius", ">= 0"\n)) } end context "with a comment" do let(:dependency_files) { bundler_project_dependency_files("comment_gemfile") } + its(:content) { is_expected.to eq(%(gem "prius", ">= 0" # My gem\n)) } end end @@ -185,6 +198,7 @@ context "when the tag should be replaced" do let(:dependency_name) { "business" } let(:replacement_git_pin) { "v5.1.0" } + its(:content) { is_expected.to include(%(ref: "v5.1.0"\n)) } end end @@ -243,6 +257,7 @@ context "with no requirements, either" do let(:requirements) { [] } + its(:content) { is_expected.to include(%("gitlab", ">= 0"\n)) } end @@ -255,6 +270,7 @@ groups: [:default] }] end + its(:content) { is_expected.to include(%("gitlab", ">= 1.4"\n)) } end end @@ -264,6 +280,7 @@ let(:version) { "1.4.3" } let(:gemspec_fixture_name) { "multiple_requirements" } let(:dependency_files) { bundler_project_dependency_files("gemspec_multiple_requirements") } + its(:content) do is_expected.to eq(%(spec.add_dependency "business", ">= 1.4.3"\n)) end @@ -271,6 +288,7 @@ context "when given as an array" do let(:dependency_files) { bundler_project_dependency_files("gemspec_multiple_requirements_array") } let(:gemspec_fixture_name) { "multiple_requirements_array" } + its(:content) do is_expected.to eq(%(spec.add_dependency "business", ">= 1.4.3"\n)) end @@ -280,6 +298,7 @@ context "with parentheses" do let(:version) { "1.4.3" } let(:dependency_files) { bundler_project_dependency_files("gemfile_multiple_requirements_parenthesis") } + its(:content) do is_expected.to eq(%(spec.add_dependency("business", ">= 1.4.3")\n)) end @@ -291,12 +310,14 @@ bundler_project_dependency_files("nested_gemspec") end subject { prepared_dependency_files.find { |f| f.name == "some/example.gemspec" } } + let(:version) { "1.4.3" } its(:content) { is_expected.to include(%("business", ">= 1.4.3")) } context "when the file requires sanitizing" do subject { prepared_dependency_files.find { |f| f.name == "example.gemspec" } } + let(:dependency_files) { bundler_project_dependency_files("gemfile_with_require") } its(:content) { is_expected.to include("begin\nrequire ") } diff --git a/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb b/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb index 691732bce5..79840794b8 100644 --- a/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb @@ -90,6 +90,7 @@ context "when the gem is Bundler" do let(:dependency_files) { bundler_project_dependency_files("bundler_specified") } let(:dependency_name) { "bundler" } + before do rubygems_response = fixture("ruby", "rubygems_response_versions.json") stub_request(:get, rubygems_url + "versions/bundler.json") @@ -100,12 +101,14 @@ context "when wrapped in a source block" do let(:dependency_files) { bundler_project_dependency_files("bundler_specified_in_source_bundler_specified") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.5.0")) } end end context "when raise_on_ignored is set and later versions are allowed" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -113,10 +116,12 @@ context "when the user is on the latest version" do let(:current_version) { "1.5.0" } + its([:version]) { is_expected.to eq(Gem::Version.new("1.5.0")) } context "when raise_on_ignored is set" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -128,6 +133,7 @@ context "when raise_on_ignored is set" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -139,6 +145,7 @@ context "when raise_on_ignored is set" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -152,6 +159,7 @@ context "when raise_on_ignored is set" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -160,6 +168,7 @@ context "when the user is ignoring the latest version" do let(:ignored_versions) { [">= 1.5.0.a, < 1.6"] } + its([:version]) { is_expected.to eq(Gem::Version.new("1.4.0")) } end @@ -172,6 +181,7 @@ context "when raise_on_ignored is set" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -187,11 +197,13 @@ stub_request(:get, rubygems_url + "versions/business.json") .to_return(status: 200, body: rubygems_response) end + its([:version]) { is_expected.to eq(Gem::Version.new("1.6.0.beta")) } end context "with a Ruby version specified" do let(:dependency_files) { bundler_project_dependency_files("explicit_ruby") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.5.0")) } end @@ -220,6 +232,7 @@ context "when there is no default source" do let(:dependency_files) { bundler_project_dependency_files("imports_gemspec_no_default_source_no_lockfile") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.5.0")) } end end @@ -281,6 +294,7 @@ context "when the user is ignoring the latest version" do let(:ignored_versions) { [">= 1.9.0.a, < 2.0"] } + its([:version]) { is_expected.to eq(Gem::Version.new("1.5.0")) } end diff --git a/bundler/spec/dependabot/bundler/update_checker/requirements_updater_spec.rb b/bundler/spec/dependabot/bundler/update_checker/requirements_updater_spec.rb index 337d45a0f9..0c46187443 100644 --- a/bundler/spec/dependabot/bundler/update_checker/requirements_updater_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker/requirements_updater_spec.rb @@ -49,6 +49,7 @@ context "when there were no requirements" do let(:requirements) { [] } + it { is_expected.to eq([]) } end @@ -57,11 +58,13 @@ context "when there is no resolvable version" do let(:latest_resolvable_version) { nil } + it { is_expected.to eq(gemfile_requirement) } end context "with a SHA-1 version" do before { gemfile_requirement.merge!(source: { type: "git" }) } + let(:updated_source) { { type: "git" } } its([:requirement]) { is_expected.to eq("~> 1.5.0") } @@ -69,19 +72,23 @@ context "when asked to remove a git source" do let(:updated_source) { nil } + its([:source]) { is_expected.to be_nil } context "when no update to the requirements is required" do let(:gemfile_requirement_string) { ">= 0" } + it { is_expected.to eq(gemfile_requirement.merge(source: nil)) } end end context "when asked to update a git reference" do let(:updated_source) { { type: "git", ref: "v1.5.0" } } + before do gemfile_requirement.merge!(source: { type: "git", ref: "v1.2.0" }) end + its([:source]) { is_expected.to eq(updated_source) } end end @@ -91,11 +98,13 @@ context "when a full version was previously specified" do let(:gemfile_requirement_string) { "~> 1.4.0" } + its([:requirement]) { is_expected.to eq("~> 1.5.0") } its([:file]) { is_expected.to eq("Gemfile") } context "when in a gems.rb" do subject { updated_requirements.find { |r| r[:file] == "gems.rb" } } + before { gemfile_requirement[:file] = "gems.rb" } its([:requirement]) { is_expected.to eq("~> 1.5.0") } @@ -106,38 +115,45 @@ context "when it's a pre-release" do let(:latest_resolvable_version) { "1.5.0.beta" } let(:gemfile_requirement_string) { "~> 1.4.0" } + its([:requirement]) { is_expected.to eq("~> 1.5.0.beta") } end context "when a pre-release was previously specified" do let(:gemfile_requirement_string) { "~> 1.5.0.beta" } + its([:requirement]) { is_expected.to eq("~> 1.5.0") } context "when at 2dp, updating to a later pre-release" do let(:gemfile_requirement_string) { "~> 1.5.beta" } let(:latest_resolvable_version) { "1.5.0.beta2" } + its([:requirement]) { is_expected.to eq("~> 1.5.beta2") } end context "when at 4dp, updating to a later pre-release" do let(:gemfile_requirement_string) { "~> 1.5.0.beta.1" } let(:latest_resolvable_version) { "1.5.0.beta.2" } + its([:requirement]) { is_expected.to eq("~> 1.5.0.beta.2") } end end context "when a minor version was previously specified" do let(:gemfile_requirement_string) { "~> 1.4" } + its([:requirement]) { is_expected.to eq("~> 1.5") } end context "when a greater than or equal to matcher was used" do let(:gemfile_requirement_string) { ">= 1.4.0" } + its([:requirement]) { is_expected.to eq(">= 1.4.0") } end context "when a less than matcher was used" do let(:gemfile_requirement_string) { "< 1.4.0" } + its([:requirement]) { is_expected.to eq("< 1.6.0") } end @@ -146,38 +162,45 @@ context "when the new version satisfies the old requirements" do let(:gemfile_requirement_string) { "~> 1.4" } + it { is_expected.to eq(gemfile_requirement) } end context "when the new version does not satisfy the old requirements" do let(:gemfile_requirement_string) { "~> 1.4.0" } + its([:requirement]) { is_expected.to eq("~> 1.5.0") } end context "when there are multiple requirements" do context "when one of which is exact" do let(:gemfile_requirement_string) { "= 1.0.0, <= 1.4.0" } + its([:requirement]) { is_expected.to eq("1.5.0") } end context "when one of which is a ~>" do context "when the conditions are already satisfied" do let(:gemfile_requirement_string) { "~> 1.0, >= 1.0.1" } + its([:requirement]) { is_expected.to eq("~> 1.0, >= 1.0.1") } end context "when the conditions are not already satisfied" do let(:gemfile_requirement_string) { "~> 0.9, >= 0.9.1" } + its([:requirement]) { is_expected.to eq("~> 1.5") } end end context "when forming a range" do let(:gemfile_requirement_string) { ">= 1.0, < 1.4" } + its([:requirement]) { is_expected.to eq(">= 1.0, < 1.6") } context "with a precision mismatch" do let(:gemfile_requirement_string) { ">= 1.0, < 1.4.2.2" } + its([:requirement]) { is_expected.to eq(">= 1.0, < 1.5.1") } end @@ -194,11 +217,13 @@ context "with a != matcher" do context "when that binds" do let(:gemfile_requirement_string) { ">= 1.0, != 1.5.0" } + its([:requirement]) { is_expected.to eq(">= 1.0") } end context "when that does not bind" do let(:gemfile_requirement_string) { ">= 1.0, != 1.4.0, < 1.3" } + its([:requirement]) do is_expected.to eq(">= 1.0, != 1.4.0, < 1.6") end @@ -210,12 +235,14 @@ context "when there are multiple requirements" do context "when one of which is exact" do let(:gemfile_requirement_string) { "= 1.0.0, <= 1.4.0" } + its([:requirement]) { is_expected.to eq("1.5.0") } end context "when one of which is a ~>" do context "when the conditions are already satisfied" do let(:gemfile_requirement_string) { "~> 1.0, >= 1.0.1" } + its([:requirement]) { is_expected.to eq("~> 1.5") } end end @@ -224,12 +251,14 @@ context "with multiple Gemfile declarations" do before { requirements << child_gemfile_requirement } + let(:child_gemfile_requirement) do gemfile_requirement.merge(file: "backend/Gemfile") end describe "the first Gemfile" do subject { updated_requirements.find { |r| r[:file] == "Gemfile" } } + its([:requirement]) { is_expected.to eq("~> 1.5.0") } end @@ -248,11 +277,13 @@ context "when there is no latest version" do let(:latest_version) { nil } + it { is_expected.to eq(gemspec_requirement) } end context "when there is no resolvable version" do let(:latest_resolvable_version) { nil } + it { is_expected.to eq(gemspec_requirement) } end @@ -262,55 +293,66 @@ context "when an = specifier was used" do let(:gemspec_requirement_string) { "= 1.4.0" } + its([:requirement]) { is_expected.to eq("= 1.5.0") } context "when the version is greater" do let(:gemspec_requirement_string) { "1.7.0" } + its([:requirement]) { is_expected.to eq("= 1.7.0") } end end context "when no specifier was used" do let(:gemspec_requirement_string) { "1.4.0" } + its([:requirement]) { is_expected.to eq("= 1.5.0") } end context "when a < specifier was used" do let(:gemspec_requirement_string) { "< 1.4.0" } + its([:requirement]) { is_expected.to eq("< 1.9.0") } end context "when a <= specifier was used" do let(:gemspec_requirement_string) { "<= 1.4.0" } + its([:requirement]) { is_expected.to eq("<= 1.9.0") } end context "when a ~> specifier was used" do let(:gemspec_requirement_string) { "~> 1.4.0" } + its([:requirement]) { is_expected.to eq(">= 1.4, < 1.9") } context "with two zeros" do let(:gemspec_requirement_string) { "~> 1.0.0" } + its([:requirement]) { is_expected.to eq(">= 1.0, < 1.9") } end context "with no zeros" do let(:gemspec_requirement_string) { "~> 1.0.1" } + its([:requirement]) { is_expected.to eq(">= 1.0.1, < 1.9.0") } end context "with minor precision" do let(:gemspec_requirement_string) { "~> 0.1" } + its([:requirement]) { is_expected.to eq(">= 0.1, < 2.0") } end context "with major precision" do let(:latest_version) { "2.8.0" } let(:gemspec_requirement_string) { "~> 1" } + its([:requirement]) { is_expected.to eq(">= 1, < 3") } context "when a 0 version is present" do let(:gemspec_requirement_string) { "~> 0" } + its([:requirement]) { is_expected.to eq("< 3") } end end @@ -318,21 +360,25 @@ context "when there are multiple requirements" do let(:gemspec_requirement_string) { "> 1.0.0, <= 1.4.0" } + its([:requirement]) { is_expected.to eq("> 1.0.0, <= 1.9.0") } context "when it could cause duplication" do let(:gemspec_requirement_string) { "~> 0.5, >= 0.5.2" } + its([:requirement]) { is_expected.to eq(">= 0.5.2, < 2.0") } end context "when one is a != requirement" do context "when it is binding" do let(:gemspec_requirement_string) { "~> 1.4, != 1.8.0" } + its([:requirement]) { is_expected.to eq("~> 1.4") } end context "when it is not binding" do let(:gemspec_requirement_string) { "~> 1.4.0, != 1.5.0" } + its([:requirement]) do is_expected.to eq(">= 1.4, != 1.5.0, < 1.9") end @@ -342,21 +388,25 @@ context "when a beta version was used in the old requirement" do let(:gemspec_requirement_string) { "< 1.4.0.beta" } + its([:requirement]) { is_expected.to eq("< 1.9.0") } end context "when a != specifier was used" do let(:gemspec_requirement_string) { "!= 1.8.0" } + its([:requirement]) { is_expected.to eq(">= 0") } end context "when a >= specifier was used" do let(:gemspec_requirement_string) { ">= 1.9.0" } + its([:requirement]) { is_expected.to eq(:unfixable) } end context "when a > specifier was used" do let(:gemspec_requirement_string) { "> 1.8.0" } + its([:requirement]) { is_expected.to eq(:unfixable) } end @@ -372,56 +422,67 @@ context "when an = specifier was used" do let(:gemspec_requirement_string) { "= 1.4.0" } + its([:requirement]) { is_expected.to eq("= 1.5.0") } end context "when no specifier was used" do let(:gemspec_requirement_string) { "1.4.0" } + its([:requirement]) { is_expected.to eq("= 1.5.0") } end context "when a < specifier was used" do let(:gemspec_requirement_string) { "< 1.4.0" } + its([:requirement]) { is_expected.to eq("< 1.9.0") } end context "when a <= specifier was used" do let(:gemspec_requirement_string) { "<= 1.4.0" } + its([:requirement]) { is_expected.to eq("<= 1.9.0") } end context "when a ~> specifier was used" do let(:gemspec_requirement_string) { "~> 1.4.0" } + its([:requirement]) { is_expected.to eq("~> 1.5.0") } context "with minor precision" do let(:gemspec_requirement_string) { "~> 0.1" } + its([:requirement]) { is_expected.to eq("~> 1.5") } end end context "when there are multiple requirements" do let(:gemspec_requirement_string) { "> 1.0.0, <= 1.4.0" } + its([:requirement]) { is_expected.to eq("> 1.0.0, <= 1.9.0") } end context "when a beta version was used in the old requirement" do let(:gemspec_requirement_string) { "< 1.4.0.beta" } + its([:requirement]) { is_expected.to eq("< 1.9.0") } end context "when a != specifier was used" do let(:gemspec_requirement_string) { "!= 1.5.0" } + its([:requirement]) { is_expected.to eq(">= 0") } end context "when a >= specifier was used" do let(:gemspec_requirement_string) { ">= 1.6.0" } + its([:requirement]) { is_expected.to eq(:unfixable) } end context "when a > specifier was used" do let(:gemspec_requirement_string) { "> 1.6.0" } + its([:requirement]) { is_expected.to eq(:unfixable) } end end diff --git a/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb b/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb index 54ab9bc3b9..863f8dcef0 100644 --- a/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb @@ -68,6 +68,7 @@ let(:requirement_string) { "~> 1.4.0" } let(:dependency_files) { bundler_project_dependency_files("gemfile") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.4.0")) } end @@ -75,6 +76,7 @@ let(:requirement_string) { "~> 1.4" } let(:dependency_files) { bundler_project_dependency_files("minor_version_specified_gemfile") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.18.0")) } end @@ -86,6 +88,7 @@ end let(:dependency_files) { bundler_project_dependency_files("blocked_by_subdep") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.1.0")) } end @@ -94,6 +97,7 @@ let(:requirements) { [] } let(:dependency_files) { bundler_project_dependency_files("subdependency") } + its([:version]) { is_expected.to eq(Gem::Version.new("0.7.0")) } context "when it will be removed if other sub-dependencies are updated" do @@ -113,6 +117,7 @@ let(:requirement_string) { "~> 1.4.0" } let(:dependency_files) { bundler_project_dependency_files("bundler_specified") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.4.0")) } context "when attempting to update Bundler" do @@ -120,12 +125,14 @@ include_context "when stubbing rubygems versions api" let(:dependency_files) { bundler_project_dependency_files("bundler_specified") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.16.3")) } context "when wrapped in a source block" do let(:dependency_files) do bundler_project_dependency_files("bundler_specified_in_source_bundler_specified") end + its([:version]) { is_expected.to eq(Gem::Version.new("1.16.3")) } end @@ -147,6 +154,7 @@ let(:requirement_string) { "~> 1.4.0" } let(:dependency_files) { bundler_project_dependency_files("bundler_specified") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.4.0")) } context "when attempting to update Bundler" do @@ -166,6 +174,7 @@ let(:requirement_string) { "2.2.1" } let(:dependency_files) { bundler_project_dependency_files("requires_bundler") } + its([:version]) { is_expected.to eq(Gem::Version.new("2.2.1")) } end @@ -196,6 +205,7 @@ let(:requirement_string) { "~> 1.4" } let(:dependency_files) { bundler_project_dependency_files("default_gem_specified") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.18.0")) } end @@ -206,6 +216,7 @@ # The latest version of ibandit is 0.8.5, but 0.11.28 is the latest # version compatible with the version of i18n in the Gemfile.lock. let(:dependency_files) { bundler_project_dependency_files("version_conflict_no_req_change") } + its([:version]) { is_expected.to eq(Gem::Version.new("0.11.28")) } context "with a gems.rb and gems.locked" do @@ -219,6 +230,7 @@ end let(:dependency_files) { bundler_project_dependency_files("version_conflict_no_req_change_gems_rb") } + its([:version]) { is_expected.to eq(Gem::Version.new("0.11.28")) } end end @@ -228,6 +240,7 @@ let(:requirement_string) { ">= 0" } let(:dependency_files) { bundler_project_dependency_files("version_conflict_with_listed_subdep") } + its([:version]) { is_expected.to eq(Gem::Version.new("3.6.0")) } end @@ -238,6 +251,7 @@ # The latest version of public_suffix is 2.0.5, but requires Ruby 2.0.0 # or greater. let(:dependency_files) { bundler_project_dependency_files("legacy_ruby") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.4.6")) } end @@ -284,6 +298,7 @@ end let(:dependency_files) { bundler_project_dependency_files("legacy_ruby") } + its([:version]) { is_expected.to eq(Gem::Version.new("3.0.2")) } end @@ -304,6 +319,7 @@ let(:requirement_string) { ">= 0" } let(:dependency_files) { bundler_project_dependency_files("jruby") } + its([:version]) { is_expected.to be >= Gem::Version.new("1.4.6") } end @@ -312,6 +328,7 @@ context "when it's that gem that we're attempting to bump" do let(:dependency_files) { bundler_project_dependency_files("minor_version_specified_yanked_gem") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.18.0")) } end @@ -319,6 +336,7 @@ let(:dependency_name) { "statesman" } let(:requirement_string) { "~> 1.2" } let(:dependency_files) { bundler_project_dependency_files("minor_version_specified_yanked_gem") } + its([:version]) { is_expected.to eq(Gem::Version.new("1.3.1")) } end end @@ -450,6 +468,7 @@ source: nil }] end + it "is nil" do skip("skipped due to https://github.com/dependabot/dependabot-core/issues/2364") is_expected.to be_nil diff --git a/bundler/spec/dependabot/bundler/update_checker_spec.rb b/bundler/spec/dependabot/bundler/update_checker_spec.rb index 1c5dba1593..68e9220cd6 100644 --- a/bundler/spec/dependabot/bundler/update_checker_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker_spec.rb @@ -153,6 +153,7 @@ let(:gemfury_business_url) do "https://repo.fury.io/greysteil/api/v1/dependencies?gems=business" end + before do bundler_version = PackageManagerHelper.bundler_version @@ -322,6 +323,7 @@ headers: git_header ) end + let(:upload_pack_fixture) { "business" } it "fetches the latest SHA-1 hash of the latest version tag" do @@ -630,6 +632,7 @@ context "when the user is ignoring the latest version" do let(:ignored_versions) { [">= 1.7.0.a, < 2.0"] } + it { is_expected.to eq(Gem::Version.new("1.6.0")) } end end @@ -708,6 +711,7 @@ context "when that is the gem we're checking" do let(:dependency_name) { "example" } let(:current_version) { "0.9.3" } + it { is_expected.to eq(Gem::Version.new("0.9.3")) } end @@ -896,6 +900,7 @@ headers: git_header ) end + let(:upload_pack_fixture) { "business" } it "fetches the latest SHA-1 hash of the latest version tag" do @@ -1471,6 +1476,7 @@ let(:requirements_updater) do Dependabot::Bundler::UpdateChecker::RequirementsUpdater end + before do allow(requirements_updater).to receive(:new).and_call_original end diff --git a/cargo/spec/dependabot/cargo/file_fetcher_spec.rb b/cargo/spec/dependabot/cargo/file_fetcher_spec.rb index 0cfd307a52..1b2462ec27 100644 --- a/cargo/spec/dependabot/cargo/file_fetcher_spec.rb +++ b/cargo/spec/dependabot/cargo/file_fetcher_spec.rb @@ -29,7 +29,9 @@ end let(:json_header) { { "content-type" => "application/json" } } + before { allow(file_fetcher_instance).to receive(:commit).and_return("sha") } + before do stub_request(:get, url + "Cargo.toml?ref=sha") .with(headers: { "Authorization" => "token token" }) @@ -246,6 +248,7 @@ .with(headers: { "Authorization" => "token token" }) .to_return(status: 200, body: parent_fixture, headers: json_header) end + let(:parent_fixture) do fixture("github", "contents_cargo_manifest_path_deps.json") end @@ -256,6 +259,7 @@ .with(headers: { "Authorization" => "token token" }) .to_return(status: 200, body: path_dep_fixture, headers: json_header) end + let(:path_dep_fixture) do fixture("github", "contents_cargo_manifest.json") end @@ -360,6 +364,7 @@ let(:url) do "https://api.github.com/repos/gocardless/bump/contents/my_dir/" end + before do stub_request(:get, "https://api.github.com/repos/gocardless/bump/" \ "contents/my_dir?ref=sha") @@ -474,6 +479,7 @@ .with(headers: { "Authorization" => "token token" }) .to_return(status: 200, body: parent_fixture, headers: json_header) end + let(:parent_fixture) do fixture("github", "contents_cargo_manifest_workspace_root.json") end @@ -484,6 +490,7 @@ .with(headers: { "Authorization" => "token token" }) .to_return(status: 200, body: child_fixture, headers: json_header) end + let(:child_fixture) do fixture("github", "contents_cargo_manifest_workspace_child.json") end @@ -497,6 +504,7 @@ let(:parent_fixture) do fixture("github", "contents_cargo_manifest_workspace_implicit.json") end + before do stub_request(:get, url + "src/s3/Cargo.toml?ref=sha") .with(headers: { "Authorization" => "token token" }) @@ -626,6 +634,7 @@ "contents_cargo_manifest_workspace_root_partial_glob.json" ) end + before do stub_request(:get, url + "packages?ref=sha") .with(headers: { "Authorization" => "token token" }) @@ -672,6 +681,7 @@ .with(headers: { "Authorization" => "token token" }) .to_return(status: 200, body: member_fixture, headers: json_header) end + let(:parent_fixture) do fixture("github", "contents_cargo_manifest_workspace_excluded_dependencies_root.json") end diff --git a/cargo/spec/dependabot/cargo/file_parser_spec.rb b/cargo/spec/dependabot/cargo/file_parser_spec.rb index 619f71763e..db4a878670 100644 --- a/cargo/spec/dependabot/cargo/file_parser_spec.rb +++ b/cargo/spec/dependabot/cargo/file_parser_spec.rb @@ -266,6 +266,7 @@ context "with an override (specified as a patch)" do let(:manifest_fixture_name) { "workspace_root_with_patch" } let(:lockfile_fixture_name) { "workspace_with_patch" } + subject(:top_level_dependencies) { dependencies.select(&:top_level?) } it "excludes the patched dependency" do @@ -361,6 +362,7 @@ context "when using an old format lockfile" do let(:lockfile_fixture_name) { "virtual_workspace_old_format" } + its(:length) { is_expected.to eq(2) } end end @@ -553,6 +555,7 @@ describe "top level dependencies" do subject(:top_level_dependencies) { dependencies.select(&:top_level?) } + its(:length) { is_expected.to eq(2) } describe "the first dependency" do @@ -829,12 +832,14 @@ context "with resolver version 2" do let(:manifest_fixture_name) { "resolver2" } let(:lockfile_fixture_name) { "no_dependencies" } + it { is_expected.to eq([]) } end context "with no dependencies" do let(:manifest_fixture_name) { "no_dependencies" } let(:lockfile_fixture_name) { "no_dependencies" } + it { is_expected.to eq([]) } end diff --git a/cargo/spec/dependabot/cargo/file_updater/manifest_updater_spec.rb b/cargo/spec/dependabot/cargo/file_updater/manifest_updater_spec.rb index b82d27b32d..15524f59b7 100644 --- a/cargo/spec/dependabot/cargo/file_updater/manifest_updater_spec.rb +++ b/cargo/spec/dependabot/cargo/file_updater/manifest_updater_spec.rb @@ -76,6 +76,7 @@ context "with a target-specific dependency" do let(:manifest_fixture_name) { "target_dependency" } + it { is_expected.to include(%(time = "<= 0.1.38")) } end diff --git a/cargo/spec/dependabot/cargo/metadata_finder_spec.rb b/cargo/spec/dependabot/cargo/metadata_finder_spec.rb index 2c566b6662..c98a4184c4 100644 --- a/cargo/spec/dependabot/cargo/metadata_finder_spec.rb +++ b/cargo/spec/dependabot/cargo/metadata_finder_spec.rb @@ -25,6 +25,7 @@ subject(:finder) do described_class.new(dependency: dependency, credentials: credentials) end + let(:credentials) do [{ "type" => "git_source", @@ -46,6 +47,7 @@ describe "#source_url" do subject(:source_url) { finder.source_url } + let(:crates_url) { "https://crates.io/api/v1/crates/bitflags" } before do @@ -55,6 +57,7 @@ body: crates_response ) end + let(:crates_response) do fixture("crates_io_responses", crates_fixture_name) end diff --git a/cargo/spec/dependabot/cargo/requirement_spec.rb b/cargo/spec/dependabot/cargo/requirement_spec.rb index d57c091cfa..71dc791171 100644 --- a/cargo/spec/dependabot/cargo/requirement_spec.rb +++ b/cargo/spec/dependabot/cargo/requirement_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Dependabot::Cargo::Requirement do subject(:requirement) { described_class.new(requirement_string) } + let(:requirement_string) { ">=1.0.0" } describe ".new" do @@ -13,11 +14,13 @@ context "with a blank string" do let(:requirement_string) { "" } + it { is_expected.to eq(described_class.new(">= 0")) } end context "with a pre-release" do let(:requirement_string) { "4.0.0-beta3" } + it "preserves the pre-release formatting" do expect(requirement.requirements.first.last.to_s).to eq("4.0.0-beta3") end @@ -25,6 +28,7 @@ context "with a build-version" do let(:requirement_string) { "4.0.0+something" } + it "preserves the build version" do expect(requirement.requirements.first.last.to_s) .to eq("4.0.0+something") @@ -34,20 +38,24 @@ describe "wildcards" do context "with only a *" do let(:requirement_string) { "*" } + it { is_expected.to eq(described_class.new(">= 0")) } end context "with a 1.*" do let(:requirement_string) { "1.*" } + it { is_expected.to eq(described_class.new("~> 1.0")) } end context "with a 1.1.*" do let(:requirement_string) { "1.1.*" } + it { is_expected.to eq(described_class.new("~> 1.1.0")) } context "when prefixed with a caret" do let(:requirement_string) { "^1.1.*" } + it { is_expected.to eq(described_class.new("~> 1.1.0")) } end end @@ -55,20 +63,24 @@ context "with no specifier" do let(:requirement_string) { "1.1.0" } + it { is_expected.to eq(described_class.new(">= 1.1.0", "< 2.0.0")) } end context "with a caret version" do context "when specified to 3 dp" do let(:requirement_string) { "^1.2.3" } + it { is_expected.to eq(described_class.new(">= 1.2.3", "< 2.0.0")) } context "with a zero major" do let(:requirement_string) { "^0.2.3" } + it { is_expected.to eq(described_class.new(">= 0.2.3", "< 0.3.0")) } context "when a zero minor is present" do let(:requirement_string) { "^0.0.3" } + it { is_expected.to eq(described_class.new(">= 0.0.3", "< 0.0.4")) } end end @@ -76,14 +88,17 @@ context "when specified to 2 dp" do let(:requirement_string) { "^1.2" } + it { is_expected.to eq(described_class.new(">= 1.2", "< 2.0")) } context "with a zero major" do let(:requirement_string) { "^0.2" } + it { is_expected.to eq(described_class.new(">= 0.2", "< 0.3")) } context "when a zero minor is present" do let(:requirement_string) { "^0.0" } + it { is_expected.to eq(described_class.new(">= 0.0", "< 0.1")) } end end @@ -91,10 +106,12 @@ context "when specified to 1 dp" do let(:requirement_string) { "^1" } + it { is_expected.to eq(described_class.new(">= 1", "< 2")) } context "with a zero major" do let(:requirement_string) { "^0" } + it { is_expected.to eq(described_class.new(">= 0", "< 1")) } end end @@ -103,37 +120,44 @@ context "with a ~ version" do context "when specified to 3 dp" do let(:requirement_string) { "~1.5.1" } + it { is_expected.to eq(described_class.new("~> 1.5.1")) } end context "when specified to 2 dp" do let(:requirement_string) { "~1.5" } + it { is_expected.to eq(described_class.new("~> 1.5.0")) } end context "when specified to 1 dp" do let(:requirement_string) { "~1" } + it { is_expected.to eq(described_class.new("~> 1.0")) } end end context "with a > version specified" do let(:requirement_string) { ">1.5.1" } + it { is_expected.to eq(Gem::Requirement.new("> 1.5.1")) } end context "with an = version specified" do let(:requirement_string) { "=1.5" } + it { is_expected.to eq(Gem::Requirement.new("1.5")) } end context "with an ~> version specified" do let(:requirement_string) { "~> 1.5.1" } + its(:to_s) { is_expected.to eq(Gem::Requirement.new("~> 1.5.1").to_s) } end context "with a comma separated list" do let(:requirement_string) { ">1.5.1, < 2.0.0" } + it { is_expected.to eq(Gem::Requirement.new("> 1.5.1", "< 2.0.0")) } end end diff --git a/cargo/spec/dependabot/cargo/update_checker/file_preparer_spec.rb b/cargo/spec/dependabot/cargo/update_checker/file_preparer_spec.rb index bfab5bcbf5..f5c1e127de 100644 --- a/cargo/spec/dependabot/cargo/update_checker/file_preparer_spec.rb +++ b/cargo/spec/dependabot/cargo/update_checker/file_preparer_spec.rb @@ -140,6 +140,7 @@ context "with a support file (e.g., a path dependency manifest)" do before { manifest.support_file = true } + let(:dependency_version) { nil } it "does not update the requirement" do @@ -290,11 +291,13 @@ describe "the updated lockfile" do subject { prepared_dependency_files.find { |f| f.name == "Cargo.lock" } } + it { is_expected.to eq(lockfile) } end context "without a lockfile" do let(:dependency_files) { [manifest] } + its(:length) { is_expected.to eq(1) } end end diff --git a/cargo/spec/dependabot/cargo/update_checker/latest_version_finder_spec.rb b/cargo/spec/dependabot/cargo/update_checker/latest_version_finder_spec.rb index 6d85f2cbd0..8baac26aa9 100644 --- a/cargo/spec/dependabot/cargo/update_checker/latest_version_finder_spec.rb +++ b/cargo/spec/dependabot/cargo/update_checker/latest_version_finder_spec.rb @@ -61,6 +61,7 @@ describe "#latest_version" do subject { finder.latest_version } + before do stub_request(:get, crates_url).to_return(status: 200, body: crates_response) end @@ -69,6 +70,7 @@ context "when the latest version is being ignored" do let(:ignored_versions) { [">= 0.1.40, < 2.0"] } + it { is_expected.to eq(Gem::Version.new("0.1.39")) } end @@ -100,6 +102,7 @@ stub_request(:get, crates_url) .to_return(status: 404, body: crates_response) end + let(:crates_fixture_name) { "not_found.json" } it { is_expected.to be_nil } @@ -108,11 +111,13 @@ context "when the latest version is a pre-release" do let(:dependency_name) { "xdg" } let(:dependency_version) { "2.0.0" } + it { is_expected.to eq(Gem::Version.new("2.1.0")) } context "when the user wants a pre-release" do context "when their current version is a pre-release" do let(:dependency_version) { "2.0.0-pre4" } + it { is_expected.to eq(Gem::Version.new("3.0.0-pre1")) } end @@ -125,6 +130,7 @@ source: nil }] end + it { is_expected.to eq(Gem::Version.new("3.0.0-pre1")) } end end @@ -132,6 +138,7 @@ context "when raise_on_ignored is set and later versions are allowed" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -139,10 +146,12 @@ context "when already on the latest version" do let(:dependency_version) { "0.1.40" } + it { is_expected.to eq(Gem::Version.new("0.1.40")) } context "when raise_on_ignored is enabled" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -151,10 +160,12 @@ context "when all later versions are being ignored" do let(:ignored_versions) { ["> 0.1.38"] } + it { is_expected.to eq(Gem::Version.new("0.1.38")) } context "when raise_on_ignored is enabled" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -166,6 +177,7 @@ context "when raise_on_ignored is enabled" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -191,21 +203,25 @@ ) ] end + it { is_expected.to eq(Gem::Version.new("0.1.19")) } context "when the lowest version is being ignored" do let(:ignored_versions) { [">= 0.1.18, < 0.1.20"] } + it { is_expected.to eq(Gem::Version.new("0.1.20")) } end context "when all versions are being ignored" do let(:ignored_versions) { [">= 0"] } + it "returns nil" do expect(subject).to be_nil end context "when raise_on_ignored is enabled" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -224,11 +240,13 @@ ) ] end + it { is_expected.to eq(Gem::Version.new("2.0.0")) } context "when the user wants a pre-release" do context "when their current version is a pre-release" do let(:dependency_version) { "2.0.0-pre1" } + it { is_expected.to eq(Gem::Version.new("2.0.0-pre3")) } end @@ -241,6 +259,7 @@ source: nil }] end + it { is_expected.to eq(Gem::Version.new("2.0.0-pre3")) } end end @@ -280,6 +299,7 @@ describe "#latest_version" do subject { finder.latest_version } + before do stub_request(:get, sparse_registry_url).to_return(status: 200, body: sparse_registry_response) end @@ -288,6 +308,7 @@ context "when the latest version is being ignored" do let(:ignored_versions) { [">= 1.0.1, < 2.0"] } + it { is_expected.to eq(Gem::Version.new("1.0.0")) } end @@ -296,6 +317,7 @@ stub_request(:get, sparse_registry_url) .to_return(status: 404, body: sparse_registry_response) end + let(:crates_fixture_name) { "not_found.json" } it { is_expected.to be_nil } @@ -308,6 +330,7 @@ {"name": "hello-world", "vers": "2.0.0-pre1", "deps": [], "cksum": "8a55b58def1ecc7aa8590c7078f379ec9a85328363ffb81d4354314b132b95c4", "features": {}, "yanked": false, "links": null} BODY end + it { is_expected.to eq(Gem::Version.new("1.0.0")) } context "with the user wants a pre-release" do @@ -325,21 +348,25 @@ } }] end + it { is_expected.to eq(Gem::Version.new("2.0.0-pre1")) } end end context "when already on the latest version" do let(:dependency_version) { "1.0.1" } + it { is_expected.to eq(Gem::Version.new("1.0.1")) } end context "when all later versions are being ignored" do let(:ignored_versions) { ["> 1.0.0"] } + it { is_expected.to eq(Gem::Version.new("1.0.0")) } context "with raise_on_ignored" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -365,21 +392,25 @@ ) ] end + it { is_expected.to eq(Gem::Version.new("1.0.1")) } context "when the lowest version is being ignored" do let(:ignored_versions) { [">= 1.0.0, < 1.0.1"] } + it { is_expected.to eq(Gem::Version.new("1.0.1")) } end context "when all versions are being ignored" do let(:ignored_versions) { [">= 0"] } + it "returns nil" do expect(subject).to be_nil end context "with raise_on_ignored" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -405,11 +436,13 @@ ) ] end + it { is_expected.to eq(Gem::Version.new("2.0.0")) } context "with the user wants a pre-release" do context "when their current version is a pre-release" do let(:dependency_version) { "2.0.0-pre1" } + it { is_expected.to eq(Gem::Version.new("2.0.0-pre3")) } end @@ -428,6 +461,7 @@ } }] end + it { is_expected.to eq(Gem::Version.new("2.0.0-pre3")) } end end diff --git a/cargo/spec/dependabot/cargo/update_checker/requirements_updater_spec.rb b/cargo/spec/dependabot/cargo/update_checker/requirements_updater_spec.rb index 6bb16264fd..ad8c424cfd 100644 --- a/cargo/spec/dependabot/cargo/update_checker/requirements_updater_spec.rb +++ b/cargo/spec/dependabot/cargo/update_checker/requirements_updater_spec.rb @@ -39,6 +39,7 @@ context "when there is no latest version" do let(:target_version) { nil } + its([:requirement]) { is_expected.to eq(req_string) } end @@ -69,11 +70,14 @@ ref: nil } end + it { is_expected.to eq(cargo_req) } context "when asked to update the source" do let(:updated_source) { { type: "git", ref: "v1.5.0" } } + before { cargo_req.merge!(source: { type: "git", ref: "v1.2.0" }) } + its([:source]) { is_expected.to eq(updated_source) } end end @@ -84,52 +88,62 @@ context "when there is a latest version" do context "when a full version was previously specified" do let(:req_string) { "1.2.3" } + its([:requirement]) { is_expected.to eq("1.5.0") } end context "when an equality requirement was previously specified" do let(:req_string) { "=1.2.3" } + its([:requirement]) { is_expected.to eq("=1.5.0") } end context "when a partial version was previously specified" do let(:req_string) { "0.1" } + its([:requirement]) { is_expected.to eq("1.5") } end context "when only the major part was previously specified" do let(:req_string) { "1" } let(:target_version) { "4.5.0" } + its([:requirement]) { is_expected.to eq("4") } end context "when the new version has fewer digits than the old one" do let(:req_string) { "1.1.0.1" } + its([:requirement]) { is_expected.to eq("1.5.0") } end context "when the new version has significantly fewer digits than the old one" do let(:req_string) { "1.1.0.1" } let(:target_version) { "4" } + its([:requirement]) { is_expected.to eq("4") } end context "when a caret was previously specified" do let(:req_string) { "^1.2.3" } + its([:requirement]) { is_expected.to eq("^1.5.0") } end context "when a pre-release was previously specified" do let(:req_string) { "^1.2.3-rc1" } + its([:requirement]) { is_expected.to eq("^1.5.0") } context "when needing an update" do let(:req_string) { "1.2.3-rc1" } + its([:requirement]) { is_expected.to eq("1.5.0") } context "when transitioning to a new pre-release version" do let(:req_string) { "1.2.3-beta" } let(:target_version) { "1.2.3-beta.2" } + its([:requirement]) { is_expected.to eq("1.2.3-beta.2") } end end @@ -137,41 +151,49 @@ context "with just *" do let(:req_string) { "*" } + its([:requirement]) { is_expected.to eq("*") } end context "with a < condition" do let(:req_string) { "< 1.2.0" } + its([:requirement]) { is_expected.to eq("< 1.6.0") } end context "with a < condition" do let(:req_string) { "> 99.2.0" } + its([:requirement]) { is_expected.to eq(:unfixable) } end context "when there were multiple range specifications" do let(:req_string) { "> 1.0.0, < 1.2.0" } + its([:requirement]) { is_expected.to eq("> 1.0.0, < 1.6.0") } context "when already valid" do let(:req_string) { "> 1.0.0, < 1.7.0" } + its([:requirement]) { is_expected.to eq(req_string) } end context "when including a pre-release" do let(:req_string) { ">=1.2.0, <1.4.0-dev" } + its([:requirement]) { is_expected.to eq(">=1.2.0, <1.6.0") } end end context "when an *.* was previously specified" do let(:req_string) { "^0.*.*" } + its([:requirement]) { is_expected.to eq("^1.*.*") } end context "when an *.* was previously specified with four places" do let(:req_string) { "^0.*.*.rc1" } + its([:requirement]) { is_expected.to eq("^1.*.*") } end @@ -218,6 +240,7 @@ context "when the target version has a build annotation" do let(:req_string) { "1.2.3" } let(:target_version) { "1.5.0+build.1" } + its([:requirement]) { is_expected.to eq("1.5.0") } end end @@ -228,58 +251,69 @@ context "when there is no latest version" do let(:target_version) { nil } + its([:requirement]) { is_expected.to eq(req_string) } end context "when there is a latest version" do context "when a full version was previously specified" do let(:req_string) { "1.2.3" } + its([:requirement]) { is_expected.to eq(req_string) } end context "when an equality requirement was previously specified" do let(:req_string) { "=1.2.3" } + its([:requirement]) { is_expected.to eq("=1.5.0") } end context "when a partial version was previously specified" do let(:req_string) { "0.1" } + its([:requirement]) { is_expected.to eq("1.5") } end context "when only the major part was previously specified" do let(:req_string) { "1" } let(:target_version) { "4.5.0" } + its([:requirement]) { is_expected.to eq("4") } end context "when the new version has fewer digits than the old one" do let(:req_string) { "0.1.0.1" } + its([:requirement]) { is_expected.to eq("1.5.0") } end context "when the new version has significantly fewer digits than the old one" do let(:req_string) { "1.1.0.1" } let(:target_version) { "4" } + its([:requirement]) { is_expected.to eq("4") } end context "when a caret was previously specified" do let(:req_string) { "^1.2.3" } + its([:requirement]) { is_expected.to eq(req_string) } end context "when a pre-release was previously specified" do let(:req_string) { "^1.2.3-rc1" } + its([:requirement]) { is_expected.to eq(req_string) } context "when needing an update" do let(:req_string) { "0.2.3-rc1" } + its([:requirement]) { is_expected.to eq("1.5.0") } context "when transitioning to a new pre-release version" do let(:req_string) { "0.2.3-beta" } let(:target_version) { "1.2.3-beta.2" } + its([:requirement]) { is_expected.to eq("1.2.3-beta.2") } end end @@ -287,41 +321,49 @@ context "with just *" do let(:req_string) { "*" } + its([:requirement]) { is_expected.to eq("*") } end context "with a < condition" do let(:req_string) { "< 1.2.0" } + its([:requirement]) { is_expected.to eq("< 1.6.0") } end context "with a < condition" do let(:req_string) { "> 99.2.0" } + its([:requirement]) { is_expected.to eq(:unfixable) } end context "when there are multiple range specifications" do let(:req_string) { "> 1.0.0, < 1.2.0" } + its([:requirement]) { is_expected.to eq("> 1.0.0, < 1.6.0") } context "when already valid" do let(:req_string) { "> 1.0.0, < 1.7.0" } + its([:requirement]) { is_expected.to eq(req_string) } end context "when including a pre-release" do let(:req_string) { ">=1.2.0, <1.4.0-dev" } + its([:requirement]) { is_expected.to eq(">=1.2.0, <1.6.0") } end end context "when an *.* was previously specified" do let(:req_string) { "^0.*.*" } + its([:requirement]) { is_expected.to eq("^1.*.*") } end context "when an *.* was previously specified with four places" do let(:req_string) { "^0.*.*.rc1" } + its([:requirement]) { is_expected.to eq("^1.*.*") } end diff --git a/cargo/spec/dependabot/cargo/update_checker/version_resolver_spec.rb b/cargo/spec/dependabot/cargo/update_checker/version_resolver_spec.rb index 81ac1366f4..01c0fe3247 100644 --- a/cargo/spec/dependabot/cargo/update_checker/version_resolver_spec.rb +++ b/cargo/spec/dependabot/cargo/update_checker/version_resolver_spec.rb @@ -74,10 +74,12 @@ context "without a lockfile" do let(:unprepared_dependency_files) { [manifest] } + it { is_expected.to be >= Gem::Version.new("0.2.10") } context "with a template manifest file" do let(:manifest_fixture_name) { "template_name" } + it { is_expected.to be >= Gem::Version.new("0.2.10") } end end @@ -551,6 +553,7 @@ context "when not unlocking" do let(:dependency_files) { unprepared_dependency_files } + it { is_expected.to eq(Gem::Version.new("0.1.80")) } end diff --git a/cargo/spec/dependabot/cargo/update_checker_spec.rb b/cargo/spec/dependabot/cargo/update_checker_spec.rb index 93594723e0..06c93cc82e 100644 --- a/cargo/spec/dependabot/cargo/update_checker_spec.rb +++ b/cargo/spec/dependabot/cargo/update_checker_spec.rb @@ -15,6 +15,7 @@ before do stub_request(:get, crates_url).to_return(status: 200, body: crates_response) end + let(:crates_url) { "https://crates.io/api/v1/crates/#{dependency_name}" } let(:crates_response) { fixture("crates_io_responses", crates_fixture_name) } let(:crates_fixture_name) { "#{dependency_name}.json" } @@ -80,16 +81,19 @@ context "when given an up-to-date dependency" do let(:dependency_version) { "0.1.40" } + it { is_expected.to be_falsey } end end describe "#latest_version" do subject { checker.latest_version } + it { is_expected.to eq(Gem::Version.new("0.1.40")) } context "when the latest version is being ignored" do let(:ignored_versions) { [">= 0.1.40, < 2.0"] } + it { is_expected.to eq(Gem::Version.new("0.1.39")) } end @@ -229,12 +233,14 @@ context "when the latest version is being ignored" do let(:ignored_versions) { [">= 0.1.40, < 2.0"] } + it { is_expected.to eq(Gem::Version.new("0.1.39")) } end context "when all versions are being ignored" do let(:ignored_versions) { [">= 0"] } let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -340,12 +346,14 @@ ) ] end + it { is_expected.to eq(Gem::Version.new("0.1.39")) } end end describe "#latest_resolvable_version_with_no_unlock" do subject { checker.send(:latest_resolvable_version_with_no_unlock) } + let(:dependency_name) { "regex" } let(:dependency_version) { "0.1.41" } let(:requirements) do @@ -361,6 +369,7 @@ context "when the latest version is being ignored" do let(:ignored_versions) { [">= 0.1.60, < 2.0"] } + it { is_expected.to eq(Gem::Version.new("0.1.59")) } end @@ -385,6 +394,7 @@ ref: nil } end + before do git_url = "https://github.com/BurntSushi/utf8-ranges.git" git_header = { diff --git a/cargo/spec/dependabot/cargo/version_spec.rb b/cargo/spec/dependabot/cargo/version_spec.rb index a8d605c68d..d27e6bd25c 100644 --- a/cargo/spec/dependabot/cargo/version_spec.rb +++ b/cargo/spec/dependabot/cargo/version_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Dependabot::Cargo::Version do subject(:version) { described_class.new(version_string) } + let(:version_string) { "1.0.0" } describe "#to_s" do @@ -13,61 +14,73 @@ context "with a non-prerelease" do let(:version_string) { "1.0.0" } + it { is_expected.to eq "1.0.0" } end context "with a normal prerelease" do let(:version_string) { "1.0.0.pre1" } + it { is_expected.to eq "1.0.0.pre1" } end context "with a PHP-style prerelease" do let(:version_string) { "1.0.0-pre1" } + it { is_expected.to eq "1.0.0-pre1" } end context "with a build version" do let(:version_string) { "1.0.0-pre1+something" } + it { is_expected.to eq "1.0.0-pre1+something" } end context "with a build version with hyphens" do let(:version_string) { "0.9.0+wasi-snapshot-preview1" } + it { is_expected.to eq "0.9.0+wasi-snapshot-preview1" } end context "with a build version with hyphens in multiple identifiers" do let(:version_string) { "0.9.0+wasi-snapshot1.alpha-preview" } + it { is_expected.to eq "0.9.0+wasi-snapshot1.alpha-preview" } end context "with a blank version" do let(:version_string) { "" } + it { is_expected.to eq "" } end context "with a version (not a version string)" do let(:version_string) { described_class.new("1.0.0") } + it { is_expected.to eq "1.0.0" } end end describe "compatibility with Gem::Requirement" do subject { requirement.satisfied_by?(version) } + let(:requirement) { Gem::Requirement.new(">= 1.0.0") } context "with a valid version" do let(:version_string) { "1.0.0" } + it { is_expected.to eq(true) } end context "with an invalid version" do let(:version_string) { "0.9.0" } + it { is_expected.to eq(false) } end context "with a valid prerelease version" do let(:version_string) { "1.1.0-pre" } + it { is_expected.to eq(true) } end end @@ -80,6 +93,7 @@ valid.each do |version| context "with version #{version}" do let(:version_string) { version } + it { is_expected.to eq(true) } end end @@ -88,6 +102,7 @@ invalid.each do |version| context "with version #{version}" do let(:version_string) { version } + it { is_expected.to eq(false) } end end diff --git a/common/spec/dependabot/clients/azure_spec.rb b/common/spec/dependabot/clients/azure_spec.rb index 13b5b54944..862b1252c2 100644 --- a/common/spec/dependabot/clients/azure_spec.rb +++ b/common/spec/dependabot/clients/azure_spec.rb @@ -143,6 +143,7 @@ context "when author_details is nil" do let(:author_details) { nil } + it "pushes commit without author property" do create_commit @@ -443,6 +444,7 @@ before do @request_body = "request body" end + it "with failure count <= max_retries" do # Request succeeds on third attempt stub_request(:post, base_url) diff --git a/common/spec/dependabot/clients/bitbucket_spec.rb b/common/spec/dependabot/clients/bitbucket_spec.rb index b10d4e86e8..01b85a532f 100644 --- a/common/spec/dependabot/clients/bitbucket_spec.rb +++ b/common/spec/dependabot/clients/bitbucket_spec.rb @@ -12,6 +12,7 @@ .with(headers: { "Authorization" => "Bearer #{access_token}" }) .to_return(status: 200, body: fixture("bitbucket", "current_user.json")) end + let(:access_token) { "access_token" } let(:credentials) do [Dependabot::Credential.new({ @@ -122,6 +123,7 @@ subject do client.current_user end + specify { expect { subject }.to_not raise_error } it { is_expected.to eq("{11111111-6349-0000-aea6-111111111111}") } diff --git a/common/spec/dependabot/clients/codecommit_spec.rb b/common/spec/dependabot/clients/codecommit_spec.rb index 50b7746560..c78f2584a6 100644 --- a/common/spec/dependabot/clients/codecommit_spec.rb +++ b/common/spec/dependabot/clients/codecommit_spec.rb @@ -28,6 +28,7 @@ let(:client) do described_class.for_source(source: source, credentials: credentials) end + before do allow_any_instance_of( Dependabot::Clients::CodeCommit @@ -56,6 +57,7 @@ context "without credentials" do let(:credentials) { [] } + before { ENV["AWS_REGION"] = "us-east-1" } it { is_expected.to eq("9c8376e9b2e943c2c72fac4b239876f377f0305a") } diff --git a/common/spec/dependabot/clients/github_with_retries_spec.rb b/common/spec/dependabot/clients/github_with_retries_spec.rb index 61fe3da8c8..cbe8f461c9 100644 --- a/common/spec/dependabot/clients/github_with_retries_spec.rb +++ b/common/spec/dependabot/clients/github_with_retries_spec.rb @@ -31,6 +31,7 @@ describe "with multiple possible access tokens" do let(:access_tokens) { %w(my-token my-other-token) } let(:client) { described_class.new(access_tokens: access_tokens) } + subject { client.contents("some/repo", path: "important_path.json") } context "when the request has to be retried" do diff --git a/common/spec/dependabot/config/file_fetcher_spec.rb b/common/spec/dependabot/config/file_fetcher_spec.rb index 2d209ee64a..cdedd409f2 100644 --- a/common/spec/dependabot/config/file_fetcher_spec.rb +++ b/common/spec/dependabot/config/file_fetcher_spec.rb @@ -35,7 +35,9 @@ describe "#config_file" do subject(:config_file) { file_fetcher_instance.config_file } + let(:url) { "https://api.github.com/repos/#{repo}/contents/" } + before do allow(file_fetcher_instance).to receive(:commit).and_return("sha") stub_request(:get, url + ".github/dependabot.yml?ref=sha") diff --git a/common/spec/dependabot/config/ignore_condition_spec.rb b/common/spec/dependabot/config/ignore_condition_spec.rb index 570c1e7139..a658ff1fd5 100644 --- a/common/spec/dependabot/config/ignore_condition_spec.rb +++ b/common/spec/dependabot/config/ignore_condition_spec.rb @@ -14,6 +14,7 @@ describe "#ignored_versions" do subject(:ignored_versions) { ignore_condition.ignored_versions(dependency, security_updates_only) } + let(:dependency) do Dependabot::Dependency.new( name: dependency_name, @@ -269,6 +270,7 @@ def expect_ignored(versions) context "with ignore_patch_versions" do let(:update_types) { ["version-update:semver-patch"] } + it "returns the expected range" do expect(ignored_versions).to eq([]) end @@ -276,6 +278,7 @@ def expect_ignored(versions) context "with ignore_minor_versions" do let(:update_types) { ["version-update:semver-minor"] } + it "returns the expected range" do expect(ignored_versions).to eq([]) end @@ -283,6 +286,7 @@ def expect_ignored(versions) context "with ignore_major_versions" do let(:update_types) { ["version-update:semver-major"] } + it "returns the expected range" do expect(ignored_versions).to eq([]) end @@ -312,16 +316,19 @@ def expect_ignored(versions) context "with ignore_major_versions" do let(:update_types) { ["version-update:semver-major"] } + it { is_expected.to eq([]) } end context "with ignore_minor_versions" do let(:update_types) { ["version-update:semver-minor"] } + it { is_expected.to eq([]) } end context "with ignore_patch_versions" do let(:update_types) { ["version-update:semver-patch"] } + it { is_expected.to eq([]) } end end diff --git a/common/spec/dependabot/config/update_config_spec.rb b/common/spec/dependabot/config/update_config_spec.rb index 226279323a..973348a407 100644 --- a/common/spec/dependabot/config/update_config_spec.rb +++ b/common/spec/dependabot/config/update_config_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Dependabot::Config::UpdateConfig do describe "#ignored_versions_for" do subject(:ignored_versions) { config.ignored_versions_for(dependency, security_updates_only: security_updates_only) } + let(:dependency) do Dependabot::Dependency.new( name: "@types/node", @@ -110,6 +111,7 @@ context "with security_updates_only" do let(:security_updates_only) { true } + it "does not expand versions" do expect(ignored_versions).to eq([]) end diff --git a/common/spec/dependabot/dependency_file_spec.rb b/common/spec/dependabot/dependency_file_spec.rb index c59dc77fec..3e4c051d5f 100644 --- a/common/spec/dependabot/dependency_file_spec.rb +++ b/common/spec/dependabot/dependency_file_spec.rb @@ -26,11 +26,13 @@ context "that starts and ends with a slash" do let(:directory) { "/path/to/files/" } + it { is_expected.to eq("/path/to/files/Gemfile") } end context "that doesn't start or end with a slash" do let(:directory) { "path/to/files" } + it { is_expected.to eq("/path/to/files/Gemfile") } end @@ -43,6 +45,7 @@ directory: directory ) end + it { is_expected.to eq("/path/to/Gemfile") } end end @@ -62,11 +65,13 @@ context "that starts and ends with a slash" do let(:directory) { "/path/to/files" } + it { is_expected.to eq("/path/to/files") } end context "that doesn't start or end with a slash" do let(:directory) { "path/to/files" } + it { is_expected.to eq("/path/to/files") } end end diff --git a/common/spec/dependabot/errors_spec.rb b/common/spec/dependabot/errors_spec.rb index e526b62eae..b70c3f0702 100644 --- a/common/spec/dependabot/errors_spec.rb +++ b/common/spec/dependabot/errors_spec.rb @@ -16,6 +16,7 @@ it { is_expected.to eq("some error") } let(:tmp) { Dependabot::Utils::BUMP_TMP_DIR_PATH } + context "with dependabot temp path" do let(:message) do "#{tmp}/dependabot_20201218-14100-y0d218/path error" @@ -89,25 +90,30 @@ describe "#file_name" do subject { error.file_name } + it { is_expected.to eq("Gemfile") } end describe "#directory" do subject { error.directory } + it { is_expected.to eq("/path/to") } context "with the root directory" do let(:file_path) { "Gemfile" } + it { is_expected.to eq("/") } end context "with a root level file whose path starts with a slash" do let(:file_path) { "/Gemfile" } + it { is_expected.to eq("/") } end context "with a nested file whose path starts with a slash" do let(:file_path) { "/path/to/Gemfile" } + it { is_expected.to eq("/path/to") } end end diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index 2e6d119448..0602bb6a7a 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -41,6 +41,7 @@ Dependabot::Clients::CodeCommit ).to receive(:cc_client).and_return(stubbed_cc_client) end + let(:repo_contents_path) { nil } let(:child_class) do @@ -299,6 +300,7 @@ def fetch_files describe "#files" do subject(:files) { file_fetcher_instance.files } + before do allow(file_fetcher_instance).to receive(:commit).and_return("sha") end @@ -307,6 +309,7 @@ def fetch_files its(:length) { is_expected.to eq(1) } let(:url) { "https://api.github.com/repos/#{repo}/contents/" } + before do stub_request(:get, url + "requirements.txt?ref=sha") .with(headers: { "Authorization" => "token token" }) @@ -445,6 +448,7 @@ def fetch_files it { is_expected.to be_a(Dependabot::DependencyFile) } its(:content) { is_expected.to include("octokit") } its(:type) { is_expected.to include("symlink") } + its(:symlink_target) do is_expected.to include("symlinked/requirements.txt") end @@ -693,6 +697,7 @@ def fetch_files "https://api.github.com/repos/#{repo}/git/blobs/" \ "88b4e0a1c8093fae2b4fa52534035f9f85ed0956" end + before do stub_request(:get, url + "requirements.txt?ref=sha") .with(headers: { "Authorization" => "token token" }) @@ -725,6 +730,7 @@ def fetch_files context "with a directory specified" do let(:directory) { "app/" } let(:url) { "https://api.github.com/repos/#{repo}/contents/app/" } + before do stub_request(:get, url.gsub(%r{/$}, "") + "?ref=sha") .with(headers: { "Authorization" => "token token" }) @@ -1234,6 +1240,7 @@ def fetch_files file_content: "foo" ) end + let(:directory) { "app/" } it "gets the file" do @@ -1255,6 +1262,7 @@ def fetch_files file_content: "foo" ) end + let(:directory) { "/app" } it "gets the file" do @@ -1276,6 +1284,7 @@ def fetch_files file_content: "foo" ) end + let(:directory) { "a/pp" } it "gets the file" do @@ -1360,6 +1369,7 @@ def fetch_files context "with repo_contents_path" do let(:repo_contents_path) { Dir.mktmpdir } + after { FileUtils.rm_rf(repo_contents_path) } describe "#files" do @@ -1370,7 +1380,9 @@ def fetch_files # `git clone` against a file:// URL that is filled by the test let(:repo_path) { Dir.mktmpdir } after { FileUtils.rm_rf(repo_path) } + let(:fill_repo) { nil } + before do Dir.chdir(repo_path) do `git init --initial-branch main .` @@ -1470,6 +1482,7 @@ def optional it { is_expected.to be_a(Dependabot::DependencyFile) } its(:type) { is_expected.to include("symlink") } + its(:symlink_target) do is_expected.to include("symlinked/requirements.txt") end diff --git a/common/spec/dependabot/file_fetchers/shared_examples_for_file_fetchers.rb b/common/spec/dependabot/file_fetchers/shared_examples_for_file_fetchers.rb index c396d30c48..d7901e2bb0 100644 --- a/common/spec/dependabot/file_fetchers/shared_examples_for_file_fetchers.rb +++ b/common/spec/dependabot/file_fetchers/shared_examples_for_file_fetchers.rb @@ -8,6 +8,7 @@ RSpec.shared_examples "a dependency file fetcher" do describe "the class" do subject { described_class } + let(:base_class) { Dependabot::FileFetchers::Base } its(:superclass) { is_expected.to eq(base_class) } diff --git a/common/spec/dependabot/file_parsers/base/dependency_set_spec.rb b/common/spec/dependabot/file_parsers/base/dependency_set_spec.rb index 6c3ed8d389..2128ecb7f0 100644 --- a/common/spec/dependabot/file_parsers/base/dependency_set_spec.rb +++ b/common/spec/dependabot/file_parsers/base/dependency_set_spec.rb @@ -19,6 +19,7 @@ describe ".new" do context "with no argument" do subject { described_class.new } + it { is_expected.to be_a(described_class) } its(:dependencies) { is_expected.to eq([]) } end @@ -87,6 +88,7 @@ let(:dependency_set) { described_class.new(case_sensitive: true) } it { is_expected.to be_a(described_class) } + its(:dependencies) do is_expected.to eq([existing_dependency, dependency]) end @@ -111,6 +113,7 @@ end it { is_expected.to be_a(described_class) } + its(:dependencies) do is_expected.to match_array([existing_dependency, dependency]) end diff --git a/common/spec/dependabot/file_parsers/base_spec.rb b/common/spec/dependabot/file_parsers/base_spec.rb index 8865f9e7c7..aac5937f6c 100644 --- a/common/spec/dependabot/file_parsers/base_spec.rb +++ b/common/spec/dependabot/file_parsers/base_spec.rb @@ -59,11 +59,13 @@ def check_required_files context "when the requested file is present" do let(:filename) { "Gemfile" } + it { is_expected.to eq(gemfile) } end context "when the requested file is not present" do let(:filename) { "Unknown.file" } + it { is_expected.to be_nil } end end diff --git a/common/spec/dependabot/file_parsers/shared_examples_for_file_parsers.rb b/common/spec/dependabot/file_parsers/shared_examples_for_file_parsers.rb index c472ec0c54..cb16aa6121 100644 --- a/common/spec/dependabot/file_parsers/shared_examples_for_file_parsers.rb +++ b/common/spec/dependabot/file_parsers/shared_examples_for_file_parsers.rb @@ -8,6 +8,7 @@ RSpec.shared_examples "a dependency file parser" do describe "the class" do subject { described_class } + let(:base_class) { Dependabot::FileParsers::Base } its(:superclass) { is_expected.to be <= base_class } diff --git a/common/spec/dependabot/file_updaters/base_spec.rb b/common/spec/dependabot/file_updaters/base_spec.rb index 570b4c12b3..35a99e5a68 100644 --- a/common/spec/dependabot/file_updaters/base_spec.rb +++ b/common/spec/dependabot/file_updaters/base_spec.rb @@ -70,11 +70,13 @@ def check_required_files context "when the requested file is present" do let(:filename) { "Gemfile" } + it { is_expected.to eq(gemfile) } end context "when the requested file is not present" do let(:filename) { "Unknown.file" } + it { is_expected.to be_nil } end end @@ -83,6 +85,7 @@ def check_required_files subject(:updated_file) do updater_instance.send(:updated_file, file: file, content: content) end + let(:file) { gemfile } let(:content) { "codes" } diff --git a/common/spec/dependabot/file_updaters/shared_examples_for_file_updaters.rb b/common/spec/dependabot/file_updaters/shared_examples_for_file_updaters.rb index 3d9b829c7c..1eb53edb31 100644 --- a/common/spec/dependabot/file_updaters/shared_examples_for_file_updaters.rb +++ b/common/spec/dependabot/file_updaters/shared_examples_for_file_updaters.rb @@ -7,6 +7,7 @@ RSpec.shared_examples "a dependency file updater" do describe "the class" do subject { described_class } + let(:base_class) { Dependabot::FileUpdaters::Base } its(:updated_files_regex) { is_expected.to be_an_instance_of(Array) } diff --git a/common/spec/dependabot/git_commit_checker_spec.rb b/common/spec/dependabot/git_commit_checker_spec.rb index c26858ef25..11e92228b8 100644 --- a/common/spec/dependabot/git_commit_checker_spec.rb +++ b/common/spec/dependabot/git_commit_checker_spec.rb @@ -56,6 +56,7 @@ context "with a non-git dependency" do let(:source) { nil } + it { is_expected.to eq(false) } end @@ -145,6 +146,7 @@ context "with a non-git dependency" do let(:source) { nil } + specify { expect { subject }.to raise_error(/Not a git dependency!/) } end @@ -183,10 +185,12 @@ } ) end + let(:upload_pack_fixture) { "no_tags" } context "but no tags on GitHub" do let(:upload_pack_fixture) { "no_tags" } + it { is_expected.to eq(false) } end @@ -207,6 +211,7 @@ context "with tags on GitHub" do let(:upload_pack_fixture) { "business" } let(:comparison_url) { repo_url + "/compare/v1.5.0...df9f605" } + before do stub_request(:get, comparison_url) .to_return( @@ -220,6 +225,7 @@ let(:comparison_response) do fixture("github", "commit_compare_diverged.json") end + it { is_expected.to eq(false) } end @@ -227,6 +233,7 @@ let(:comparison_response) do fixture("github", "commit_compare_behind.json") end + it { is_expected.to eq(true) } context "even though this fork is not on GitHub" do @@ -238,6 +245,7 @@ ref: "df9f605" } end + it { is_expected.to eq(true) } end @@ -250,6 +258,7 @@ "password" => "token" }] end + it { is_expected.to eq(true) } end end @@ -288,6 +297,7 @@ .to receive(:look_up_source) .and_return(Dependabot::Source.from_url(source_url)) end + let(:source_url) { "https://bitbucket.org/gocardless/business" } let(:service_pack_url) do "https://bitbucket.org/gocardless/business.git/info/refs" \ @@ -307,6 +317,7 @@ } ) end + let(:upload_pack_fixture) { "business" } context "when not included in a release" do @@ -365,30 +376,35 @@ context "with a non-git dependency" do let(:source) { nil } + specify { expect { subject }.to raise_error(/Not a git dependency!/) } end context "with no branch or reference specified" do let(:ref) { nil } let(:branch) { nil } + it { is_expected.to eq(false) } end context "with no reference specified" do let(:ref) { nil } let(:branch) { "master" } + it { is_expected.to eq(false) } end context "with a reference that matches the branch" do let(:ref) { "master" } let(:branch) { "master" } + it { is_expected.to eq(false) } end context "with a reference that does not match the branch" do let(:ref) { "v1.0.0" } let(:branch) { "master" } + it { is_expected.to eq(true) } end @@ -397,11 +413,13 @@ context "and a reference that matches the version" do let(:ref) { "df9f605" } + it { is_expected.to eq(true) } end context "and a reference that does not match the version" do let(:repo_url) { "https://github.com/gocardless/business.git" } + before do stub_request(:get, repo_url + "/info/refs?service=git-upload-pack") .to_return( @@ -415,11 +433,13 @@ context "and does not match any branch names" do let(:ref) { "my_ref" } + it { is_expected.to eq(true) } end context "and does match a branch names" do let(:ref) { "master" } + it { is_expected.to eq(false) } end @@ -435,6 +455,7 @@ let(:repo_url) { "https://bitbucket.org/gocardless/business.git" } let(:ref) { "my_ref" } + it { is_expected.to eq(true) } end @@ -450,6 +471,7 @@ .with(anything, "git ls-remote #{git_url}") .and_return(["", "", exit_status]) end + let(:ref) { "my_ref" } it "raises a helpful error" do @@ -473,6 +495,7 @@ stub_request(:get, url + "/info/refs?service=git-upload-pack") .to_raise(Excon::Error::Timeout) end + let(:ref) { "my_ref" } it "raises a helpful error" do @@ -487,6 +510,7 @@ stub_request(:get, url + "/info/refs?service=git-upload-pack") .to_raise(Excon::Error::Timeout) end + let(:ref) { "my_ref" } it "raises a generic error (that won't be misinterpreted)" do @@ -742,6 +766,7 @@ ref: "master" } end + it { is_expected.to eq(false) } end @@ -754,6 +779,7 @@ ref: "v1.0.0" } end + it { is_expected.to eq(true) } context "that includes a hyphen" do @@ -765,6 +791,7 @@ ref: "v1.0.0-pre" } end + it { is_expected.to eq(true) } end @@ -777,6 +804,7 @@ ref: "v1" } end + it { is_expected.to eq(true) } end end @@ -790,6 +818,7 @@ ref: "1a21311" } end + it { is_expected.to eq(false) } end @@ -802,6 +831,7 @@ ref: nil } end + it { is_expected.to eq(false) } end end @@ -818,6 +848,7 @@ ref: "master" } end + it { is_expected.to eq(false) } end @@ -830,6 +861,7 @@ ref: "v1.0.0" } end + it { is_expected.to eq(false) } end @@ -855,6 +887,7 @@ } ) end + let(:upload_pack_fixture) { "monolog" } it { is_expected.to eq(true) } @@ -882,6 +915,7 @@ ref: nil } end + it { is_expected.to eq(false) } end end @@ -911,6 +945,7 @@ describe "#local_tag_for_latest_version" do subject { checker.local_tag_for_latest_version } + let(:repo_url) { "https://github.com/gocardless/business.git" } let(:service_pack_url) { repo_url + "/info/refs?service=git-upload-pack" } before do @@ -923,6 +958,7 @@ } ) end + let(:upload_pack_fixture) { "no_tags" } context "with no tags on GitHub" do @@ -949,6 +985,7 @@ context "with tags on GitHub" do context "but no version tags" do let(:upload_pack_fixture) { "no_versions" } + it { is_expected.to eq(nil) } end @@ -956,15 +993,18 @@ let(:upload_pack_fixture) { "business" } its([:tag]) { is_expected.to eq("v1.13.0") } + its([:commit_sha]) do is_expected.to eq("7bb4e41ce5164074a0920d5b5770d196b4d90104") end + its([:tag_sha]) do is_expected.to eq("37f41032a0f191507903ebbae8a5c0cb945d7585") end context "and a pre-release latest version" do let(:upload_pack_fixture) { "k8s-apiextensions-apiserver" } + its([:tag]) { is_expected.to eq("kubernetes-1.11.2") } context "when using a pre-release" do @@ -997,6 +1037,7 @@ context "raise_on_ignored when later versions are allowed" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -1004,10 +1045,12 @@ context "already on the latest version" do let(:version) { "1.13.0" } + its([:tag]) { is_expected.to eq("v1.13.0") } context "raise_on_ignored" do let(:raise_on_ignored) { true } + it "doesn't raise an error" do expect { subject }.to_not raise_error end @@ -1017,10 +1060,12 @@ context "all later versions ignored" do let(:version) { "1.0.0" } let(:ignored_versions) { ["> 1.0.0"] } + its([:tag]) { is_expected.to eq("v1.0.0") } context "raise_on_ignored" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -1029,22 +1074,26 @@ context "and an ignore condition" do let(:ignored_versions) { [">= 1.12.0"] } + its([:tag]) { is_expected.to eq("v1.11.1") } end context "multiple ignore conditions" do let(:ignored_versions) { [">= 1.11.2, < 1.12.0"] } + its([:tag]) { is_expected.to eq("v1.13.0") } end context "all versions ignored" do let(:ignored_versions) { [">= 0"] } + it "returns nil" do expect(subject).to be_nil end context "raise_on_ignored" do let(:raise_on_ignored) { true } + it "raises an error" do expect { subject }.to raise_error(Dependabot::AllVersionsIgnored) end @@ -1069,8 +1118,10 @@ describe "#local_ref_for_latest_version_matching_existing_precision" do subject { checker.local_ref_for_latest_version_matching_existing_precision } + let(:repo_url) { "https://github.com/gocardless/business.git" } let(:service_pack_url) { repo_url + "/info/refs?service=git-upload-pack" } + before do stub_request(:get, service_pack_url) .to_return( @@ -1084,11 +1135,13 @@ context "with no tags, nor version branches" do let(:upload_pack_fixture) { "no_tags" } + it { is_expected.to be_nil } end context "with no version tags nor version branches" do let(:upload_pack_fixture) { "no_versions" } + it { is_expected.to be_nil } end @@ -1194,8 +1247,10 @@ describe "#local_ref_for_latest_version_lower_precision" do subject { checker.local_ref_for_latest_version_lower_precision } + let(:repo_url) { "https://github.com/gocardless/business.git" } let(:service_pack_url) { repo_url + "/info/refs?service=git-upload-pack" } + before do stub_request(:get, service_pack_url) .to_return( @@ -1209,11 +1264,13 @@ context "with no tags, nor version branches" do let(:upload_pack_fixture) { "no_tags" } + it { is_expected.to be_nil } end context "with no version tags nor version branches" do let(:upload_pack_fixture) { "no_versions" } + it { is_expected.to be_nil } end @@ -1342,6 +1399,7 @@ } ) end + let(:upload_pack_fixture) { "actions-checkout" } context "that is a tag" do @@ -1400,6 +1458,7 @@ } ) end + let(:upload_pack_fixture) { "actions-checkout-moving-v2" } context "for a moving major tag" do diff --git a/common/spec/dependabot/git_metadata_fetcher_spec.rb b/common/spec/dependabot/git_metadata_fetcher_spec.rb index 771d6d5261..05b0d21c00 100644 --- a/common/spec/dependabot/git_metadata_fetcher_spec.rb +++ b/common/spec/dependabot/git_metadata_fetcher_spec.rb @@ -44,19 +44,23 @@ context "but no tags on GitHub" do let(:upload_pack_fixture) { "no_tags" } + it { is_expected.to eq([]) } context "and a git@... URL" do let(:url) { "git@github.com:gocardless/business" } + it { is_expected.to eq([]) } context "that separates with :/" do let(:url) { "git@github.com:/gocardless/business" } + it { is_expected.to eq([]) } end context "that separates with /" do let(:url) { "git@github.com/gocardless/business" } + it { is_expected.to eq([]) } end end @@ -248,11 +252,13 @@ context "with tags on GitHub" do let(:upload_pack_fixture) { "no_versions" } + it { is_expected.to eq(%w(master imported release)) } end context "but no tags on GitHub" do let(:upload_pack_fixture) { "no_tags" } + it { is_expected.to eq(%w(master rails5)) } end @@ -277,6 +283,7 @@ describe "#head_commit_for_ref" do subject(:head_commit_for_ref) { checker.head_commit_for_ref(ref) } + let(:ref) { "v1.0.0" } before do @@ -327,11 +334,13 @@ context "that doesn't exist" do let(:ref) { "nonexistent" } + it { is_expected.to be_nil } end context "that is HEAD" do let(:ref) { "HEAD" } + it { is_expected.to eq("7bb4e41ce5164074a0920d5b5770d196b4d90104") } end end diff --git a/common/spec/dependabot/metadata_finders/base/changelog_finder_spec.rb b/common/spec/dependabot/metadata_finders/base/changelog_finder_spec.rb index 2cdf33c061..1a64fabead 100644 --- a/common/spec/dependabot/metadata_finders/base/changelog_finder_spec.rb +++ b/common/spec/dependabot/metadata_finders/base/changelog_finder_spec.rb @@ -17,6 +17,7 @@ dependency: dependency ) end + let(:credentials) { github_credentials } let(:source) do Dependabot::Source.new( @@ -48,6 +49,7 @@ let(:dummy_commits_finder) do instance_double(Dependabot::MetadataFinders::Base::CommitsFinder) end + before do allow(Dependabot::MetadataFinders::Base::CommitsFinder) .to receive(:new).and_return(dummy_commits_finder) @@ -138,6 +140,7 @@ body: changelog_body, headers: { "Content-Type" => "application/json" }) end + let(:changelog_body) { fixture("github", "changelog_contents.json") } context "with a changelog" do @@ -264,6 +267,7 @@ end let(:dependency_name) { "scrapy" } let(:github_response) { fixture("github", "scrapy_files.json") } + before do stub_request(:get, github_url + "docs") .to_return(status: github_status, @@ -330,6 +334,7 @@ let(:changelog_body_without_version) do fixture("github", "changelog_contents_japanese.json") end + before do stub_request(:get, github_url + "packages/stryker") .to_return(status: github_status, @@ -427,6 +432,7 @@ body: changelog_body, headers: { "Content-Type" => "application/json" }) end + let(:changelog_body) { fixture("github", "changelog_contents.json") } it "gets the right URL" do @@ -549,6 +555,7 @@ context "that can't be found exists" do let(:gitlab_status) { 404 } let(:gitlab_response) { fixture("gitlab", "not_found.json") } + it { is_expected.to be_nil } end end @@ -632,11 +639,13 @@ context "that can't be found exists" do let(:azure_status) { 404 } + it { is_expected.to be_nil } end context "that is private" do let(:azure_status) { 403 } + it { is_expected.to be_nil } end end @@ -709,17 +718,20 @@ context "that can't be found exists" do let(:bitbucket_status) { 404 } + it { is_expected.to be_nil } end context "that is private" do let(:bitbucket_status) { 403 } + it { is_expected.to be_nil } end end context "without a source" do let(:source) { nil } + it { is_expected.to be_nil } context "for a docker dependency" do @@ -747,6 +759,7 @@ describe "#changelog_text" do subject(:changelog_text) { finder.changelog_text } + let(:dependency_version) { "1.4.0" } let(:dependency_previous_version) { "1.0.0" } @@ -819,6 +832,7 @@ context "that is an image" do let(:changelog_body) { fixture("github", "contents_image.json") } + it { is_expected.to be_nil } end @@ -1058,6 +1072,7 @@ context "without a source" do let(:source) { nil } + it { is_expected.to be_nil } end end @@ -1122,6 +1137,7 @@ describe "#upgrade_guide_text" do subject(:upgrade_guide_text) { finder.upgrade_guide_text } + let(:dependency_version) { "1.4.0" } let(:dependency_previous_version) { "0.9.0" } diff --git a/common/spec/dependabot/metadata_finders/base/changelog_pruner_spec.rb b/common/spec/dependabot/metadata_finders/base/changelog_pruner_spec.rb index d4758bfb02..8e9be9f422 100644 --- a/common/spec/dependabot/metadata_finders/base/changelog_pruner_spec.rb +++ b/common/spec/dependabot/metadata_finders/base/changelog_pruner_spec.rb @@ -15,6 +15,7 @@ dependency: dependency ) end + let(:changelog_text) do Base64.decode64(JSON.parse(changelog_body).fetch("content")) .force_encoding("UTF-8").encode @@ -107,6 +108,7 @@ context "when the new version is not included" do let(:dependency_version) { "5.0.0" } + it { is_expected.to eq(false) } end @@ -126,6 +128,7 @@ context "when the previous version is not included" do let(:dependency_previous_version) { "5.0.0" } + it { is_expected.to eq(false) } end @@ -138,6 +141,7 @@ describe "#pruned_text" do subject(:pruned_text) { pruner.pruned_text } + let(:dependency_version) { "1.4.0" } let(:dependency_previous_version) { "1.0.0" } @@ -267,6 +271,7 @@ context "and the previous version is the latest in the changelog" do let(:dependency_previous_version) { "1.11.1" } + it { is_expected.to be_nil } end end diff --git a/common/spec/dependabot/metadata_finders/base/commits_finder_spec.rb b/common/spec/dependabot/metadata_finders/base/commits_finder_spec.rb index 12dce39631..cac9ab83dd 100644 --- a/common/spec/dependabot/metadata_finders/base/commits_finder_spec.rb +++ b/common/spec/dependabot/metadata_finders/base/commits_finder_spec.rb @@ -15,6 +15,7 @@ source: source ) end + let(:dependency) do Dependabot::Dependency.new( name: dependency_name, @@ -52,6 +53,7 @@ } ) end + let(:service_pack_url) do "https://github.com/gocardless/business.git/info/refs" \ "?service=git-upload-pack" @@ -175,6 +177,7 @@ directory: "packages/ember" ) end + before do allow(builder) .to receive(:fetch_dependency_tags) @@ -261,6 +264,7 @@ context "with a github repo that has a DMCA takedown notice" do let(:url) { "https://github.com/gocardless/business.git" } + before do stub_request(:get, service_pack_url) .to_return( @@ -813,6 +817,7 @@ context "without a recognised source" do let(:source) { nil } + it { is_expected.to be_nil } end end @@ -927,6 +932,7 @@ directory: "packages/@pollyjs/ember" ) end + before do allow(builder) .to receive(:fetch_dependency_tags) @@ -1183,6 +1189,7 @@ repo: "org/#{dependency_name}" ) end + before do stub_request(:get, gitlab_compare_url) .to_return(status: 200, @@ -1278,6 +1285,7 @@ context "without a recognised source" do let(:source) { nil } + it { is_expected.to eq([]) } end end diff --git a/common/spec/dependabot/metadata_finders/base/release_finder_spec.rb b/common/spec/dependabot/metadata_finders/base/release_finder_spec.rb index aafcf57a8c..916b4df2e2 100644 --- a/common/spec/dependabot/metadata_finders/base/release_finder_spec.rb +++ b/common/spec/dependabot/metadata_finders/base/release_finder_spec.rb @@ -16,6 +16,7 @@ credentials: credentials ) end + let(:dependency) do Dependabot::Dependency.new( name: dependency_name, @@ -93,6 +94,7 @@ context "without a source" do let(:source) { nil } + it { is_expected.to be_nil } end @@ -305,6 +307,7 @@ context "but all versions are blank or nil" do let(:dependency_version) { "1.7.0" } + it { is_expected.to be_nil } end @@ -432,6 +435,7 @@ context "when the release is not present" do let(:dependency_version) { "1.9.0" } let(:dependency_previous_version) { "1.8.0" } + it { is_expected.to be_nil } context "and there is a blank named release that needs excluding" do @@ -440,6 +444,7 @@ end let(:dependency_version) { "3.5.3" } let(:dependency_previous_version) { "3.5.2" } + it { is_expected.to be_nil } end @@ -462,6 +467,7 @@ let(:github_response) do fixture("github", "business_releases_bad_name.json") end + it "gets the right text" do expect(subject) .to eq( @@ -477,6 +483,7 @@ let(:dependency_version) { "2.4.0" } let(:dependency_previous_version) { "2.3.2" } let(:github_response) { fixture("github", "releases_monorepo.json") } + it "gets the right text" do expect(subject) .to eq( @@ -498,6 +505,7 @@ context "when authentication fails" do before { stub_request(:get, github_url).to_return(status: 404) } + it { is_expected.to be_nil } end @@ -579,6 +587,7 @@ context "without a recognised source" do let(:source) { nil } + it { is_expected.to be_nil } end end diff --git a/common/spec/dependabot/metadata_finders/base_spec.rb b/common/spec/dependabot/metadata_finders/base_spec.rb index 43aa7d17e8..900784b20a 100644 --- a/common/spec/dependabot/metadata_finders/base_spec.rb +++ b/common/spec/dependabot/metadata_finders/base_spec.rb @@ -11,6 +11,7 @@ subject(:finder) do described_class.new(dependency: dependency, credentials: credentials) end + let(:dependency) do Dependabot::Dependency.new( name: dependency_name, @@ -35,6 +36,7 @@ }] end before { allow(finder).to receive(:source).and_return(source) } + let(:source) do Dependabot::Source.new( provider: "github", @@ -60,6 +62,7 @@ context "without a source" do let(:source) { nil } + it { is_expected.to be_nil } end @@ -101,6 +104,7 @@ describe "#commits_url" do subject { finder.commits_url } + let(:dummy_commits_finder) do instance_double(Dependabot::MetadataFinders::Base::CommitsFinder) end @@ -123,6 +127,7 @@ describe "#commits" do subject { finder.commits } + let(:dummy_commits_finder) do instance_double(Dependabot::MetadataFinders::Base::CommitsFinder) end @@ -145,6 +150,7 @@ describe "#changelog_url" do subject { finder.changelog_url } + let(:dummy_changelog_finder) do instance_double(Dependabot::MetadataFinders::Base::ChangelogFinder) end @@ -168,6 +174,7 @@ describe "#changelog_text" do subject { finder.changelog_text } + let(:dummy_changelog_finder) do instance_double(Dependabot::MetadataFinders::Base::ChangelogFinder) end @@ -191,6 +198,7 @@ describe "#upgrade_guide_url" do subject { finder.upgrade_guide_url } + let(:dummy_changelog_finder) do instance_double(Dependabot::MetadataFinders::Base::ChangelogFinder) end @@ -214,6 +222,7 @@ describe "#upgrade_guide_text" do subject { finder.upgrade_guide_text } + let(:dummy_changelog_finder) do instance_double(Dependabot::MetadataFinders::Base::ChangelogFinder) end @@ -237,6 +246,7 @@ describe "#releases_url" do subject { finder.releases_url } + let(:dummy_release_finder) do instance_double(Dependabot::MetadataFinders::Base::ReleaseFinder) end @@ -259,6 +269,7 @@ describe "#releases_text" do subject { finder.releases_text } + let(:dummy_release_finder) do instance_double(Dependabot::MetadataFinders::Base::ReleaseFinder) end diff --git a/common/spec/dependabot/metadata_finders/shared_examples_for_metadata_finders.rb b/common/spec/dependabot/metadata_finders/shared_examples_for_metadata_finders.rb index 5cf68d5cd0..df570b4fb1 100644 --- a/common/spec/dependabot/metadata_finders/shared_examples_for_metadata_finders.rb +++ b/common/spec/dependabot/metadata_finders/shared_examples_for_metadata_finders.rb @@ -7,6 +7,7 @@ RSpec.shared_examples "a dependency metadata finder" do describe "the class" do subject { described_class } + let(:base_class) { Dependabot::MetadataFinders::Base } its(:superclass) { is_expected.to eq(base_class) } diff --git a/common/spec/dependabot/pull_request_creator/azure_spec.rb b/common/spec/dependabot/pull_request_creator/azure_spec.rb index 2ca6ce7926..7061cafabd 100644 --- a/common/spec/dependabot/pull_request_creator/azure_spec.rb +++ b/common/spec/dependabot/pull_request_creator/azure_spec.rb @@ -130,6 +130,7 @@ context "with reviewers" do let(:reviewers) { ["0013-0006-1980"] } + it "pushes a commit to Azure and creates a pull request with assigned reviewers" do creator.create @@ -151,6 +152,7 @@ context "with assignees" do let(:assignees) { ["0013-0006-1980"] } + it "pushes a commit to Azure and creates a pull request with assigned optional reviewers" do creator.create diff --git a/common/spec/dependabot/pull_request_creator/branch_namer/solo_strategy_spec.rb b/common/spec/dependabot/pull_request_creator/branch_namer/solo_strategy_spec.rb index ced27b3033..bfd4da605c 100644 --- a/common/spec/dependabot/pull_request_creator/branch_namer/solo_strategy_spec.rb +++ b/common/spec/dependabot/pull_request_creator/branch_namer/solo_strategy_spec.rb @@ -48,6 +48,7 @@ describe "#new_branch_name" do subject(:new_branch_name) { namer.new_branch_name } + it { is_expected.to eq("dependabot/dummy/business-1.5.0") } context "with directory" do @@ -423,6 +424,7 @@ context "that has a trailing dot" do let(:requirement_string) { "^7." } + it { is_expected.to eq("dependabot/dummy/business-tw-7") } end end diff --git a/common/spec/dependabot/pull_request_creator/branch_namer_spec.rb b/common/spec/dependabot/pull_request_creator/branch_namer_spec.rb index 18b6db32c5..98c0cf0f04 100644 --- a/common/spec/dependabot/pull_request_creator/branch_namer_spec.rb +++ b/common/spec/dependabot/pull_request_creator/branch_namer_spec.rb @@ -48,6 +48,7 @@ describe "#new_branch_name" do subject(:new_branch_name) { namer.new_branch_name } + it { is_expected.to eq("dependabot/dummy/business-1.5.0") } context "with directory" do @@ -423,6 +424,7 @@ context "that has a trailing dot" do let(:requirement_string) { "^7." } + it { is_expected.to eq("dependabot/dummy/business-tw-7") } end end diff --git a/common/spec/dependabot/pull_request_creator/github_spec.rb b/common/spec/dependabot/pull_request_creator/github_spec.rb index d2b2aedda8..9d44197000 100644 --- a/common/spec/dependabot/pull_request_creator/github_spec.rb +++ b/common/spec/dependabot/pull_request_creator/github_spec.rb @@ -561,6 +561,7 @@ headers: json_header ) end + let(:base_commit) { "basecommitsha" } it "creates a PR" do @@ -675,6 +676,7 @@ "\n" \ "Commit msg" end + before { allow(Time).to receive(:now).and_return(Time.new(2001, 1, 1, 0, 0, 0, "+00:00")) } it "passes the author details and signature to GitHub" do @@ -920,6 +922,7 @@ context "when a reviewer has been requested" do let(:reviewers) { { "reviewers" => ["greysteil"] } } + before do stub_request(:post, "#{repo_api_url}/pulls/1347/requested_reviewers") .to_return(status: 200, @@ -944,6 +947,7 @@ headers: json_header) stub_request(:post, "#{repo_api_url}/issues/1347/comments") end + let(:expected_comment_body) do "Dependabot tried to add `@greysteil` as a reviewer to this PR, " \ "but received the following error from GitHub:\n\n" \ @@ -974,6 +978,7 @@ context "when an assignee has been requested" do let(:assignees) { ["greysteil"] } + before do stub_request(:post, "#{repo_api_url}/issues/1347/assignees") .to_return(status: 201, @@ -1007,6 +1012,7 @@ context "when a milestone has been requested" do let(:milestone) { 5 } + before do stub_request(:patch, "#{repo_api_url}/issues/1347") .to_return(status: 201, diff --git a/common/spec/dependabot/pull_request_creator/labeler_spec.rb b/common/spec/dependabot/pull_request_creator/labeler_spec.rb index 84b8bf0bc5..2e28af78e8 100644 --- a/common/spec/dependabot/pull_request_creator/labeler_spec.rb +++ b/common/spec/dependabot/pull_request_creator/labeler_spec.rb @@ -78,10 +78,12 @@ body: fixture("github", labels_fixture_name), headers: json_header) end + let(:labels_fixture_name) { "labels_with_dependencies.json" } context "when the 'dependencies' label doesn't yet exist" do let(:labels_fixture_name) { "labels_without_dependencies.json" } + before do stub_request(:post, "#{repo_api_url}/labels") .to_return(status: 201, @@ -165,6 +167,7 @@ context "that should be ignored" do let(:labels_fixture_name) { "labels_with_custom_ignored.json" } + before do stub_request(:post, "#{repo_api_url}/labels") .to_return( @@ -196,6 +199,7 @@ context "when the 'ruby' label doesn't yet exist" do let(:labels_fixture_name) { "labels_with_dependencies.json" } + before do stub_request(:post, "#{repo_api_url}/labels") .to_return(status: 201, @@ -378,6 +382,7 @@ let(:repo_api_url) do "https://gitlab.com/api/v4/projects/#{CGI.escape(source.repo)}" end + before do stub_request(:get, "#{repo_api_url}/labels?per_page=100") .to_return(status: 200, @@ -508,6 +513,7 @@ body: fixture("github", labels_fixture_name), headers: json_header) end + let(:labels_fixture_name) { "labels_with_dependencies.json" } context "when a 'dependencies' label exists" do @@ -530,6 +536,7 @@ context "and label_language is true" do let(:label_language) { true } + it { is_expected.to match_array(%w(dependencies ruby)) } end end @@ -548,15 +555,18 @@ context "when asking for custom labels" do let(:custom_labels) { ["wontfix"] } + it { is_expected.to eq(["wontfix"]) } context "that don't exist" do let(:custom_labels) { ["non-existent"] } + it { is_expected.to eq([]) } end context "when only one doesn't exist" do let(:custom_labels) { %w(wontfix non-existent) } + it { is_expected.to eq(["wontfix"]) } end end @@ -568,6 +578,7 @@ context "for a repo that has an automerge label" do let(:labels_fixture_name) { "labels_with_automerge_tag.json" } + it { is_expected.to include("automerge") } end end @@ -577,6 +588,7 @@ context "for a repo that has an automerge label" do let(:labels_fixture_name) { "labels_with_automerge_tag.json" } + it { is_expected.to_not include("automerge") } end end @@ -593,20 +605,24 @@ context "for a patch release" do let(:version) { "1.4.1" } + it { is_expected.to include("patch") } context "when the tags are for an auto-releasing tool" do let(:labels_fixture_name) { "labels_with_semver_tags_auto.json" } + it { is_expected.to_not include("patch") } end end context "for a patch release with build identifier" do let(:version) { "1.4.1+10" } + it { is_expected.to include("patch") } context "when the tags are for an auto-releasing tool" do let(:labels_fixture_name) { "labels_with_semver_tags_auto.json" } + it { is_expected.to_not include("patch") } end end @@ -614,48 +630,57 @@ context "for a patch release when both have build identifiers" do let(:previous_version) { "1.4.0+10" } let(:version) { "1.4.1+9" } + it { is_expected.to include("patch") } context "when the tags are for an auto-releasing tool" do let(:labels_fixture_name) { "labels_with_semver_tags_auto.json" } + it { is_expected.to_not include("patch") } end end context "for a minor release" do let(:version) { "1.5.1" } + it { is_expected.to include("minor") } end context "for a minor release with build identifier" do let(:version) { "1.5.1+1" } + it { is_expected.to include("minor") } end context "for a minor release when both have build identifiers" do let(:previous_version) { "1.4.0+10" } let(:version) { "1.5.1+1" } + it { is_expected.to include("minor") } end context "for a major release" do let(:version) { "2.5.1" } + it { is_expected.to include("major") } end context "for a major release with build identifier" do let(:version) { "2.5.1+100" } + it { is_expected.to include("major") } end context "for a major release when both have build identifiers" do let(:previous_version) { "1.4.0+10" } let(:version) { "2.5.1+100" } + it { is_expected.to include("major") } end context "for a non-semver release" do let(:version) { "random" } + it { is_expected.to eq(["dependencies"]) } end @@ -697,6 +722,7 @@ context "without a previous version" do let(:previous_version) { nil } + it { is_expected.to eq(["dependencies"]) } end end @@ -735,15 +761,18 @@ context "when asking for custom labels" do let(:custom_labels) { ["critical"] } + it { is_expected.to eq(["critical"]) } context "that don't exist" do let(:custom_labels) { ["non-existent"] } + it { is_expected.to eq(["non-existent"]) } end context "when only one doesn't exist" do let(:custom_labels) { %w(critical non-existent) } + it { is_expected.to eq(%w(critical non-existent)) } end end @@ -756,6 +785,7 @@ let(:repo_api_url) do "https://gitlab.com/api/v4/projects/#{CGI.escape(source.repo)}" end + before do stub_request(:get, "#{repo_api_url}/labels?per_page=100") .to_return(status: 200, @@ -775,6 +805,7 @@ context "for a security fix" do let(:includes_security_fixes) { true } + before do stub_request(:get, "#{repo_api_url}/labels?per_page=100") .to_return(status: 200, @@ -824,15 +855,18 @@ context "when asking for custom labels" do let(:custom_labels) { ["critical"] } + it { is_expected.to eq(["critical"]) } context "that don't exist" do let(:custom_labels) { ["non-existent"] } + it { is_expected.to eq([]) } end context "when only one doesn't exist" do let(:custom_labels) { %w(critical non-existent) } + it { is_expected.to eq(["critical"]) } end end @@ -841,6 +875,7 @@ describe "#label_pull_request" do subject(:label_pr) { labeler.label_pull_request(pull_request_number) } + let(:pull_request_number) { 1 } context "with GitHub details" do @@ -848,6 +883,7 @@ Dependabot::Source.new(provider: "github", repo: "gocardless/bump") end let(:repo_api_url) { "https://api.github.com/repos/#{source.repo}" } + before do stub_request(:post, "#{repo_api_url}/issues/1/labels") .to_return(status: 200, @@ -918,6 +954,7 @@ context "for a security fix" do let(:includes_security_fixes) { true } + before do stub_request(:get, "#{repo_api_url}/labels?per_page=100") .to_return(status: 200, @@ -937,6 +974,7 @@ context "when requesting custom labels that don't exist" do let(:custom_labels) { ["non-existent"] } + before do stub_request(:get, "#{repo_api_url}/labels?per_page=100") .to_return(status: 200, diff --git a/common/spec/dependabot/pull_request_creator/message_builder/issue_linker_spec.rb b/common/spec/dependabot/pull_request_creator/message_builder/issue_linker_spec.rb index 460719ef6b..9824b9f9b4 100644 --- a/common/spec/dependabot/pull_request_creator/message_builder/issue_linker_spec.rb +++ b/common/spec/dependabot/pull_request_creator/message_builder/issue_linker_spec.rb @@ -14,16 +14,19 @@ context "with an absolute link" do let(:text) { "This is just [#12](https://example.com) text" } + it { is_expected.to eq(text) } end context "with a [12] non-link" do let(:text) { "This is not a [19] link" } + it { is_expected.to eq(text) } end context "with just a number" do let(:text) { "This is not a 19 link" } + it { is_expected.to eq(text) } end @@ -66,6 +69,7 @@ context "with an anchored link" do let(:text) { "This is a https://example.com/my/repo#19 link" } + it { is_expected.to eq(text) } end diff --git a/common/spec/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer_spec.rb b/common/spec/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer_spec.rb index f90ed5bc9a..50292778a4 100644 --- a/common/spec/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer_spec.rb +++ b/common/spec/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer_spec.rb @@ -9,6 +9,7 @@ subject(:sanitizer) do described_class.new(github_redirection_service: github_redirection_service) end + let(:github_redirection_service) { "github-redirect.com" } describe "#sanitize_links_and_mentions" do @@ -70,16 +71,19 @@ context "that appears in single tick code quotes" do let(:text) { "Great work `@greysteil`!" } + it { is_expected.to eq("

Great work @greysteil!

\n") } end context "that appears in double tick code quotes" do let(:text) { "Great work ``@greysteil``!" } + it { is_expected.to eq("

Great work @greysteil!

\n") } end context "with unmatched single code ticks previously" do let(:text) { fixture("changelogs", "sentry.md") } + it do is_expected.to include( "@\u200Bhalkeye" @@ -89,12 +93,14 @@ context "that appears in codeblock quotes" do let(:text) { "``` @model ||= 123```" } + it do is_expected.to eq("

@model ||= 123

\n") end context "that use `~`" do let(:text) { "~~~\n @model ||= 123\n~~~" } + it do is_expected.to eq("
 @model ||= 123\n
\n") end @@ -229,16 +235,19 @@ context "with empty text" do let(:text) { "" } + it { is_expected.to eq(text) } end context "with ending newline" do let(:text) { "Changelog 2.0\n" } + it { is_expected.to eq("

Changelog 2.0

\n") } end context "with an email" do let(:text) { "Contact support@dependabot.com for details" } + it do is_expected.to eq( "

Contact " \ @@ -286,6 +295,7 @@ let(:text) do "dsp-testing/dependabot-ts-definitely-typed#25" end + it do is_expected.to eq( "

dsp-testing/dependabot-ts-definitely-typed#25

\n" @@ -357,6 +367,7 @@ context "with HTML tags" do let(:text) { "This contains \"