diff --git a/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb b/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb index ab68ba11ade..56509a7204c 100644 --- a/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb +++ b/bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb @@ -7,23 +7,14 @@ RSpec.describe Dependabot::Bundler::FileParser::FilePreparer do let(:preparer) { described_class.new(dependency_files: dependency_files) } - let(:dependency_files) { [gemfile, lockfile] } - - let(:gemfile) do - Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile") - end - let(:lockfile) do - Dependabot::DependencyFile.new(content: lockfile_body, name: "Gemfile.lock") - end - let(:gemfile_body) { fixture("ruby", "gemfiles", "Gemfile") } - let(:lockfile_body) { fixture("ruby", "lockfiles", "Gemfile.lock") } + let(:dependency_files) { bundler_project_dependency_files("gemfile") } describe "#prepared_dependency_files" do subject(:prepared_dependency_files) { preparer.prepared_dependency_files } describe "the updated Gemfile" do subject { prepared_dependency_files.find { |f| f.name == "Gemfile" } } - its(:content) { is_expected.to eq(gemfile.content) } + its(:content) { is_expected.to include('gem "business", "~> 1.4.0"') } end describe "the updated lockfile" do @@ -31,7 +22,7 @@ prepared_dependency_files.find { |f| f.name == "Gemfile.lock" } end - its(:content) { is_expected.to eq(lockfile.content) } + its(:content) { is_expected.to include("1.10.6") } end describe "the updated gemspec" do @@ -39,13 +30,7 @@ prepared_dependency_files.find { |f| f.name == "example.gemspec" } end - let(:dependency_files) { [gemfile, lockfile, gemspec] } - let(:gemspec) do - Dependabot::DependencyFile.new( - content: fixture("ruby", "gemspecs", "with_require"), - name: "example.gemspec" - ) - end + let(:dependency_files) { bundler_project_dependency_files("gemfile_gemspec_with_require") } its(:content) { is_expected.to include("begin\nrequire ") } its(:content) { is_expected.to include(%(version = "0.0.1")) } @@ -56,31 +41,19 @@ prepared_dependency_files.find { |f| f.name == ".ruby-version" } end - let(:dependency_files) { [gemfile, lockfile, ruby_version] } - let(:ruby_version) do - Dependabot::DependencyFile.new( - content: "2.4.1", - name: ".ruby-version" - ) - end + let(:dependency_files) { bundler_project_dependency_files("ruby_version_file") } - its(:content) { is_expected.to eq(ruby_version.content) } + its(:content) { is_expected.to eq("2.2.0\n") } end describe "the updated .specification file" do subject do - prepared_dependency_files.find { |f| f.name == ".specification" } + prepared_dependency_files.find { |f| f.name == "plugins/example/.specification" } end - let(:dependency_files) { [gemfile, lockfile, specification] } - let(:specification) do - Dependabot::DependencyFile.new( - content: fixture("ruby", "specifications", "statesman"), - name: ".specification" - ) - end + let(:dependency_files) { bundler_project_dependency_files("version_specified_gemfile_specification") } - its(:content) { is_expected.to eq(specification.content) } + its(:content) { is_expected.to start_with("--- !ruby/object:Gem::Specification") } end end end diff --git a/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/Gemfile b/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/Gemfile new file mode 100644 index 00000000000..bb897e7e7bb --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "business", "~> 1.4.0" +gem "statesman", "~> 1.2.0" diff --git a/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/Gemfile.lock b/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/Gemfile.lock new file mode 100644 index 00000000000..65d23b6c746 --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/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/gemfile_gemspec_with_require/example.gemspec b/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/example.gemspec new file mode 100644 index 00000000000..da77199c39d --- /dev/null +++ b/bundler/spec/fixtures/projects/bundler1/gemfile_gemspec_with_require/example.gemspec @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'example/version' + +Gem::Specification.new do |spec| + spec.name = "example" + spec.version = Example::VERSION + spec.summary = "Automated dependency management #{Example::VERSION}" + 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/**/*"] + Find.find("lib", "helpers") do |path| + if ignores.any? { |i| File.fnmatch(i, "/" + path, File::FNM_DOTMATCH) } + Find.prune + else + spec.files << path unless File.directory?(path) + end + end + + spec.required_ruby_version = ">= 2.4.0" + spec.required_rubygems_version = ">= 2.6.11" + + spec.add_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 "octokit", "~> 4.6" + spec.add_dependency "gitlab", "~> 4.1" + + spec.add_development_dependency "webmock", "~> 2.3.1" + 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 "rake" +end