铁路测试用例夹具未加载

发布于 2024-09-04 15:57:17 字数 2186 浏览 6 评论 0原文

Rails 似乎没有加载任何用于单元或功能测试的固定装置。我有一个简单的“products.yml”,可以解析并显示正确:

ruby:
  title: Programming Ruby 1.9
  description:
    Ruby is the fastest growing and most exciting dynamic
    language out there. If you need to get working programs
    delivered fast, you should add Ruby to your toolbox.
  price: 49.50
  image_url: ruby.png

我的控制器功能测试开始于:

require 'test_helper'

class ProductsControllerTest < ActionController::TestCase
  fixtures :products

  setup do
    @product = products(:one)    
    @update = {
      :title => 'Lorem Ipsum' ,
      :description => 'Wibbles are fun!' ,
      :image_url => 'lorem.jpg' ,
      :price => 19.95
    }
  end

根据这本书,Rails 应该“神奇地”加载固定装置(因为我的 test_helper.rb 有 < code>fixtures:all 在其中我还添加了显式的固定装置负载(见上文)是的 Rails 抱怨:

user @ host ~/Dropbox/Rails/depot > rake test:functionals
(in /Somewhere/Users/user/Dropbox/Rails/depot)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/functional/products_controller_test.rb" 
Loaded suite /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
Started
EEEEEEE
Finished in 0.062506 seconds.

  1) Error:
test_should_create_product(ProductsControllerTest):
NoMethodError: undefined method `products' for ProductsControllerTest:Class
    /test/functional/products_controller_test.rb:7

  2) Error:
test_should_destroy_product(ProductsControllerTest):
NoMethodError: undefined method `products' for ProductsControllerTest:Class
    /test/functional/products_controller_test.rb:7
...

我确实遇到了其他 Rails 测试固定装置问题 Rails 单元测试不加载固定装置,但这会导致插件问题(与加载固定装置的顺序有关)。

一句,我正在 Mac OS X 10.6 上使用 Rail 2.3.5 和 Ruby 1.8.7 进行开发,没有额外的插件(除了基本安装之外)。

顺便说 似乎在这里失败了?我可以跟踪代码到库中并找到答案吗?有很多“mixin”模块,我找不到 fixtures 方法的真正位置。 。

Rails appears to not be loading any fixtures for unit or functional tests. I have a simple 'products.yml' that parses and appears correct:

ruby:
  title: Programming Ruby 1.9
  description:
    Ruby is the fastest growing and most exciting dynamic
    language out there. If you need to get working programs
    delivered fast, you should add Ruby to your toolbox.
  price: 49.50
  image_url: ruby.png

My controller functional test begins with:

require 'test_helper'

class ProductsControllerTest < ActionController::TestCase
  fixtures :products

  setup do
    @product = products(:one)    
    @update = {
      :title => 'Lorem Ipsum' ,
      :description => 'Wibbles are fun!' ,
      :image_url => 'lorem.jpg' ,
      :price => 19.95
    }
  end

According to the book, Rails should "magically" load the fixtures (as my test_helper.rb has fixtures :all in it. I also added the explicit fixtures load (seen above). Yes Rails complains:

user @ host ~/Dropbox/Rails/depot > rake test:functionals
(in /Somewhere/Users/user/Dropbox/Rails/depot)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/functional/products_controller_test.rb" 
Loaded suite /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
Started
EEEEEEE
Finished in 0.062506 seconds.

  1) Error:
test_should_create_product(ProductsControllerTest):
NoMethodError: undefined method `products' for ProductsControllerTest:Class
    /test/functional/products_controller_test.rb:7

  2) Error:
test_should_destroy_product(ProductsControllerTest):
NoMethodError: undefined method `products' for ProductsControllerTest:Class
    /test/functional/products_controller_test.rb:7
...

I did come across the other Rails test fixture question Rails unit testing doesn't load fixtures, but that leads to a plugin issue (something to do with the order of loading fixtures).

BTW, I am developing on Mac OS X 10.6 with Rail 2.3.5 and Ruby 1.8.7, no additional plugins (beyond the base install).

Any pointers on how to debug, why the magic of Rails appears to be failing here? Is it a version problem? Can I trace code into the libraries and find the answer? There are so many "mixin" modules I can't find where the fixtures method really lives.

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

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

发布评论

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

评论(3

泛滥成性 2024-09-11 15:57:17

在 Rails 3.2 中,我发现运行单个测试文件(指定 TEST=/test/unit/foo.rb)时,装置不会加载。然而,当运行测试时,

ruby -Itest /test/unit/foo.rb

夹具会按预期加载。

With Rails 3.2, I find that when running a single test file (specifying TEST=/test/unit/foo.rb), the fixtures are not loaded. However when running the tests with

ruby -Itest /test/unit/foo.rb

the fixtures are loaded as expected.

や莫失莫忘 2024-09-11 15:57:17

使用 ruby​​ 1.8.7 和 Rails 2.1.1,我通过在 test_helper.rb 中设置 self.use_instantiated_fixtures = true 解决了该问题。

Using ruby 1.8.7 and rails 2.1.1, I resolved the issue by setting self.use_instantiated_fixtures = true in test_helper.rb.

内心激荡 2024-09-11 15:57:17

放弃后,我尝试在 Rail 3.0.0beta3 上重新安装/重建。这解决了问题。我只能假设这是某种版本不匹配。

Having given up, I tried a reinstall/rebuild onto rail 3.0.0beta3. this resolved the issue. I can only assume this was some kind of version mismatch.

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