The day my gems disappeared

So my Rakefile kept telling me RSpec wasn’t installed.

begin
  require 'rspec/core/rake_task'
  RSpec::Core::RakeTask.new(:spec)

  task :default => :spec
  task :spec => :dotenv
rescue LoadError
  warn "RSpec unavailable; spec task not defined"
end
$ rake spec
RSpec unavailable; spec task not defined

“Rubbish”, said I. “It is clearly specified in the Gemfile.”

# ...
group :test do
  gem 'rspec', '~> 2.14'
  gem 'rspec-given', '~> 3.1'
  gem 'capybara'
  gem 'domino'
  gem 'fakeweb'
  gem 'vcr'
  gem 'launchy'
end
# ...

Let’s ask Bundler.

$ bundle show rspec-core
Could not find gem 'rspec-core'.

Wait, what? Maybe I’m out of date.

$ bundle
Using rake (10.1.0) 
Using i18n (0.6.5) 
Using minitest (4.7.5) 
Using multi_json (1.8.2) 
Using atomic (1.1.14) 
Using thread_safe (0.1.3) 
Using tzinfo (0.3.38) 
Using activesupport (4.0.0) 
Using builder (3.1.4) 
Using activemodel (4.0.0) 
Using rails-observers (0.1.2) 
Using activeresource (4.0.0) 
Using addressable (2.3.5) 
Using backports (3.3.5) 
Using columnize (0.3.6) 
Using debugger-linecache (1.2.0) 
Using byebug (2.3.1) 
Using dalli (2.6.4) 
Using unf_ext (0.0.6) 
Using unf (0.1.3) 
Using domain_name (0.5.14) 
Using dotenv (0.9.0) 
Using tilt (1.4.1) 
Using haml (4.0.3) 
Using kramdown (1.2.0) 
Using map (6.5.1) 
Using net-http-digest_auth (1.4) 
Using net-http-persistent (2.9) 
Using mini_portile (0.5.2) 
Using nokogiri (1.6.0) 
Using ntlm-http (0.1.1) 
Using webrobots (0.1.1) 
Using mechanize (2.1.1) 
Using memcachier (0.0.2) 
Using moneta (0.7.20) 
Using rack (1.5.2) 
Using rack-protection (1.5.1) 
Using rack-test (0.6.2) 
Using sass (3.2.12) 
Using sinatra (1.4.4) 
Using sinatra-contrib (1.4.1) 
Using wistia-api (0.2.3) 
Using bundler (1.3.5) 
Your bundle is complete!
Gems in the group test were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

At this point, had I paid attention, I would have seen a clue at the end of the bundle output:

Gems in the group test were not installed.

Instead, I just noted with increasing perplexity the lack of any gems from the test group in the list of bundled gems.

Eventually I had the bright idea to read the documentation for bundle install, where I discovered that –without is a remembered option. Sure enough:

$ cat .bundle/config 
---
BUNDLE_WITHOUT: test

Obviously the reverse of –without is –with.

$ bundle install --with test
Unknown switches '--with'

Silly me.

Turns out the correct invocation is:

$ bundle install --without=

(Note that the –without= option is deliberately left blank.)

Another one for the “blog this so Google will remind me the next time I make the same mistake” file.

4 comments

  1. Went through this same EXACT issue this week! Was testing some bundler groups for being in gem development lingo, and I was like whhhhhat?! When I was bundling I was doing the same thing and looking over the output, taking it for granted!

    Good post 🙂

Comments are closed.