rake 不运行单元测试

发布于 2024-09-16 14:11:20 字数 2431 浏览 4 评论 0原文

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

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

如果我尝试使用以下命令运行一个单独的文件,它会执行相同的操作:rake -I"lib:test" test/unit/foo.rb 或使用autotest

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

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

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


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

我使用bundler的原因是为了在heroku上安装依赖项,并且因为我想使用来自github上的git存储库的gem。总而言之,我已经删除了捆绑器的预初始化程序,并重新使用 config.gem。为了解决我无法使用 config.gem 来使用 github 存储库的事实,我已将自己的副本推出到 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

I've upgraded my app from using config.gem to a Gemfile with bundler and have noticed that my unit tests have now stopped running. It's a bit strange and I'm not entirely sure where to start looking.

When I run rake test:units --trace I can see my environment being setup and it lists the files it intends to execute, but then it just returns.

It does the same thing if I try to run one individual file using something like: rake -I"lib:test" test/unit/foo.rb or using autotest.

It's all very strange. It's as if the files are being loaded but the actual unit tests are not being run.

I'm using shoulda and fast_context and I thought these might be the problem but if I include a unit test using the standard def test_ syntax it still doesn't get run so I don't think it's those.

Any hints or pointers would be greatly appreciated. I feel like I'm coding blind until I can get them working again!


So here's where I am now:

My reasons for using bundler are for installing dependencies on heroku and because I wanted to use a gem sourced from a git repo on github. The long and the short of it is that I've removed the preinitializer for bundler and have gone back to using config.gem. To get around the fact that I can't use a github repo using config.gem I've pushed out my own copy to rubygems. Was this the right move?


Here's the 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

I don't know how the .gems file would be useful because it's a heroku only thing and I'd have to hunt through git for it, but here's my 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惟欲睡 2024-09-23 14:11:21

您的 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)

Do you have this at the end of your config/boot.rb file:

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

(from http://gembundler.com/rails23.html)

偷得浮生 2024-09-23 14:11:21

我最近在运行一个项目的规范时遇到了麻烦。原因是我在 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)

I recently had trouble running specs for a project. The reason was that I was missing a line from config/application.rb. Nowadays that line pops in by default when you create a new rails 3 project, but if your project has been initialized some time ago it might be missing.

# 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)
末骤雨初歇 2024-09-23 14:11:20

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

Got the same problem.Just remove the gem 'hydra' will get the unit test back to normal

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文