Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use project fixtures for PathGemspecFinder #3386

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions bundler/spec/fixtures/projects/bundler1/path_source_if/Gemfile
Original file line number Diff line number Diff line change
@@ -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"