6

我已将我的应用程序从 using 升级config.gemGemfilewith bundler,并注意到我的单元测试现已停止运行。这有点奇怪,我不完全确定从哪里开始寻找。

当我运行时,rake test:units --trace我可以看到我的环境正在设置中,它列出了它打算执行的文件,但它只是返回。

如果我尝试使用类似:rake -I"lib:test" test/unit/foo.rb或使用autotest.

这一切都很奇怪。就好像正在加载文件但没有运行实际的单元测试。

我正在使用shoulda并且fast_context我认为这些可能是问题,但是如果我使用标准def test_语法包含一个单元测试,它仍然无法运行,所以我认为不是那些。

任何提示或指针将不胜感激。我觉得我在盲目编码,直到我能让它们再次工作!


所以这就是我现在的位置:

我使用 bundler 的原因是为了在 heroku 上安装依赖项,并且因为我想使用来自 github 上的 git repo 的 gem。总而言之,我已经删除了preinitializerfor bundler 并重新使用了config.gem. 为了解决我无法使用 github 存储库的事实,我config.gem将自己的副本推送到了 ruby​​gems。这是正确的举动吗?


这是 preinitializer.rb

begin
  require "rubygems"
  require "bundler"
rescue LoadError
  raise "Could not load the bundler gem. Install it with `gem install bundler`."
end

if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
  raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
   "Run `gem install bundler` to upgrade."
end

begin
  # Set up load paths for all bundled gems
  ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
  Bundler.setup
rescue Bundler::GemNotFound
  raise RuntimeError, "Bundler couldn't find some gems." +
    "Did you run `bundle install`?"
end

我不知道 .gems 文件会有什么用,因为它是 heroku 唯一的东西,我必须通过 git 寻找它,但这是我的 gemfile。

source :gemcutter

gem 'rails', '2.3.9'
gem 'pg'
gem 'minitest'
gem 'RedCloth'
gem 'erubis'
#gem 'memcached'
gem 'daemons'
gem 'resque'

gem 'inherited_resources', '1.0.6'
gem 'clearance', '0.8.8'
gem 'acl9'
gem 'sprockets'

gem 'aws-s3'
gem 'paperclip', '2.3.1.1'
gem 'rmagick', '2.12.2'

gem 'jonnii-cheddargetter', '0.1.3'

gem 'attribute_normalizer'

gem 'formtastic', '1.1.0.beta'
gem 'will_paginate', '2.3.14'

gem 'hoptoad_notifier'
gem 'mixpanel_client'

gem 'sunspot'
gem 'websolr-sunspot_rails'

gem 'geokit'
gem 'ri_cal'

gem 'jonnii-yelp'

group :development, :test do
  gem 'test-spec'
  gem 'shoulda'

  gem 'redgreen'
  gem 'factory_girl'
  gem 'populator'
  gem 'faker'

  gem 'ZenTest'
  gem 'autotest-rails'

  gem 'webrat'
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'parallel'
  gem 'hydra'
  gem 'heroku'
  gem 'taps'
  gem 'ruby-prof'
  gem 'treetop'
  gem 'rspec'
  gem 'rspec-rails'
end
4

3 回答 3

1

遇到了同样的问题。只需删除 gem 'hydra' 将使单元测试恢复正常

于 2010-12-02T13:29:58.723 回答
0

你在 config/boot.rb 文件的末尾有这个:

class Rails::Boot
  def run
    load_initializer

    Rails::Initializer.class_eval do
      def load_gems
        @bundler_loaded ||= Bundler.require :default, Rails.env
      end
    end

    Rails::Initializer.run(:set_load_path)
  end
end

(来自http://gembundler.com/rails23.html

于 2010-10-19T14:36:39.870 回答
0

我最近在为一个项目运行规范时遇到了麻烦。原因是我在 config/application.rb 中遗漏了一行。现在,当您创建新的 rails 3 项目时,默认情况下会弹出该行,但如果您的项目已在一段时间前初始化,则它可能会丢失。

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
于 2010-10-27T10:54:06.153 回答