Skip to content

Commit

Permalink
Merge pull request #3388 from dependabot/feelepxyz/convert-file-prepa…
Browse files Browse the repository at this point in the history
…rer-spec-fixtures

Use project fixtures for FilePreparer
  • Loading branch information
feelepxyz committed Mar 29, 2021
2 parents c17f2bb + 2a1278c commit afc44cd
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 36 deletions.
45 changes: 9 additions & 36 deletions bundler/spec/dependabot/bundler/file_parser/file_preparer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,30 @@
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
subject do
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
subject do
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")) }
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "business", "~> 1.4.0"
gem "statesman", "~> 1.2.0"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
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

0 comments on commit afc44cd

Please sign in to comment.