How to fix win32console message in rake test output? - ruby-on-rails

I'm currently trying to learn Ruby on Rails on Windows 10.
I'm following the excellent railstutorial by Michael Hartl.
However, I'm getting bugged by the 'gem install win32console' message (and lack of colour) appearing when I run rake test. How can I fix this?
Sample output:
$ bundle exec rake test
ansi: 'gem install win32console' to use color on Windows
Started
3/3: [===================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.35885s
3 tests, 6 assertions, 0 failures, 0 errors, 0 skips
My setup:
Base: Ruby 2.2 Rails Installer for Windows.
Running commands using Git Bash.
I also have the minitest-reporters gem installed (step 3.7.1 of tutorial).
What I've tried:
First I ran gem install win32console bu this had no effect, even though the gem is visible when I run gem list.
Then I saw win32console is deprecated so I installed ansicon.
This also had no effect. And it seems colours are supported on Windows 10 anyway.
E.g. I can run the Hello World example puts "\e[34mHello \e[31mWorld\e[0m" found on this blog and it shows blue and red text, whether ansicon is installed or not.
However, colours won't show up correctly in rake test output and I still get the warning.

Hooray got it working!
In the end your comment Jordan plus the suggestions on Paul's Perambulations got me there.
Steps taken, for anyone else stuck on this:
Download and unzip win32console source
Install specific (older) versions of the dependencies:
gem install rake -v 10.4.2
gem install rake-compiler -v 0.9.9 (this is current latest anyway)
gem install hoe -v 3.7.0
Run rake _10.4.2_ gem in the win32console source directory (to use correct version)
Run gem install pkg/win32console-1.3.2.gem (had to change version number and flip the slash around from original instructions)
Add gem "win32console", '1.3.2' to Gemfile
Go back to project directory and run bundle install
Finally run bundle exec rake test - the info message has disappeared and colours are showing correctly!

Related

How to fix issue with bundler requiring latest version of gem when I need to require a different version?

I've been scratching my head with this one for close to 2 weeks. I have an Ubuntu 14.04 server with rbenv installed running a number of different Rails websites, some of them on older versions of Rails, some of them on the latest version.
I have 2 websites in particular that both require a different version of puma_worker_killer, 1 requires 0.1.0 and the other 0.1.1. Both these websites use Ruby 2.5.3.
When I start the server with RAILS_ENV=dev3 bundle exec pumactl -F ./config/puma.rb start I get the following error in the logs and the website hangs:
You have already activated puma_worker_killer 0.1.1, but your Gemfile requires puma_worker_killer 0.1.0. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
At first I thought it may've been an issue with rbenv as I had the gems installed in ~/.gem instead of in ~/.rbenv so I've nuked all rubies in ~/.gem and installed them freshly into the correct rbenv folder with bundle install and I still get this same issue.
Now at this point I want to clarify that I've done extensive research on this subject online and I know that I can do many things to solve this.
I know I can just change the version and bundle update puma_worker_killer.
I also know I can remove the latest version by doing gem uninstall puma_worker_killer and choosing 0.1.1 but this would mean the dependencies on the other website wouldn't be met.
I've done some digging into the source code of bundler and can see that it's caused by the following line of code:
return if activated_spec.version == spec.version
When running in the context of bundler using bundle exec both the activated_spec and spec match, meaning that the following code in that method (check_for_activated_spec!) doesn't run. For some reason, when running the command above to start the server, activated_spec (the activated gem) is the latest version (0.1.1) and not the one listed in the Gemfile (0.1.0), meaning it doesn't return and throws the error above.
I should also mention that there also seems to be the same issue with get_process_mem, which is one of the dependencies of puma_worker_killer. It complains of already activating 0.2.5 but my Gemfile wants 0.2.4:
You have already activated get_process_mem 0.2.5, but your Gemfile requires get_process_mem 0.2.4. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
It is my understanding of bundler that it should load the version listed in the Gemfile when using bundle exec to counteract this very problem of having multiple versions of the same gem.
I know I could also create a separate gemset (which can be done with rbenv apparently) that has different versions of puma_worker_killer in them and then run rbenv local 2.5.3-pwk0.1.0 or rbenv local 2.5.3-pwk0.1.1 depending on the version I want, inside the project, but that seems overkill for what I want to achieve.
At this rate I'm tempted to just update all websites with the latest version of both puma_worker_killer and get_process_mem and then lock them in and remove all older versions on the server, but I don't think I should have to do that.
Does anyone know what's happening here or whether I'm doing something glaringly wrong?
Below is the piece of code I use to use puma_worker_killer in my puma config.
before_fork do
require 'puma_worker_killer'
PumaWorkerKiller.config do |config|
config.ram = 1024 # mb
config.frequency = 5 # seconds
config.percent_usage = 0.98
config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds
end
PumaWorkerKiller.start
end
What is happening here is basically you have several versions of the gem in your system.
Most of the time it did not cause issues because bundle exec will dynamically load required versions for your application.
In some cases gems will have binary files included. It such case bundle exec will not help because you can have only one version linked in one moment.
Basically, if you want to call the binary by alias you have to use separate gemset for each application.
If you want to keep all the gems in one place you can call binary files directly.
In your case it will be:
RAILS_ENV=dev3 bundle exec pumactl _0.1.0_ -F ./config/puma.rb
The _<version>_ construction allows you to specify version of the binary file you want to run.
You can create your custom binary as well, like fake_pumactl inside the project which will check the Gemfile.lock and automatically proxy your call to the library and specify version automatically for you. Another way is to parse gem version by shell script and put this script instead of _<version>_ in your call.
Here is the brief example
$ gem install puma
Fetching puma-4.3.3.gem
$ gem install puma -v 4.3.0
Fetching puma-4.3.0.gem
$ pumactl -v
4.3.3
$ pumactl _4.3.0_ -v
4.3.0
$ ruby -v
ruby 2.6.3p62
$ export puma_version=_4.3.0_
$ pumactl ${puma_version} -v
4.3.0
puma_version variable can be defined from result of a bash command which will extract the gem version from Gemfile.lock.

error Could not find i18n-0.7.0 in any of the sources

This Saturday (27th, December), I upgraded my project Rails version from version 4.1.5 to version 4.2.0. And I also upgraded the Ruby version from 2.1.2 to 2.1.5.
Today, I was trying to run a Controller generator: bin/rails g controller Clients index and I realized that the command is not working. I am getting this error:
Could not find i18n-0.7.0 in any of the sources
I tried other commands like: bin/rake db:migrate, bin/rake and the same problem.
But I can run the server using: bin/rails s. I can navigate through the website too.
I solved the problem.
The problem was, I upgraded the Rails version but I did not upgrade the bin/ folder.
So, to do that, I had to run the following command, and override everything:
$ bundle exec rake rails:update:bin
Thanks.
Try:
bin/bundle install
Solves the problem ;)
Earlier version was i18n --version 0.6.1
Issue got resolved using the below command.
sudo gem install i18n --version 0.7
I had the same issue and solved it by deleting the Gemfile.lock and running another bundle command.
After that, I was back to an earlier version of i18n (0.6.11) and everything worked as expected.
If you is using RVM you need reset your RVM gemsets, try this:
https://github.com/phusion/passenger/wiki/Resetting-RVM-gemsets
I did all of the above without result. Then I discovered that i18n couldn't be installed because my Ruby version was too low. (Said message was lost in the blast that bundler emits.) I updated Ruby and voila! i18n installed. NB: for some reason, Gemfile.lock showed it as installed even before this success, but RubyMine didn't show it as one of the installed libraries. Go figure.

Two versions of rails showing up when i run gem list rails

I just installed ruby and rails. When i run 'ruby -v' command it shows version of ruby that's currently installed. Similarly, I need to check the version of rails as well. Since rails was installed using RVM, the 'rails -v' command is not working. When i run the 'gem list rails' command, it shows two versions of rails. But when i try 'which rails' command, nothing happens. Please help find the version of rails installed.
Have you tried to run this into your console:
$ rails --version
Can't test from here but I'm pretty sure it was --version with rails.
If you want to know which version a specific app is running, you can simply open Gemfile and see. Should be one of the first lines.

Inconsistent rails gem errors

Every other time I run a rake command, or start the server (script/server) I get gem install errors;
Missing these required gems:
image_science >= 0
youtube_it >= 0
But, if I ignore that (the gems are installed) and try again, then on the 2nd or 3rd attempt, it will work fine, no errors.
It seems like maybe there are multiple rails or rake installs, but which rails shows only '/usr/bin/rails' as does which rake
I'm wondering if maybe my app could have different requirements in different places? Is that possible?
Rails version is 2.3.15
EDIT
More output
You're running:
ruby 1.8.7.358 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.8.24 at /Library/Ruby/Gems/1.8, /Users/<snip>/.gem/ruby/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Thanks in advance.

How to run a specific version of rake

Background:
I get errors whenever I run rake in an older project. (uninitialized constant Rake::DSL).
The rails project in question is an old project that was started with Rails 2.1 (I think), and since then I've updated the OS on my laptop a couple of times, and made updates along the way to make it run.
Right now, the rails app works fine, provided I have RAILS_GEM_VERSION set to 2.3.5. I'm not sure if the app was completely updated to Rails 2.3.5.
There is no Gemfile in my older project.
If I create a brand-new rails project (and unset RAILS_GEM_VERSION), rake runs fine.
My question: To troubleshoot, I'd like to try newer versions of rake. I'd like to know how to force one specific version to be used, since it appears I have multiple versions installed.
Info on my environment:
$ gem list rake
*** LOCAL GEMS ***
rake (0.9.2.2, 0.9.2, 0.8.7, 0.8.3)
$ rake --version
rake, version 0.8.7
So it looks like it's picking up the 0.8.7 version.
All the help files online seem to tell me to specify the rake version in the Gemfile, but there isn't one in this project. (Maybe it predates gemfiles?)
If I unset the RAILS_GEM_ENVIRONMENT variable altogether, and try to run rake, I get:
rake aborted!
can't activate rails (= 2.3.5, runtime) for [], already activated rails-3.2.8 for []
None of the environment config files in my older project set that variable either.
This may be of help. Have you tried the underscore solution?
Example:
rake _0.9.2_
you can run rake specific version by using this
bundle exec rake ...
more detail see this - bundle exec, rake
You can uninstall the current version of rake and install another desired version using commands similar to the following:
gem uninstall rake 12.3.1
gem install rake 10.5.0
(Note: you might need to run as sudo for permissions)
I had a problem where I received the following error while trying to install rake 10.5.0:
Could not find a valid gem '0.8.7' (>= 0) in any repository
I resolved this problem by adding the following line to my Gemfile:
gem 'rake', ' <11.0'
After editing Gemfile I was able to successfully downgrade rake by updating my gems:
bundle update

Resources