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'
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.
A more technical answer:
There are 3 ways gems can be selected for your Ruby (or Rails) projects:
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).
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With