未初始化常量 Test::Unit::TestResult::TestResultFailureSupport

发布于 2024-08-06 05:14:47 字数 1016 浏览 7 评论 0原文

当我尝试在新的 Rails 项目中运行规范或生成器时,我在主题中收到错误。

当我将“应该”添加到混合物中时,就会发生这种情况。

我在 config/environment.rb 中添加了以下内容:

config.gem 'rspec', :version => '1.2.6', :lib => false
config.gem 'rspec-rails', :version => '1.2.6', :lib => false
config.gem "thoughtbot-shoulda", :version => "2.10.2", :lib => 'shoulda', :source => "http://gems.github.com"

我使用的是 OSX。

  • ruby 1.8.6 (2008-08-11 patchlevel 287)
  • gems 1.3.5
  • Rails 2.3.4
  • rspec - 1.2.6
  • Shoulda - 2.10.2
  • test-unit - 2.0.3

我知道 这个并添加config.gem 'test-unit', :lib => 'test/unit' 确实解决了生成器问题,因为它不会抛出异常,但它打印 0 个测试,0 个断言,0 个失败,0 个错误,0 个待处理,0 个遗漏,0 个通知< /code> 在运行结束时,所以我想它会尝试运行意外和不需要的测试,并且规范完全停止运行,看起来 rspec 根本没有运行,当运行 rake spec 我再次得到测试单元输出(0个测试,因为只有规格,没有定义测试)

I get the error in subj when I'm trying to run specs or generators in a fresh rails project.

This happens when I add shoulda to the mix.

I added the following in the config/environment.rb:

config.gem 'rspec', :version => '1.2.6', :lib => false
config.gem 'rspec-rails', :version => '1.2.6', :lib => false
config.gem "thoughtbot-shoulda", :version => "2.10.2", :lib => 'shoulda', :source => "http://gems.github.com"

I'm on OSX.

  • ruby 1.8.6 (2008-08-11 patchlevel 287)
  • gems 1.3.5
  • rails 2.3.4
  • rspec - 1.2.6
  • shoulda - 2.10.2
  • test-unit - 2.0.3

I'm aware of this and adding config.gem 'test-unit', :lib => 'test/unit' indeed solves the genrator problem as it doesn't throw an exception, but it prints 0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications at the end of the run so I suppose it tries to run tests which is unexpected and undesired, also the specs stop to run at all, seems like rspec is not running at all, when running rake spec I get the test-unit output again (with 0 tests as there are only specs, no tests defined)

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

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

发布评论

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

评论(3

负佳期 2024-08-13 05:14:47

我最近遇到了类似的问题,并追踪到 ruby​​gems 中的此提交:

http://github。 com/vvs/rubygems/commit/cbb4b07d491dd49b8dff8ab7af706dde31307c7d

如果存在“测试单元”gem,则加载它,如果不存在,则默默地继续前进。此更改的作者可能没有意识到一个基本事实 - 激活宝石通常可以改变加载到系统中的其他宝石的行为。应用程序开发人员应该负责定义他们想要激活的宝石集; rubygems 系统本身决定选择性地加载 gem 是一个令人头疼的问题。

这个问题的另一半是为什么测试单元 gem 会干扰 rspec 的问题。我无法回答这个问题,但我确实追踪到没有注册任何ExampleGroups的事实,这反过来又是由于当Rspec动态创建ActiveSupport的新子类时,ExampleGroupMethods中的“继承”回调不会被调用: :TestCase(这发生在ExampleGroupMethods#subclass中)

I ran into a similar problem recently and traced it to this commit in rubygems:

http://github.com/vvs/rubygems/commit/cbb4b07d491dd49b8dff8ab7af706dde31307c7d

Which loads the 'test-unit' gem if it is there, or silently moves on if it's not. The author of this change perhaps is not aware of a fundamental truth - that activating a gem can often change the behavior of other gems loaded into the system. Application developers should be in charge of defining the set of gems they want activated; that the rubygems system itself decides to optionally load a gem is a head-scratcher.

The other half of this problem is the question of why the test-unit gem interferes with rspec. This I can't answer, but I did trace it to the fact that no ExampleGroups get registered, which in turn is due the fact that the "inherited" callback in ExampleGroupMethods does not get called when Rspec dynamically creates a new subclass of ActiveSupport::TestCase (this happens in ExampleGroupMethods#subclass)

祁梦 2024-08-13 05:14:47

根据我在此处,看来问题并不是 RSpec 在所有版本的测试单元中都消失了,只是它与较新的版本不兼容。因此,完全卸载测试单元是一种解决方法。但是,如果这不适合您(因为它不适合我),您可以安装旧版本(例如 1.2.3),并确保它在 rspec 之前加载。

例如,我的环境/test.rb 文件中有此内容,并且测试再次运行:

config.gem 'test-unit'  , :lib => 'test/unit',  :version => '<2.0'
config.gem "rspec",       :lib => false, :version => '<2.0'
config.gem "rspec-rails", :lib => false, :version => '<2.0'

Based on a conversation I found here, it seems the issue isn't that RSpec dies with all versions of test-unit, only that it's incompatible with newer ones. So, uninstalling test-unit altogether is one workaround. But, if that's not an option for you (as it isn't for me) you can install an older version (ex. 1.2.3), and simply make sure it's loaded before rspec is.

For example, I have this in my environment/test.rb file, and the tests are running again:

config.gem 'test-unit'  , :lib => 'test/unit',  :version => '<2.0'
config.gem "rspec",       :lib => false, :version => '<2.0'
config.gem "rspec-rails", :lib => false, :version => '<2.0'
听风念你 2024-08-13 05:14:47

test-unit 实际上内置于 Ruby 中,因此删除 gem 会依赖于 Ruby 的内置版本。除非您需要一些特殊的东西未包含在默认测试单元中,否则我不会太担心这一点。

test-unit is actually built into Ruby so removing the gem falls back on Ruby's built-in version. Unless there's something special that you need that's not included in the default test-unit then I wouldn't worry about this too much.

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