Error installing json 1.8.3 with ruby 2.4

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You are trying to install the gems for your rails application in a new computer, or by using ruby 2.4 and you get the following error:

Solution

Remove your old Gemfile.lock file and run bundle again. A newer version of json (ie 1.8.6) should be installed.

Using Array.wrap in Rails when the results could either be a string or an array

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to use some array method in a value returned, which can either be a single value or an array of values.

Solution

Rails ActiveSupport Array, provides a method called wrap, that can be used to:

Wraps its argument in an array unless it is already an array (or array-like)

Full explanation of the method here.

Thanks Miles

Capturing output with UnitTest in Ruby

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You have some ruby code, a rake task for example, that outputs some results in the standard output, but you would like to test it in your unit tests.
MiniTest has capture_io and capture_subprocess_io, but there is nothing similar in UnitTest.

Solution

Looking at the code of the above MiniTest assertions you can create your own assertion to be used in your tests.

Create a new file under your test folder called MyAssertions and use the following code (taken from MiniTest), for your capture_output assertion:

Then include it in your test_helper.rb file with:

and use it in your tests like:

How to display the git last commit of every file in a list with ruby

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to display the last commit of every file that you have in a list.

Solution

Let’s say that you have the following file list in an array:

in order to be able to get the last commits of each of the files in ruby do the following:

Could not find libv8-3.16.14.9 in any of the sources

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You are trying to upgrade one of your gems (ie uglifier) and at the same time you are using a new gemset (ie for rails 4.2.4), and you get the following error when you are trying to bundle:

Solution

Upgrade to rails 4.2.4 first and bundle and afterwards change the other gem and do bundle again.

OSVDB 119927 : http Gem for Ruby SSL Certificate Validation MitM Spoofing

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

There was a security vulnerability issued by Gemnasium about the http gem with the title OSVDB-119927 – MitM Security Vulnerability.

The details for it are here.

Solution

After some investigation (gem dependency http –reverse-dependencies) it turns out that the twitter gem (5.14.), is using an older vulnerable http dependency (0.6.3).

In order to remove this warning and until there is a new twitter gem released, you can use the github master branch of twitter, like:

rvm – Branch origin/ruby_2_1_0 not found.

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You are trying to install the new ruby in your ubuntu rvm installation with rvm install 2.1 but you are getting the error:

Solution

If you are careful and you notice a warning message as:

then you would need to update your rvm installation to the latest one with:

And then you should be able to install the latest ruby version with:

Dreamhost keeps asking for password when installing rvm ruby version

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

After installing rvm on dreamhost, when trying to install any ruby version afterwards, there is a prompt for password, and when entering the user’s password there is the message that the user is not in the sudoers list.

Solution

To be able to install the rvm ruby version you would like you should be installing them by using the following which is based on the answer here :

and then: