How to prevent warnings in ruby 2.7 - ruby

In ruby 2.7 I having a lot of warnings like this:
<main>: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead
/Users/user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/pry-nav-0.3.0/lib/pry-nav.rb:17:
warning: in `eval'
The RUBYOPT with such parameters doesn't work:
-W:no-deprecated -W:no-experimental

This is pry specific and it should have been fixed, see this commit.
Update pry (which pry-rails has a dependency) to v0.13.0
Edit: On the other hand, pry-nav which also seems to be involved in your issues currently asks for something lower than v0.13.0, so it might not work just like this out of the box. You have to get it to run with the latest pry.

Related

Ruby 2.7.4 Net Constant Warnings

I'm getting repetitive warnings upon running a ruby script in a crontab, as well as manually in the terminal.
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:208: warning: previous definition of BUFSIZE was here
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:504: warning: previous definition of Socket was here
I've changed the script to either use net/http or Faraday, the latter I'm assuming requires the first. Having seen this behaviour before recently and way back, this is a reload of the net gem, which is part of the core if I am correct. I'm just not sure why it's reloading.
I'm using rbenv to juggle ruby versions for a couple of reasons, and that won't change. My shebang is #!/Users/rich/.rbenv/shims/ruby but my ruby version is a bit different:
$ which ruby
==> /Users/rich/.rbenv/versions/2.7.4/bin/ruby
$ ruby -v
==> Ruby version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm64-darwin21]
This slight difference from the shebang and requested versions of ruby might be the issue. I have many scripts that rely on that shebang, which points to the current rbenv version, which is what I want. I change versions from time to time and don't want to hard code that instruction.
Is there a way I can see why this is happening? How can I make these go away? How can I stop reloading core gems that are already loaded?
Bundler was the culprit with some dependency issues and reloading various versions on top of previous Gemfile.lock versions...something like that. Update this way:
bundle update --bundler
I had to add the following 2 lines to the Gemfile to finally eliminate the all the warnings:
gem 'net-http'
gem 'uri', '0.10.0' # force the default version for ruby 2.7

Why did my minitest/pride alias break?

Silly, cosmetic question for everyone.
I take pride in my testing. That is, I like to use minitest/pride. Unfortunately, not everyone on my team is a fan, so I have activated it in the past using the command line instead of modifying the code by setting an alias to this:
RUBYOPT=-rminitest/pride bex rake`
(bex is an alias to bundle exec, and the default rake task runs our tests.)
Recently, we updated the ruby version of our project from 1.9.3 to 2.2.0. This has broken my alias, and now when I try to run it, I get this error instead:
/Users/cf5455/.rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- minitest/pride (LoadError)
from /Users/cf5455/.rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
My best guess as to why this is happening is that MiniTest was changed since our last Ruby version and pride has been renamed or moved, but I have not been successfully able to Google its new name or location.
Does someone know a way that I can fix my arguments to get pride working again?
Duplicated your error by switching to ruby 2.3.0. I just ran the tests before installing any gems.
I managed to get the tests running with your alias by simply doing a gem minitest install. Not sure if your problem is caused by the same reason since I'm using rbenv for managing my rubies and gems but it does feel like you are having a package management issue. Hope this helps.

Migrating to rubinius

I'm trying to migrate my project from mri to rubinius to get concurrency advantage.
I've started the server and open first page and then got error:
Puma caught this error: undefined method `=~' for Pathname (NameError)
kernel/common/module.rb:212:in `instance_method'
kernel/common/module.rb:354:in `undef_method'
kernel/bootstrap/array.rb:66:in `each'
kernel/common/module.rb:352:in `undef_method'
...
My Gemfile
source 'https://rubygems.org'
ruby '2.1.0', :engine => "rbx", engine_version: '2.2.1'
gem "rubysl" # Ruby Standard Library meta-gem for rubinius
# Server requirements
gem 'puma'
...
What might be a problem here?
UPDATE: full stack trace
I examined your stack trace and looked at the Rubinius source code. The offending line is:
class Pathname
undef =~ # THIS IS IT
end
#=~ is an instance method on Object so normally undef =~ should work on any class... unless it has been undef'd on Object or on Pathname already.
I'm wondering if this is happening because you have the rubysl gem in your Gemfile. I don't know Rubinius, but from what I can see, it doesn't seem to require you to specifically include this gem. Or maybe it did in past versions, but doesn't now. If the standard library is being loaded twice, that would explain why undef =~ fails the second time.
If that doesn't help, I recommend you try temporarily removing as many gems as possible and see if the problem disappears. If so, add them back one by one until you find which one is causing the problem.

Is there a trick to profiling memory usage w/ ruby-prof using an rvm gemset?

I've been trying to get ruby-prof working for memory usage on Mac OS X w/ Ruby 1.8.7 and so far I'm not having much luck.
I understand from the documentation that RubyProf::MEMORY mode requires a patched version of Ruby. I've tried installing the GC-patched version (which I found referenced in the Rails documentation) through RVM:
rvm reinstall 1.8.7 --patch ruby187gc
Based on the output of this command, everything looks good. I clearly see "Applying patch 'ruby187gc'" in the console output.
The problem seems to come when trying to use an RVM gemset. I wrote the following script to test this:
require "ruby-prof"
RubyProf.measure_mode = RubyProf::MEMORY
results = RubyProf.profile do
# code to measure
end
File.open(File.join(File.dirname(__FILE__), "profile-graph.html"), "w") do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
end
When I preceed this script with rvm use 1.8.7 --patch ruby187gc, it creates the file "profile-graph.html" showing memory usage of all the different method calls in the script, as I'd expect. However, when I try something like rvm use 1.8.7#gemset_name --patch ruby187gc, the output file contains all "nan" values.
What gives? Is there some special trick to using a patched version of Ruby along with an RVM gemset? Does the problem lie elsewhere? I'm crossing my fingers and hoping that someone has run into a very similar problem and figured this out before.
Ah, I was overcomplicating things. Turns out I just needed to uninstall and reinstall the ruby-prof gem (after patching Ruby).

rcov outside rails

This may seem obvious but I don't find a way to run Rcov or coverMe outside a Rails project.
I would like to use it with Rspec 2.5
I am using Ruby 1.9.2 so I guess this may be the problem.
I also would like not to use rake tasks but a command on the command line. I have tried several things and the best result I got is Rcov report for :
/var/lib/gems/1.9.1/gems/rcov-0.9.9/lib/rcov/code_coverage_analyzer.rb
and
/var/lib/gems/1.9.1/gems/rcov-0.9.9/lib/rcov/code_coverage_analyzer.rb
No idea why
Check out http://ruby-toolbox.com/categories/code_metrics.html for some alternatives to RCov if using Ruby 1.9 is the problem.
SimpleCov, it runs awesome outside the Rails box.
http://rubydoc.info/gems/simplecov/0.5.4/frames
The latest available version of rcov (0.9.8) still doesn't have good support for 1.9.2. You can try to run it on your project by doing:
rcov spec/*.rb
But you'll most likely get something like:
** WARNING: Ruby 1.9 Support is experimental at best. Don't expect correct results! **
And then some errors after that.

Resources