How to remove warning "RubyZip 3.0 is coming!" - ruby-on-rails

I just did a bundle update on my Rails 6 app, and since I have a long warning every time I bundle exec something :
RubyZip 3.0 is coming!
**********************
The public API of some Rubyzip classes has been modernized to use named
parameters for optional arguments. Please check your usage of the
following classes:
* `Zip::File`
* `Zip::Entry`
* `Zip::InputStream`
* `Zip::OutputStream`
Please ensure that your Gemfiles and .gemspecs are suitably restrictive
to avoid an unexpected breakage when 3.0 is released (e.g. ~> 2.3.0).
See https://github.com/rubyzip/rubyzip for details. The Changelog also
lists other enhancements and bugfixes that have been implemented since
version 2.3.0.
I don't have rubyzip in my Gemfile, it's a dependancy of webdrivers and selenium-webdriver, libraries used to get a headless browser for Capybara testing.
What can I do to get rid of this warning ?

This warning was added in rubyzip 2.3.1 to give people time to get ready for the 3.0 release which will have breaking changes. If you don't want to see the warning just lock the rubyzip version to 2.3.0 in the development/test section of your Gemfile
gem 'rubyzip', '2.3.0'

Related

Why does my rest-client request raise an error?

I am getting the following error when I make a rest-client request:
<internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require': D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types/logger.rb:28: _1 is reserved for numbered parameter (SyntaxError)
Here is my code:
require 'rest-client'
response = RestClient.get 'https://www.linkedin.com/feed/'
puts response
Can anyone solve this one in return thanks for appreciation?
You are having a gem versioning issue. The error you are getting when you require rest-client is:
.../mime-types-3.1/.../logger.rb:28: _1 is reserved for numbered parameter (SyntaxError)
This is a problem in the gem mime-types, which rest-client depends on. Ruby introduced a change in syntax to support 'numbered parameters' in blocks that made _1, _2, ... reserved words. That change meant that people who had named variables matching that style (_1, _2, etc.) got a warning in Ruby 2.7. In Ruby 3.0 (which you are using), that now causes a syntax error.
The version of mime-types you are using (3.1) must have had code of that kind; it worked prior to Ruby 3.0, but now breaks. The good news is that the latest version of mine-types, 3.3.1, works with Ruby 3. You just need to update your gem:
D:> gem update mime-types
Updating installed gems
Updating mime-types
Fetching mime-types-3.3.1.gem
Successfully installed mime-types-3.3.1
If you are using bundler, you might need to change the version in your Gemfile and re-rerun bundle install to trigger the update.
For every require load error execute the below command to install gems for ruby programs.
ruby -S gem install <gem-name>
in my case it is.
ruby -S gem install rest-client

Rails not using modified gem instead of original

this is what I believe a simple problem I need help with. I'm trying to modify a gem's method so that I can add another argument to it. For this, I've cloned the gem's repo to a local directory and changed the code I needed. Inside my app's Gemfile I'm doing this:
gem 'recommendable', path: "/home/aristizabal95/forked_gems/recommendable"
And running bundle install afterwards. Even though the bundler says it's using my code, when I run the tests I get this error:
ArgumentError: wrong number of arguments (given 4, expected 1..3)
from /var/lib/gems/2.3.0/gems/recommendable-2.2.0/lib/recommendable/rater/recommender.rb:21:in `recommended_for'
which indicates that the app is not running my version of the gem, but the original one. I have no idea why it's not working, and was unable to find any issue related to this.
Thanks in advance
EDIT:
This is what the Gemfile.lock looks like
PATH
remote: /home/aristizabal95/forked_gems/recommendable
specs:
recommendable (2.2.1)
activesupport (>= 3.0.0)
hooks (>= 0.2.1)
redis (>= 2.2.0)
GEM
recommendable!
My guess is that spring still has the gem from the original gem source loaded.
To force spring to reload the gem (from your local source), do:
spring stop
in the console. Then restart your server and you should be using the gem from your local source.

Ruby \ Rubygems how do they decide which gems to load?

This is more curiosity question and not a problem. When many version are present on the system which ones are chosen when require command is used? Background of the story is: I was implementing bundler gem in project (not Rails project). I had no issues but other developers had issues, after quick investigation I realized that I did not use
require "bundler/setup"
which basically loads up bundled gems. Quick fix, but it got me wondering how does ruby via rubygems decide which gems to use. Since code broke because Ruby application used older version of one of the gems, and not the newer one. Meaning it does not use the "newest" gems, so what is logic behind it?
UPDATE
To further explain this question let say you have gems foo-1.0.1 and foo-1.0.2 when you say, require 'foo' how does ruby know which one to load?
In Ruby you require a file rather than a gem. If that file isn’t found on the current load path, Rubygems will search the installed gems for a file with that name, and if it finds one the gem is activated (meaning that it gets added to the laod path) and the file is then required. Normally a gem will have a file with the same name in its lib dir. Only one version of a gem can be activated.
The gem that gets activated is the latest version available that is compatible with any other activated gems. Normally this will just mean that the latest version installed wil be activated, but this might not be the case if you have already activated some gems which declare dependencies on earlier version of the gem you’re trying to activate.
For example, if you have foo-1.0.1 and foo-1.0.2 installed, then require 'foo' (assuming they have a file named foo.rb in their lib dirs and no other gem does) will cause version 1.0.2 to be activated. However if you also have a gem bar which has a dependency on 1.0.1 then calling require 'foo' after bar has been activated will cause 1.0.1 of foo to be activated.
Futhermore, if you try to require them in the other order, require 'foo'; require 'bar'; then you will get something like
Gem::LoadError: Unable to activate bar-1, because foo-2 conflicts with foo (= 1)
Here you can’t activate bar, which depends on version 1.0.1 of foo because you have already activated version 1.0.2 of foo.
Without Bundler, you have to specify each gem you want. e.g.,
require 'my_gem'
require 'my_other_gem'
However, Bundler can make this a bit easier for you using a Gemfile
If this is your Gemfile
gem 'my_gem'
gem 'my_other_gem'
Calling this will include all gems
require 'bundler/setup'

Can't activate gem: how do I figure out which gem has a dependency on this one?

I'm getting the following error:
Gem::Exception: can't activate hpricot (= 0.6.161, runtime),
already activated hpricot-0.8.3
0.6 is installed locally, 0.8.3 is frozen in my app.
This is my "stacktrace":
Loading production environment (Rails 2.3.10)
/software/ruby-ror-gem-1.3.1/lib/rubygems.rb:149:in `activate':Gem::Exception: can't activate hpricot (= 0.6.161, runtime), already activated hpricot-0.8.3
/e/app/www.example.com/rails/releases/20101117142713/vendor/rails/railties/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController
How do I figure out which gem or library has a dependency on hpricot 0.6?
I've added the output of user438962's command below:
{"daemons-1.0.9"=>[],
"scgi_dp_rails-0.0.5"=>["preforkdp", "daemons"],
"rails-2.3.10"=>[],
"rwfd-0.1.0"=>[],
"nokogiri-1.3.2"=>["racc", "rexical", "rake-compiler", "hoe"],
"activesupport-2.3.10"=>[],
"rack-1.0.1"=>
["test-spec",
"camping",
"fcgi",
"memcache-client",
"mongrel",
"ruby-openid",
"thin"],
"rack-1.1.0"=>
["test-spec", "camping", "fcgi", "memcache-client", "mongrel", "thin"],
"preforkdp-0.1.2"=>["rwfd"],
"activerecord-2.3.10"=>[],
"hpricot-0.6.161"=>[],
"cgi_multipart_eof_fix-2.5.0"=>[],
"fastthread-1.0.1"=>[],
"gem_plugin-0.2.3"=>[],
"activeresource-2.3.10"=>[],
"ferret-0.11.6"=>["rake"],
"mysql-2.7"=>[],
"actionmailer-2.3.10"=>[],
"actionpack-2.3.10"=>[],
"hpricot-0.8.3"=>[],
"mongrel_upload_progress-0.2.2"=>["mongrel", "gem_plugin"],
"mongrel-1.1.3"=>
["gem_plugin", "daemons", "fastthread", "cgi_multipart_eof_fix"],
"mongrel_cluster-1.0.5"=>["gem_plugin", "mongrel"],
"rake-0.8.4"=>[],
"haml-2.0.9"=>[],
"remvee-mini_magick-1.2.3.4.0"=>[]}
If you use Bundler, you avoid this problem and you have the really great command : bundle viz
This Command generate a graph with all dependencies.
require 'rubygems'
require 'pp'
h = {}
Gem.source_index.each{|g, spec| h[g] = spec.dependencies.map{|d| d.name} }
pp h
I found that rfeedparser is the gem that uses hpricot 0.6.
The problem is that this version (0.6) works with rfeedparser, but emits the warning "Passing no parameters to XML::SaxParser.new is deprecated."
Well, with newer versions of hpricot (at least 0.8.2), this warning seems to have taken effect, because now having that version of hpricot or newer causes "ArgumentError: wrong number of arguments (1 for 0)" when calling FeedParser.parse(url).
Unfortunately, I've found that the only way to make this work with legacy Rails (we have a 2.2.2 app) is to uninstall any hpricot version that's not 0.6.
The issue will be that one of the gems you use depends on hpricot version 0.6.161
and so tries to load it, but that you already have hpricot-0.8.3 loaded. The more recent version might be loaded if you're using hpricot yourself, and have required hpricot for use without specifying a version. If that's the case, you can change your own require to be the same version as the other gem uses (0.6.161).
The other reason the more recent version of hpricot is being loaded, could be that another gem you use depends on that version of hpricot, meaning you can't use the specific versions of those two gems you have because they have clashing requirements for their hpricot version.
Use the methods other users have posted to help you track down the dependencies of the gems you are using.
You could try grepping your load path:
$:.each do |dir|
cmd = %(grep -r hpricot #{dir})
puts cmd
puts `#{cmd}`
end

installed gems activated before frozen gems?

We're using gems:unpack to ensure gem version consistency across environments. However, we're running into:
can't activate , already activated [GEM-VERSION]
Is this because installed gems take precedence over frozen ones? Is it possible to have frozen gems activate first? Advice on ways to keep gems consistent welcome.
This usually happens when a gem/plugin you have packed requires a gem then a second gem/plugin requires a specific version of the same gem. The first gem requires the dependency, but when the second gem requires the specified version of the same gem then you will see the error you describe.
For example:
some_gem requires special_gem
another_gem requires special_gem => 1.0
And you have the following:
Packed in app:
special_gem 2.0
some_gem 1.0
another_gem 1.0
Installed Locally:
special_gem 1.0, 2.0
some_gem 1.0
another_gem 1.0
Then the some_gem will require 2.0, but when another_gem requires 1.0 you get the error.

Resources