Search code examples
rubyrubygemsbundler

Bundler misses gems on Mac


I have problems loading gems with bundler. Happens only in my mac environment. The gem cannot be found via bundler, but when I install the gem globally via gem install #{gem} it works.

I suppose this is something environment specific, but I am not sure how to debug it. I have the same versions of ruby, ruby-install and chruby and bundler on a Ubuntu box, but it works just fine.

So far I had this problem with the gems spring-comands-rspec and rack-cors.

Broken environment (Mac):

OS: Darwin nb-mjacobus2 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Bundler: 1.15.4
ruby-install: 0.6.1
chruby: 0.3.9
ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

Exposing the error:

Gemfile

group :development do
  # ...
  gem 'spring-commands-rspec'
  # ...
end

Running tests

./bin/rspec spec/controller/some_controller_spec.rb:8
/$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- spring-commands-rspec (LoadError)
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.spring.rb:2:in `<top (required)>'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/commands.rb:29:in `<module:Spring>'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/commands.rb:4:in `<top (required)>'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/server.rb:9:in `<top (required)>'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/client/server.rb:9:in `call'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/bin/spring:49:in `<main>'

Manually installing the gem solves the problem....

gem install spring-commands-rspec
Fetching: spring-commands-rspec-1.0.4.gem (100%)
Successfully installed spring-commands-rspec-1.0.4
Parsing documentation for spring-commands-rspec-1.0.4
Installing ri documentation for spring-commands-rspec-1.0.4
Done installing documentation for spring-commands-rspec after 0 seconds
1 gem installed

... BUT I get this warnings:

./bin/rspec spec/pattern_library_controller_spec.rb
WARN: Unresolved specs during Gem::Specification.reset:
      minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
WARN: Unresolved specs during Gem::Specification.reset:
      minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Running via Spring preloader in process 53164
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 5284

SomeController
  should respond with a success status code (2xx)

Finished in 0.13193 seconds (files took 0.66951 seconds to load)
1 example, 0 failures

Randomized with seed 5284

Any idea what the problem could be?


Solution

  • For some reason the gems were installed inside inside vendor/bundle, but not all of them. Removing rm -rf .bundle vendor/bundle && bundle install did it.

    The content of .bundle/config was:

    ---
    BUNDLE_WITHOUT: "development:related"