Ruby on rails Bundler提升GemNotFound排除组中Gem的错误(使用,即,`--without test`)

Ruby on rails Bundler提升GemNotFound排除组中Gem的错误(使用,即,`--without test`),ruby-on-rails,ruby,rubygems,bundler,Ruby On Rails,Ruby,Rubygems,Bundler,当使用bundle install(无测试)安装gem时,然后使用bundle exec unicorn-c./config/unicorn.rb-E development启动我的服务器时,bundler抛出gem not found错误,因为gem只是测试环境中的依赖项。我已尝试明确指示bundler仅在boot.rb中使用默认和特定于环境的gems,如下所示: ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FIL

当使用
bundle install(无测试)安装gem时,然后使用
bundle exec unicorn-c./config/unicorn.rb-E development启动我的服务器时,bundler抛出gem not found错误,因为gem只是
测试
环境中的依赖项。我已尝试明确指示bundler仅在
boot.rb
中使用默认和特定于环境的gems,如下所示:

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

# Set up gems listed in the Gemfile.
if File.exists?(ENV['BUNDLE_GEMFILE'])
  require 'bundler'
  Bundler.setup(:default, ENV["RAILS_ENV"])
end
但错误依然存在。我已经验证了服务器是否在预期的环境中运行,但仍然会出现如下错误:
/var/lib/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/spec_set.rb:95:in'block in materialize':对于测试特定的gems,在任何源(bundler::GemNotFound)
中都找不到io-like-0.3.0。我也在gem文件中的默认gem中显式添加了
io-like
gem,以测试这是否是
io-like
特定的问题,但对于不同的仅测试gem,我仍然会得到相同的错误

你知道这里会发生什么吗

我在下面包含了我的Gemfile,以及我的Gemfile.lock,作为上下文

Gemfile

source 'https://rubygems.org'

ruby '2.3.0'

gem 'rails', '4.2.6'

gem 'therubyracer', platforms: :ruby
gem 'unicorn'

gem 'pg'

# API helpers
gem 'gon'
gem 'jbuilder', '~> 2.0'
gem 'responders'
gem 'kaminari'

# asset helpers
gem "sprockets-es6"
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'

# Model helpers
gem 'bcrypt', '~> 3.1.11'
gem 'redcarpet'
gem 'carrierwave'
gem 'carrierwave-dropbox'
gem "fog-aws"

gem 'sendgrid'

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'factory_girl_rails', require: false
  gem 'jasmine-rails'
end

group :test do
  gem 'rspec-rails'
  gem 'database_cleaner'
  gem 'capybara'
  gem 'selenium-webdriver'
  gem 'chromedriver-helper'
  gem 'timecop'
end
Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.6)
      actionpack (= 4.2.6)
      actionview (= 4.2.6)
      activejob (= 4.2.6)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.6)
      actionview (= 4.2.6)
      activesupport (= 4.2.6)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.6)
      activesupport (= 4.2.6)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.6)
      activesupport (= 4.2.6)
      globalid (>= 0.3.0)
    activemodel (4.2.6)
      activesupport (= 4.2.6)
      builder (~> 3.1)
    activerecord (4.2.6)
      activemodel (= 4.2.6)
      activesupport (= 4.2.6)
      arel (~> 6.0)
    activesupport (4.2.6)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    archive-zip (0.7.0)
      io-like (~> 0.3.0)
    arel (6.0.3)
    babel-source (5.8.19)
    babel-transpiler (0.7.0)
      babel-source (>= 4.0, < 6)
      execjs (~> 2.0)
    bcrypt (3.1.11)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    builder (3.2.2)
    byebug (5.0.0)
      columnize (= 0.9.0)
    capybara (2.4.4)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    carrierwave (0.10.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      json (>= 1.7)
      mime-types (>= 1.16)
    carrierwave-dropbox (1.2.1)
      carrierwave (~> 0.9)
      dropbox-sdk (~> 1.6)
    childprocess (0.5.6)
      ffi (~> 1.0, >= 1.0.11)
    chromedriver-helper (1.0.0)
      archive-zip (~> 0.7.0)
      nokogiri (~> 1.6)
    columnize (0.9.0)
    concurrent-ruby (1.0.2)
    database_cleaner (1.4.1)
    debug_inspector (0.0.2)
    diff-lcs (1.2.5)
    dropbox-sdk (1.6.5)
      json
    erubis (2.7.0)
    excon (0.49.0)
    execjs (2.5.2)
    factory_girl (4.5.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.5.0)
      factory_girl (~> 4.5.0)
      railties (>= 3.0.0)
    ffi (1.9.10)
    fog-aws (0.9.2)
      fog-core (~> 1.27)
      fog-json (~> 1.0)
      fog-xml (~> 0.1)
      ipaddress (~> 0.8)
    fog-core (1.37.0)
      builder
      excon (~> 0.45)
      formatador (~> 0.2)
    fog-json (1.0.2)
      fog-core (~> 1.0)
      multi_json (~> 1.10)
    fog-xml (0.1.2)
      fog-core
      nokogiri (~> 1.5, >= 1.5.11)
    formatador (0.2.5)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    gon (6.0.1)
      actionpack (>= 3.0)
      json
      multi_json
      request_store (>= 1.0)
    i18n (0.7.0)
    io-like (0.3.0)
    ipaddress (0.8.3)
    jasmine-core (2.3.4)
    jasmine-rails (0.10.8)
      jasmine-core (>= 1.3, < 3.0)
      phantomjs (>= 1.9)
      railties (>= 3.2.0)
      sprockets-rails
    jbuilder (2.3.1)
      activesupport (>= 3.0.0, < 5)
      multi_json (~> 1.2)
    json (1.8.3)
    kaminari (0.16.3)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    kgio (2.9.3)
    libv8 (3.16.14.11)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.4)
      mime-types (>= 1.16, < 4)
    mime-types (3.0)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0221)
    mini_portile2 (2.0.0)
    minitest (5.8.4)
    multi_json (1.11.2)
    nokogiri (1.6.7.2)
      mini_portile2 (~> 2.0.0.rc2)
    pg (0.18.2)
    phantomjs (1.9.8.0)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.6)
      actionmailer (= 4.2.6)
      actionpack (= 4.2.6)
      actionview (= 4.2.6)
      activejob (= 4.2.6)
      activemodel (= 4.2.6)
      activerecord (= 4.2.6)
      activesupport (= 4.2.6)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.6)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    railties (4.2.6)
      actionpack (= 4.2.6)
      activesupport (= 4.2.6)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    raindrops (0.13.0)
    rake (11.1.2)
    redcarpet (3.3.2)
    ref (2.0.0)
    request_store (1.2.0)
    responders (2.1.0)
      railties (>= 4.2.0, < 5)
    rspec-core (3.3.2)
      rspec-support (~> 3.3.0)
    rspec-expectations (3.3.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-mocks (3.3.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-rails (3.3.3)
      actionpack (>= 3.0, < 4.3)
      activesupport (>= 3.0, < 4.3)
      railties (>= 3.0, < 4.3)
      rspec-core (~> 3.3.0)
      rspec-expectations (~> 3.3.0)
      rspec-mocks (~> 3.3.0)
      rspec-support (~> 3.3.0)
    rspec-support (3.3.0)
    rubyzip (1.1.7)
    sass (3.4.16)
    sass-rails (5.0.3)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (~> 1.1)
    selenium-webdriver (2.47.1)
      childprocess (~> 0.5)
      multi_json (~> 1.0)
      rubyzip (~> 1.0)
      websocket (~> 1.0)
    sendgrid (1.2.0)
      json
    spring (1.3.6)
    sprockets (3.6.0)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-es6 (0.7.0)
      babel-transpiler
      sprockets (>= 3.0.0)
    sprockets-rails (3.0.4)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    therubyracer (0.12.2)
      libv8 (~> 3.16.14.0)
      ref
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (1.4.1)
    timecop (0.7.4)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (2.7.1)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unicorn (4.9.0)
      kgio (~> 2.6)
      rack
      raindrops (~> 0.7)
    web-console (2.2.1)
      activemodel (>= 4.0)
      binding_of_caller (>= 0.7.2)
      railties (>= 4.0)
      sprockets-rails (>= 2.0, < 4.0)
    websocket (1.2.2)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  bcrypt (~> 3.1.11)
  byebug
  capybara
  carrierwave
  carrierwave-dropbox
  chromedriver-helper
  database_cleaner
  factory_girl_rails
  fog-aws
  gon
  io-like
  jasmine-rails
  jbuilder (~> 2.0)
  kaminari
  pg
  rails (= 4.2.6)
  redcarpet
  responders
  rspec-rails
  sass-rails (~> 5.0)
  selenium-webdriver
  sendgrid
  spring
  sprockets-es6
  therubyracer
  timecop
  uglifier (>= 1.3.0)
  unicorn
  web-console (~> 2.0)

BUNDLED WITH
   1.11.2

我打赌您使用了
Gemfile
优化技术来处理
Docker
,这就是您的
Dockerfile
中的内容:

COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install --without development test
这种方法的问题在于,这条线

BUNDLE_WITHOUT: development:test
已写入
/tmp/.bundle/config
文件,执行
Bundler.setup
时,
Bundler
无法访问该文件

因此,一种可能的解决方案是将这一行添加到您的
Dockerfile
(将其添加到切换后的工作目录到应用目录中):

另一种方法是

RUN bundler config without development:test

但是看起来bundler解析GEM文件,这个命令在我的机器上需要5秒,所以我决定坚持使用
printf

如果你打开
application.rb
并添加
put Rails.groups.inspect
bundler.require
行之前,你会得到什么?我怀疑
test
组将在这些组中。@BoraMa我不确定我们是否已经走到了这一步,因为docker日志或STDOUT中都没有显示任何内容。我尝试了
put
方法和
%x(echo#{Rails.groups.inspect})
,但运气不佳。此外,此错误的第一个实例甚至在尝试启动服务器之前就会弹出。我已经编辑了我的原始消息以包含确切的输出。@BoraMa当我安装所有gems组时,
将Rails.groups.inspect
放在
Bundler.require
之前,只有预期的组存在(默认值&)。看起来是在引导过程的早期。谢谢!该命令实际上是
runbundle-config而不是development:test
BUNDLE_WITHOUT: development:test
RUN mkdir -p .bundle && printf '%s\n%s\n' '---' 'BUNDLE_WITHOUT: development:test' > .bundle/config
RUN bundler config without development:test