Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundler/DuplicatedGem does not recognize if statements and the like #3752

Closed
edestecd opened this issue Nov 30, 2016 · 8 comments
Closed

Bundler/DuplicatedGem does not recognize if statements and the like #3752

edestecd opened this issue Nov 30, 2016 · 8 comments

Comments

@edestecd
Copy link

This fails and should not:

  if RUBY_VERSION < '2.2.5'
    # beaker 3.1+ requires ruby 2.2.5.  Lock to 2.0
    gem 'beaker', '~> 2.0', :require => false
    # beaker-rspec 6.0.0 requires beaker 3.0. Lock to 5.0
    gem 'beaker-rspec', '~> 5.0', :require => false
  else
    gem 'beaker-rspec', :require => false
  end
@backus
Copy link
Contributor

backus commented Dec 18, 2016

This is an interesting issue since it seems like bundler doesn't want you to specify different dependency versions depending on the ruby version. Bundler has a construct built in for specifying dependencies depending on the ruby version and if you try to convert your example to their platforms construct then you get an error

source 'https://rubygems.org'

gem 'beaker-rspec', '~> 5.0', require: false, platforms: :ruby_22
gem 'beaker-rspec', require: false, platforms: :ruby_23
$ bundle install
[!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.
You specified: beaker-rspec (~> 5.0) and beaker-rspec (>= 0). Bundler cannot continue.

 #  from Gemfile:4
 #  -------------------------------------------
 #  gem 'beaker-rspec', '~> 5.0', require: false, platforms: :ruby_22
 >  gem 'beaker-rspec', require: false, platforms: :ruby_23
 #  -------------------------------------------

@mvz
Copy link
Contributor

mvz commented Jan 17, 2017

Note that for this particular case, you shouldn't need the if when using Bundler 1.13.x. You can instead tell Bundler to respect the gems' ruby version requirements like so:

ruby RUBY_VERSION

gem 'beaker-rspec', :require => false

@edestecd
Copy link
Author

What if you need to run your Gemfile against multiple ruby versions.
Our app (puppet) supports many versions of ruby and we want travis ci to test all of them.

@edestecd
Copy link
Author

@mvz From what I understand of the ruby keyword in bundler, it just fails if ruby is not at the specified version. We need a Gemfile that works for multiple versions of ruby ;) Can that be done without an if?

@edestecd
Copy link
Author

@edestecd
Copy link
Author

Hmm, Maybe the ruby version can be an ENV var? Seems like the gem knows what version of ruby it needs and bundler can satisfy this?
https://github.com/puppetlabs/beaker-rspec/blob/master/beaker-rspec.gemspec#L15

I'll mess around with setting the ruby version and see if it works out...

@mvz
Copy link
Contributor

mvz commented Jan 18, 2017

From what I understand of the ruby keyword in bundler, it just fails if ruby is not at the specified version.

Yes, but because you set it to RUBY_VERSION, ruby is actually automatically at the specified version. As a side effect, Bundler is triggered to ignore all other ruby versions and can therefore use the gems' ruby version requirements.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 19, 2018

There hasn't been much activity on this ticket and our Core Team is spread too thin on so many tasks, so I'll just close it for the sake of having a cleaner lists of tasks to focus on. We'd gladly review a PR, but it's unlikely that'd we're going to tackle this ourselves in the foreseeable future.

@bbatsov bbatsov closed this as completed Sep 19, 2018
lamont-granquist added a commit to chef/chefstyle that referenced this issue Apr 30, 2019
rubocop/rubocop#4432 and rubocop/rubocop#3752 have been closed
against this cop which make it pretty annoying with false positives.

since this is a lint that complains against a hard-error from bundler
there really isn't a lot of point to this.  throwing a style error
to prevent a syntax error, where the linter will necessarily be
inaccurate due to static analysis is not adding value.
lamont-granquist added a commit to chef/chefstyle that referenced this issue Apr 30, 2019
rubocop/rubocop#4432 and rubocop/rubocop#3752 have been closed
against this cop which make it pretty annoying with false positives.

since this is a lint that complains against a hard-error from bundler
there really isn't a lot of point to this.  throwing a style error
to prevent a syntax error, where the linter will necessarily be
inaccurate due to static analysis is not adding value.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
tomnatt added a commit to tomnatt/puppet-multitemplate that referenced this issue Jul 21, 2020
Since rubocop does not honour if/else blocks. As per:
rubocop/rubocop#3752
cegeka-jenkins pushed a commit to cegeka/puppet-multitemplate that referenced this issue Jun 29, 2023
Since rubocop does not honour if/else blocks. As per:
rubocop/rubocop#3752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants