Warning regarding not using bundler when running guard init
Asked Answered
C

2

10

In my Rails app am getting this warning when running guard init rspec:

Warning: you have a Gemfile, but you're not using bundler or
RUBYGEMS_GEMDEPS
14:54:15 - INFO - Writing new Guardfile to
/home/ubuntu/railsprojects/sillyfish/Guardfile 14:54:16 - INFO - rspec
guard added to Guardfile, feel free to edit it

I don't understand why it's showing. Is it okay to ignore this warning?

Here is my Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.4'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'rspec-rails', '3.3.3'
  gem 'guard-rspec', require: false
  gem 'spring-commands-rspec'
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

group :test do
  gem 'capybara', '2.5.0'
end

#custom gems
gem 'puma'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'devise', '~> 3.5.2'
Catarinacatarrh answered 10/10, 2015 at 9:46 Comment(4)
Did you run the bundle install command?Padishah
Yes i did. Eventhough its showing this warning everything seems working fine.Catarinacatarrh
guard init rspec will add guard definition to your Guardfile, but Guardfile is generated by guard, I think you should add guard gem to your gemfile.Padishah
Tried that but showing same warning.Catarinacatarrh
T
15

If you run guard init rspec, it will use the globally installed guard-rails. To run the one installed through your Gemfile, use bundle exec guard init rspec. This is also what is recommended in the documentation.

From the README:

It's important that you always run Guard through Bundler to avoid errors.

So it's probably best to take this warning seriously, to avoid issues down the line.

Testes answered 10/10, 2015 at 11:57 Comment(2)
Thanks for pointing this out. As i already created the guardfile using guard init rspec can i simply delete the guard file and regenerate using bundle exec...?Catarinacatarrh
That should be fine @ABHILASHV.R. One instance when this can cause issues is when the version of your global Gem and the one specified for the project are different, so it's a good practice to always run commands with the bundle exec prefix.Testes
S
1

A more technical answer:

There are 3 ways gems can be selected for your Ruby (or Rails) projects:

  1. As they are installed on your system (by looking at environment variables such as $GEM_HOME), e.g. guard init rspec will look for guard and guard-rspec in your $GEM_HOME. Usually RubyGems will use the latest installed versions you have installed (not always what you'll want).

  2. If you have Bundler, bundle exec guard init rspec will cause your gems to be loaded in versions listed in your Gemfile.lock. This also allows you to load gems directly from other folders (anywhere using :path option in your Gemfile) bundled with the app (e.g. .bundle directory) or even downloaded and updated from GitHub (using :github, :branch, etc. options).

  3. If you have a recent version of RubyGems, it can also load your gems from a Gemfile.lock. But only if you have the $RUBYGEMS_GEMDEPS environment properly set up. It works like Bundler (it reads your Gemfile.lock), except it doesn't have all the features (like loading gems from a GitHub repository).

In general, if your project has a Gemfile, it's best to use Bundler, because it makes sure all the versions of all gems are matched up to what you expect.

Sorrows answered 29/7, 2016 at 16:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.