Skip to content

Commit

Permalink
Merge pull request #3374 from dependabot/brrygrdn/gemfile-declaration…
Browse files Browse the repository at this point in the history
…-finder-proj-fixtures

Convert the spec for Bundler::FileParser::GemfileDeclarationFinder to use project based fixtures.
  • Loading branch information
feelepxyz authored Mar 29, 2021
2 parents c0dbc99 + 3e6875c commit e7c1929
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
let(:dependency_name) { "business" }
let(:dependency_requirement_sting) { "~> 1" }

let(:gemfile) do
Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile")
end
let(:gemfile_body) { fixture("ruby", "gemfiles", "Gemfile") }
let(:gemfile) { bundler_project_dependency_file("gemfile", filename: "Gemfile") }

describe "#gemfile_includes_dependency?" do
subject(:gemfile_includes_dependency) do
Expand All @@ -37,7 +34,9 @@
end

context "when the file is just comments" do
let(:gemfile_body) { "#Lol this is just a comment" }
let(:gemfile) do
Dependabot::DependencyFile.new(content: "#Lol this is just a comment", name: "Gemfile")
end
it { is_expected.to eq(false) }
end

Expand All @@ -46,16 +45,14 @@
it { is_expected.to eq(true) }

context "but it's in a source block" do
let(:gemfile_body) { fixture("ruby", "gemfiles", "sidekiq_pro") }
let(:gemfile) { bundler_project_dependency_file("sidekiq_pro", filename: "Gemfile") }
let(:dependency_name) { "sidekiq-pro" }

it { is_expected.to eq(true) }
end

context "but it's in a group block" do
let(:gemfile_body) do
fixture("ruby", "gemfiles", "development_dependencies")
end
let(:gemfile) { bundler_project_dependency_file("development_dependencies", filename: "Gemfile") }
let(:dependency_name) { "business" }

it { is_expected.to eq(true) }
Expand All @@ -72,7 +69,10 @@
end

context "when the file is just comments" do
let(:gemfile_body) { "#Lol this is just a comment" }
let(:gemfile) do
Dependabot::DependencyFile.new(content: "#Lol this is just a comment", name: "Gemfile")
end

it { is_expected.to be_nil }
end

Expand All @@ -82,9 +82,7 @@
it { is_expected.to eq("~> 1.4.0") }

context "but doesn't specify a requirement" do
let(:gemfile_body) do
fixture("ruby", "gemfiles", "version_not_specified")
end
let(:gemfile) { bundler_project_dependency_file("version_not_specified", filename: "Gemfile") }
let(:dependency_requirement_sting) { nil }

# NOTE: It would be equally valid to return `nil` here
Expand All @@ -102,9 +100,7 @@
end

context "but it's using a version that would be transformed" do
let(:gemfile_body) do
fixture("ruby", "gemfiles", "prerelease_with_dash")
end
let(:gemfile) { bundler_project_dependency_file("prerelease_with_dash_gemfile", filename: "Gemfile") }
let(:dependency_name) { "business" }
let(:dependency_requirement_sting) { "~> 1.4.0.pre.rc1" }

Expand All @@ -117,7 +113,7 @@
end

context "but it's using a function version" do
let(:gemfile_body) { fixture("ruby", "gemfiles", "function_version") }
let(:gemfile) { bundler_project_dependency_file("function_version_gemfile", filename: "Gemfile") }
let(:dependency_name) { "business" }
let(:dependency_requirement_sting) { "~> 1.0.0" }

Expand Down
8 changes: 8 additions & 0 deletions bundler/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def bundler_project_dependency_files(project)
project_dependency_files(File.join("bundler1", project))
end

def bundler_project_dependency_file(project, filename:)
dependency_file = bundler_project_dependency_files(project).find { |file| file.name == filename }

raise "Dependency File '#{filename} does not exist for project '#{project}'" unless dependency_file

dependency_file
end

RSpec.configure do |config|
config.around do |example|
if bundler_2_available? && example.metadata[:bundler_v1_only]
Expand Down

0 comments on commit e7c1929

Please sign in to comment.