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 17444a5441..b3b28f06f5 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 @@ -8,28 +8,22 @@ RSpec.describe Dependabot::Bundler::FileFetcher::ChildGemfileFinder 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 "#child_gemfile_paths" do subject(:child_gemfile_paths) { finder.child_gemfile_paths } context "when the file does not include any child Gemfiles" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "Gemfile") } + 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_body) { fixture("ruby", "gemfiles", "eval_gemfile") } + let(:gemfile) { bundler_project_dependency_file("eval_gemfile_gemfile", filename: "Gemfile") } it { is_expected.to eq(["backend/Gemfile"]) } context "whose path must be eval-ed" do - let(:gemfile_body) do - fixture("ruby", "gemfiles", "eval_gemfile_absolute") - end + let(:gemfile) { bundler_project_dependency_file("eval_gemfile_absolute", filename: "Gemfile") } it "raises a helpful error" do expect { finder.child_gemfile_paths }.to raise_error do |error| @@ -40,9 +34,7 @@ end context "that includes a variable" do - let(:gemfile_body) do - fixture("ruby", "gemfiles", "eval_gemfile_variable") - end + let(:gemfile) { bundler_project_dependency_file("eval_gemfile_variable", filename: "Gemfile") } it "raises a helpful error" do expect { finder.child_gemfile_paths }.to raise_error do |error| @@ -56,11 +48,16 @@ let(:gemfile_body) do "group :development do\neval_gemfile('some_gemfile')\nend" end + + let(:gemfile) do + Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") + end + it { is_expected.to eq(["some_gemfile"]) } 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.child_gemfile_paths }.to raise_error do |error| @@ -71,8 +68,7 @@ end context "when this Gemfile is already in a nested directory" do - let(:gemfile_body) { fixture("ruby", "gemfiles", "eval_gemfile") } - let(:gemfile_name) { "nested/Gemfile" } + let(:gemfile) { bundler_project_dependency_file("eval_gemfile_nested", filename: "nested/Gemfile") } it { is_expected.to eq(["nested/backend/Gemfile"]) } end diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/Gemfile b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/Gemfile new file mode 100644 index 0000000000..e08aed36a1 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +eval_gemfile File.expand_path('backend/Gemfile', File.dirname(__FILE__)) + +gem "business", "~> 1.4.0" diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/Gemfile.lock b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/Gemfile.lock new file mode 100644 index 0000000000..65d23b6c74 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + business (1.4.0) + statesman (1.2.1) + +PLATFORMS + ruby + +DEPENDENCIES + business (~> 1.4.0) + statesman (~> 1.2.0) + +BUNDLED WITH + 1.10.6 diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/backend/Gemfile b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/backend/Gemfile new file mode 100644 index 0000000000..be0f45dc3a --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_absolute/backend/Gemfile @@ -0,0 +1,4 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gem "statesman", "~> 1.2.0" diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/Gemfile b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/Gemfile new file mode 100644 index 0000000000..5febdf9583 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +eval_gemfile('backend/Gemfile') + +gem "business", "~> 1.4.0" diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/Gemfile.lock b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/Gemfile.lock new file mode 100644 index 0000000000..65d23b6c74 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + business (1.4.0) + statesman (1.2.1) + +PLATFORMS + ruby + +DEPENDENCIES + business (~> 1.4.0) + statesman (~> 1.2.0) + +BUNDLED WITH + 1.10.6 diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/backend/Gemfile b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/backend/Gemfile new file mode 100644 index 0000000000..be0f45dc3a --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_nested/nested/backend/Gemfile @@ -0,0 +1,4 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gem "statesman", "~> 1.2.0" diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/Gemfile b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/Gemfile new file mode 100644 index 0000000000..25064841bb --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +local_gemfile = File.dirname(__FILE__), 'backend/Gemfile' +eval_gemfile File.join(local_gemfile) + +gem "business", "~> 1.4.0" diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/Gemfile.lock b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/Gemfile.lock new file mode 100644 index 0000000000..65d23b6c74 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + business (1.4.0) + statesman (1.2.1) + +PLATFORMS + ruby + +DEPENDENCIES + business (~> 1.4.0) + statesman (~> 1.2.0) + +BUNDLED WITH + 1.10.6 diff --git a/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/backend/Gemfile b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/backend/Gemfile new file mode 100644 index 0000000000..be0f45dc3a --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/eval_gemfile_variable/backend/Gemfile @@ -0,0 +1,4 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gem "statesman", "~> 1.2.0" diff --git a/bundler/spec/fixtures/projects/bundler1/invalid_ruby/Gemfile b/bundler/spec/fixtures/projects/bundler1/invalid_ruby/Gemfile new file mode 100644 index 0000000000..759c9ed2e5 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/invalid_ruby/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' do + ruby -rubygems -e 'require "jekyll-import"; + end