Skip to content

Commit

Permalink
Merge pull request #708 from mvz/fix-git-repo-gem-handling
Browse files Browse the repository at this point in the history
Do not set Bundle path. Bundler will figure it out.
  • Loading branch information
xtreme-shane-lattanzio committed Apr 20, 2020
2 parents 36b99db + 6319a7a commit 5ca798d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
16 changes: 16 additions & 0 deletions features/features/package_managers/bundler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@
bundler_developer.run_license_finder
expect(bundler_developer).to be_seeing_something_like /rake.*MIT/
end

specify 'works with git dependency running outside of the bundle' do
# Run license_finder outside any Bundler environment
::Bundler.with_unbundled_env do
# Fake home to avoid polluting real home with git checkout
ENV['HOME'] = LicenseFinder::TestingDSL::Paths.projects.to_s
# Make running license_finder pick up the correct implementation
ENV['RUBYOPT'] = "-I#{LicenseFinder::TestingDSL::Paths.root}/lib"
# Allow the main executable to be found
ENV['PATH'] = "#{LicenseFinder::TestingDSL::Paths.root}/bin:#{ENV['PATH']}"
LicenseFinder::TestingDSL::GitBundlerProject.create
puts 'bundler project created'
bundler_developer.run_license_finder
expect(bundler_developer).to be_seeing_something_like /bundler.*MIT/
end
end
end
23 changes: 23 additions & 0 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,29 @@ def add_to_gemfile(content)
end
end

class GitBundlerProject < Project
def add_dep
add_to_gemfile("source 'https://rubygems.org'")
add_to_gemfile("gem 'license_finder', git: #{Paths.root.to_s.inspect}")
end

def install
::Bundler.with_original_env do
shell_out('bundle install')
end
end

private

def add_gem_to_gemfile(gem_name, options)
add_to_gemfile("gem #{gem_name.inspect}, #{options.inspect}")
end

def add_to_gemfile(content)
add_to_file('Gemfile', content)
end
end

# lives adjacent to a BundlerProject, so has a different lifecycle from other Projects and doesn't inherit
class GemProject
def self.create(name, options)
Expand Down
2 changes: 0 additions & 2 deletions lib/license_finder/package_managers/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def possible_package_paths
attr_reader :ignored_groups

def definition
# DI
ENV['BUNDLE_PATH'] = project_path.to_s
ENV['BUNDLE_GEMFILE'] = "#{project_path}/#{gemfile}"

@definition ||= ::Bundler::Definition.build(detected_package_path, lockfile_path, nil)
Expand Down

0 comments on commit 5ca798d

Please sign in to comment.