From c5240aaa4cb8c78d5ad9d89a62d18fa7ffe2d071 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Fri, 26 Mar 2021 19:39:05 +0000 Subject: [PATCH] Use project fixtures for GemspecFinder spec --- .../file_fetcher/gemspec_finder_spec.rb | 21 +++++++----------- .../nested/Gemfile | 7 ++++++ .../nested/Gemfile.lock | 22 +++++++++++++++++++ .../nested/subdir/example.gemspec | 21 ++++++++++++++++++ 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile create mode 100644 bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile.lock create mode 100644 bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/subdir/example.gemspec 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 97948e80dd..8e440c4dc5 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher/gemspec_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher/gemspec_finder_spec.rb @@ -8,22 +8,16 @@ RSpec.describe Dependabot::Bundler::FileFetcher::GemspecFinder 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") } - describe "#gemspec_directories" do subject(:gemspec_directories) { finder.gemspec_directories } context "when the file does not include any gemspecs" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "Gemfile") } + let(:gemfile) { bundler_project_dependency_file("gemfile", filename: "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.gemspec_directories }.to raise_error do |error| @@ -34,18 +28,19 @@ end context "when the file does include a gemspec reference" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "imports_gemspec") } + let(:gemfile) { bundler_project_dependency_file("imports_gemspec", filename: "Gemfile") } it { is_expected.to eq([Pathname.new(".")]) } context "that has a path specified" do - let(:gemfile_body) do - fixture("ruby", "gemfiles", "imports_gemspec_from_path") - end + let(:gemfile) { bundler_project_dependency_file("imports_gemspec_from_path", filename: "Gemfile") } it { is_expected.to eq([Pathname.new("subdir")]) } context "when this Gemfile is already in a nested directory" do - let(:gemfile_name) { "nested/Gemfile" } + let(:gemfile) do + bundler_project_dependency_file("imports_gemspec_from_nested_path", filename: "nested/Gemfile") + end + it { is_expected.to eq([Pathname.new("nested/subdir")]) } end end diff --git a/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile b/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile new file mode 100644 index 0000000000..c735e46b5d --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gemspec path: 'subdir' + +gem "business", "~> 1.4.0" +gem "statesman", "~> 1.2.0" diff --git a/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile.lock b/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile.lock new file mode 100644 index 0000000000..17163f0142 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/Gemfile.lock @@ -0,0 +1,22 @@ +PATH + remote: subdir + specs: + example (0.9.3) + business (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + business (1.4.0) + statesman (1.2.5) + +PLATFORMS + ruby + +DEPENDENCIES + business (~> 1.4.0) + example! + statesman (~> 1.2.0) + +BUNDLED WITH + 1.15.3 diff --git a/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/subdir/example.gemspec b/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/subdir/example.gemspec new file mode 100644 index 0000000000..f1d7674d9f --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/imports_gemspec_from_nested_path/nested/subdir/example.gemspec @@ -0,0 +1,21 @@ +# 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.author = "Dependabot" + spec.email = "support@dependabot.com" + spec.homepage = "https://github.com/hmarr/example" + spec.license = "MIT" + + spec.require_path = "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_dependency 'business', '~> 1.0' +end