Skip to content

Commit

Permalink
Use #is_a_path? conditionally on Bundler version (#19)
Browse files Browse the repository at this point in the history
* Use #is_a_path? conditionally on Bundler version

* Use Bundler::VERSION

* Update setting Bundler to frozen with #set_local

* Force travis to install with correct Bundler version

* Resolve rubocop offenses

* Verify bundler version is not greater than 1.14.0 in travis

* Print the version

* Override install properly

* Overwrite script as well

* Force uninstall of bundler as suggestion in link

https://stackoverflow.com/questions/26481650/travis-could-not-find-bundler-1-7-4

* try moving it to before_install

* Try another tactic found on this travis-ci issue

travis-ci/travis-ci#8717 (comment)

* Turn condition in Gemfile into Bundler version log

* Create build matrix with multiple Ruby & Bundler versions

* Remove logging that creates test failures

* Fix wrong bundler version

* Add 2 more Bundler versions

* Use matrix of 1 Ruby & 2 Bundler versions

* Use Gem::Version to compare Bundler versions

* Use #respond_to? instead of looking at Bundler

* Remove duplication from #path?
  • Loading branch information
garettarrowood committed Aug 15, 2018
1 parent c09e175 commit 81014fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
sudo: true
language: ruby
rvm:
- 2.3.1
before_install:
- gem install bundler -v 1.13.6
- "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
- gem install bundler:"$BUNDLER_VERSION"
- sudo apt-get -qq install graphviz
rvm:
- 2.5.1
env:
- BUNDLER_VERSION=1.15.4
- BUNDLER_VERSION=1.16.3
10 changes: 7 additions & 3 deletions lib/cobra_commander/component_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ def initialize(root_path)
def dependencies
@deps ||= begin
return [] unless gem?
gems = bundler_definition.dependencies.select do |dep|
dep.source&.is_a_path? && dep.source.path.to_s != "."
end
gems = bundler_definition.dependencies.select { |dep| path?(dep.source) }
format(gems)
end
end

def path?(source)
return if source.nil?
source_has_path = source.respond_to?(:path?) ? source.path? : source.is_a_path?
source_has_path && source.path.to_s != "."
end

def format(deps)
deps.map do |dep|
path = File.join(dep.source.path, dep.name)
Expand Down
13 changes: 7 additions & 6 deletions spec/cobra_commander/component_tree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
end

describe "when bundle is frozen" do
# When the application bundle is locked, Bundler represents a components' self-dependency
# (triggered by `gemspec` in its Gemfile) as a Bundler::Source::Path, rather than a
# Bundler::Source::Gemspec. This can be confused with a dependency on another component.
# When the application bundle is locked, Bundler represents a components'
# self-dependency (triggered by `gemspec` in its Gemfile) as a
# Bundler::Source::Path, rather than a Bundler::Source::Gemspec.
# This can be confused with a dependency on another component.
before do
@original = Bundler.settings[:frozen]
Bundler.settings[:frozen] = true
@original = Bundler.settings.frozen?
Bundler.settings.set_local(:frozen, true)
end

it "#component_dependencies still accurately selects" do
expect(subject.to_h).to eql(AppHelper.tree)
end

after do
Bundler.settings[:frozen] = @original
Bundler.settings.set_local(:frozen, @original)
end
end
end
Expand Down

0 comments on commit 81014fa

Please sign in to comment.