[Ruby on Rails] I get a warning when executing RSpec due to a different gem version.

Preface / Editing points

2020.10.10 I made a correction from the comment.

environment

Ruby 2.5.7 Rails 5.2.4

gem gem 'rspec-rails', '~> 3.6'

Background

When I wrote the test code in RSpec and executed it, I got the following error.

$ rspec spec/models/tag_spec.rb

WARN: Unresolved specs during Gem::Specification.reset:
      diff-lcs (< 2.0, >= 1.2.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.

It's not exactly an error, it seems that I'm being warned of it because there are multiple versions of the same gem, and the test itself was running successfully. However, I can't leave it alone, so I'll solve it.

procedure

I referred to this article for the solution. What to do when WARN: Clearing out unresolved specs. Appears in Qiita --Rubygem

First, let's check the gem in question.

$ diff-lcs (< 2.0, >= 1.2.0)

It was pointed out that there are multiple versions of the gem called diff-lcs, but I don't remember installing this gem myself, so of course it is not mentioned in the Gemfile. Then, when installing some gem, bundler may have installed it automatically as a dependent gem, so if you check Gemfile.lock, you can see thatdiff-lcs (1.4) other than the gem dependency of rspec. There was .4).

There are two dependent gems installed with rspec, both of which are like diff-lcs (> = 1.2.0, <2.0), and the version is not written, so the version of this gem is next I will investigate with a command.

$ gem list -a | grep diff-lcs

diff-lcs (1.4.4, 1.4.2, 1.3)

As a result of investigation, it seems that (1.4.4, 1.4.2, 1.3) 3 versions are installed. The non-dependent diff-lsc (1.4.4) is the latest of these, so we'll match the other two, which depend on rspec, to this version.

One thing to note here is that if you install a gem that depends on bundler, if you change the version of the dependent gem easily, other gems that are dependent on it may malfunction. In this case, the version of diff-lcs (<2.0,> = 1.2.0), which depends on rspec, was written as" 1.2.0 or more, less than 2.0 ", so it is the latest (in this time). I came to the conclusion that there is no problem even if I upgrade the version of 1.4.4.

Next, execute the command written on the reference site.

$ gem cleanup

And

$ bundle install

The warning text has now disappeared.

Procedure (if the dependency requires multiple versions of the gem)

I will excerpt from this comment.

$ bundle exec rspec (Executable file specification)

When you do, bundler will automatically recognize the dependencies described in the Gemfile.

When the dependency becomes complicated and multiple versions are absolutely necessary, this method is the only way because it cannot be combined into the latest version mentioned above.

Summary

In my case, there was another warning message in addition to this, so please see the next article for that ヽ (; ▽ ;) ノ Qiita-[Ruby on Rails] I get a warning when running RSpec because gem'chromedriver-helper' is deprecated.

If you have any questions, differences in interpretation, or discomfort in the description method, we would appreciate it if you could point them out in the comments.

Thank you for reading until the end.

Reference site

I have published the files I actually use on my GitHub, so I hope you can refer to that as well! GitHub - MasaoSasaki/matchi

Other What to do when WARN: Clearing out unresolved specs. Appears in Qiita --Rubygem YoheiIsokawa-[Rails] How to write Gemfile version specification

Recommended Posts

[Ruby on Rails] I get a warning when executing RSpec due to a different gem version.
[Ruby on Rails] I get a warning when running RSpec because gem'chromedriver-helper' is deprecated.
I get a Ruby version error when I try to start Rails.
Introducing Rspec, a Ruby on Rails test framework
I made a portfolio with Ruby On Rails
[Introduction] Try to create a Ruby on Rails application
Rspec: I want to test the post-execution state when I set a method on subject
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
What I was addicted to while using rspec on rails
How to display a graph in Ruby on Rails (LazyHighChart)
[Ruby on Rails] Column restrictions when saving to DB (4 representatives)
Apply CSS to a specific View in Ruby on Rails
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
Steps to build a Ruby on Rails development environment with Vagrant
(Ruby on Rails6) Create a function to edit the posted content
Rails tutorial When rails new cannot be done due to different versions
How to use Ruby on Rails
Change from SQLite3 to PostgreSQL in a new Ruby on Rails project
How to create a query using variables in GraphQL [Using Ruby on Rails]
How to build a Ruby on Rails environment using Docker (for Docker beginners)
I was a little addicted to running old Ruby environment and old Rails
What to do when Blocked Host: "host name" appears in Ruby on Rails
How to implement gem "summer note" in wysiwyg editor in Ruby on Rails
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Environment construction of Ruby on Rails from 0 [Cloud9] (From Ruby version change to Rails installation)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
[Ruby on Rails] View test with RSpec
[Ruby on Rails] How to use CarrierWave
[Ruby on Rails] Controller test with RSpec
Deploy to Heroku [Ruby on Rails] Beginner
Preparing to introduce jQuery to Ruby on Rails
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
[Ruby on Rails] Model test with RSpec
[Ruby on Rails] Button to return to top
I get an error when I try to use "^" or "$" in ruby ​​regular expression
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
What I tried when I wanted to get all the fields of a bean
[Ruby on Rails] Try to create a service that makes local cats happy
[Rails] When transitioning to a page with link_to, move to the specified location on the page
I managed to get a blank when I brought the contents of Beans to the textarea
[Ruby On Rails / HTML] How to display the cursor (caret) at an appropriate place when displaying a web page
Deploy to Ruby on Rails Elastic beanstalk (EB deploy)
[Rails] How to write when making a subquery
[Ruby on Rails] How to display error messages
[Ruby on Rails] Until the introduction of RSpec
[Rails] I tried to raise the Rails version from 5.0 to 5.2
How to add / remove Ruby on Rails columns
Introducing Rspec with Ruby on Rails x Docker
When the Ruby on Rails terminal rolls back
I get an error when adding a dependency
[Ruby] I want to do a method jump!
[Ruby on Rails] A memorandum of layout templates
[Ruby] When adding a null constraint to a table
(Ruby on Rails6) Creating data in a table
Rails beginners tried to get started with RSpec
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] How to use session method
I want to get the value in Ruby