From 4c91008a24f26d26fa36191b20c7ccd4e014033e Mon Sep 17 00:00:00 2001 From: Philip Harrison Date: Mon, 29 Mar 2021 12:57:30 +0100 Subject: [PATCH] Use project fixtures for PathGemspecFinder --- .../file_fetcher/path_gemspec_finder_spec.rb | 19 +++++------ .../nested_path_source/nested/Gemfile | 6 ++++ .../nested_path_source/nested/Gemfile.lock | 30 ++++++++++++++++ .../nested/example/example.gemspec | 34 +++++++++++++++++++ .../bundler1/path_source_eval/Gemfile | 6 ++++ .../projects/bundler1/path_source_if/Gemfile | 11 ++++++ 6 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile create mode 100644 bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile.lock create mode 100644 bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/example/example.gemspec create mode 100644 bundler/spec/fixtures/projects/bundler1/path_source_eval/Gemfile create mode 100644 bundler/spec/fixtures/projects/bundler1/path_source_if/Gemfile 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 7ddea9ad0d0..baa691fa93d 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 @@ -8,22 +8,17 @@ RSpec.describe Dependabot::Bundler::FileFetcher::PathGemspecFinder do let(:finder) { described_class.new(gemfile: gemfile) } - let(:gemfile) do - Dependabot::DependencyFile.new(content: gemfile_body, name: gemfile_name) - end - let(:gemfile_name) { "Gemfile" } - let(:gemfile_body) { fixture("ruby", "gemfiles", "Gemfile") } + let(:gemfile) { bundler_project_dependency_file("gemfile", filename: "Gemfile") } describe "#path_gemspec_paths" do subject(:path_gemspec_paths) { finder.path_gemspec_paths } context "when the file does not include any path gemspecs" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "Gemfile") } it { is_expected.to eq([]) } end context "with invalid Ruby in the Gemfile" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "invalid_ruby") } + let(:gemfile) { bundler_project_dependency_file("invalid_ruby", filename: "Gemfile") } it "raises a helpful error" do expect { finder.path_gemspec_paths }.to raise_error do |error| @@ -34,11 +29,11 @@ end context "when the file does include a path gemspec" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "path_source") } + let(:gemfile) { bundler_project_dependency_file("path_source", filename: "Gemfile") } it { is_expected.to eq([Pathname.new("plugins/example")]) } context "whose path must be eval-ed" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "path_source_eval") } + let(:gemfile) { bundler_project_dependency_file("path_source_eval", filename: "Gemfile") } it "raises a helpful error" do expect { finder.path_gemspec_paths }.to raise_error do |error| @@ -49,13 +44,15 @@ end context "when this Gemfile is already in a nested directory" do - let(:gemfile_name) { "nested/Gemfile" } + let(:gemfile) do + bundler_project_dependency_file("nested_path_source", filename: "nested/Gemfile") + end it { is_expected.to eq([Pathname.new("nested/plugins/example")]) } end context "that is behind a conditional that is false" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "path_source_if") } + 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/fixtures/projects/bundler1/nested_path_source/nested/Gemfile b/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile new file mode 100644 index 00000000000..b2d90817699 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem "business", "~> 1.4.0" +gem "statesman", "~> 1.2.0" +gem "example", ">= 0.9.0", path: "plugins/example" +gem "prius", git: "https://github.com/gocardless/prius" diff --git a/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile.lock b/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile.lock new file mode 100644 index 00000000000..6803a685e5c --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/Gemfile.lock @@ -0,0 +1,30 @@ +GIT + remote: https://github.com/gocardless/prius + revision: cff701b3bfb182afc99a85657d7c9f3d6c1ccce2 + specs: + prius (1.0.0) + +PATH + remote: plugins/example + specs: + example (0.9.3) + i18n (>= 0.3.3) + +GEM + remote: https://rubygems.org/ + specs: + business (1.4.0) + i18n (0.8.4) + statesman (1.2.5) + +PLATFORMS + ruby + +DEPENDENCIES + business (~> 1.4.0) + example (>= 0.9.0)! + prius! + statesman (~> 1.2.0) + +BUNDLED WITH + 1.15.1 diff --git a/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/example/example.gemspec b/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/example/example.gemspec new file mode 100644 index 00000000000..a39e98a0f46 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/nested_path_source/nested/example/example.gemspec @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +Gem::Specification.new do |spec| + spec.name = "example" + spec.version = "0.9.3" + spec.summary = "Automated dependency management" + spec.description = "Core logic for updating a GitHub repos dependencies" + spec.date = "2019-08-01" + + spec.author = "Dependabot" + spec.email = "support@dependabot.com" + spec.homepage = "https://github.com/hmarr/example" + spec.license = "MIT" + + spec.require_path = Dir["lib"] + spec.files = Dir["CHANGELOG.md", "LICENSE.txt", "README.md", + "lib/**/*", "helpers/**/*"] + + spec.required_ruby_version = ">= 2.4.0" + spec.required_rubygems_version = ">= 2.6.11" + + spec.add_runtime_dependency "bundler", ">= 1.12.0" + spec.add_dependency "excon", ["~> 0.55"] + spec.add_dependency("gemnasium-parser", "~> 0.1") + spec.add_dependency "gems", "~> 1.0" + spec.add_dependency "gitlab", "~> 4.1" + spec.add_dependency "octokit", "~> 4.6" + + spec.add_development_dependency "rake" + spec.add_development_dependency "rspec", "~> 3.5.0" + spec.add_development_dependency "rspec-its", "~> 1.2.0" + spec.add_development_dependency "rubocop", "~> 0.48.0" + spec.add_development_dependency "webmock", "~> 2.3.1" +end diff --git a/bundler/spec/fixtures/projects/bundler1/path_source_eval/Gemfile b/bundler/spec/fixtures/projects/bundler1/path_source_eval/Gemfile new file mode 100644 index 00000000000..2cda2d90d6b --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/path_source_eval/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem "business", "~> 1.4.0" +gem "statesman", "~> 1.2.0" +gem "example", path: File.join(File.dirname(__FILE__), 'plugins/example') +gem "prius", git: "https://github.com/gocardless/prius" diff --git a/bundler/spec/fixtures/projects/bundler1/path_source_if/Gemfile b/bundler/spec/fixtures/projects/bundler1/path_source_if/Gemfile new file mode 100644 index 00000000000..cee9a2c981a --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/path_source_if/Gemfile @@ -0,0 +1,11 @@ +source "https://rubygems.org" + +if ENV['something'] + gem "example", path: "plugins/example" +else + gem "example" +end + +gem "statesman", "~> 1.2.0" +gem "business", "~> 1.4.0" +gem "prius", git: "https://github.com/gocardless/prius"