ruby轨道 – 轨道测试箱固定装置未加载

前端之家收集整理的这篇文章主要介绍了ruby轨道 – 轨道测试箱固定装置未加载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Rails似乎没有加载任何装置或功能测试的夹具.我有一个简单的’products.yml’,解析并显示正确:
  1. ruby:
  2. title: Programming Ruby 1.9
  3. description:
  4. Ruby is the fastest growing and most exciting dynamic
  5. language out there. If you need to get working programs
  6. delivered fast,you should add Ruby to your toolBox.
  7. price: 49.50
  8. image_url: ruby.png

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

  1. require 'test_helper'
  2.  
  3. class ProductsControllerTest < ActionController::TestCase
  4. fixtures :products
  5.  
  6. setup do
  7. @product = products(:one)
  8. @update = {
  9. :title => 'Lorem Ipsum',:description => 'Wibbles are fun!',:image_url => 'lorem.jpg',:price => 19.95
  10. }
  11. end

根据这本书,Rails应该“神奇地”加载灯具(因为我的test_helper.rb有灯具:全部在里面,我还添加显示灯具的负载(见上图).是Rails抱怨:

  1. user @ host ~/DropBox/Rails/depot > rake test:functionals
  2. (in /Somewhere/Users/user/DropBox/Rails/depot)
  3. /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"
  4. 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
  5. Started
  6. EEEEEEE
  7. Finished in 0.062506 seconds.
  8.  
  9. 1) Error:
  10. test_should_create_product(ProductsControllerTest):
  11. NoMethodError: undefined method `products' for ProductsControllerTest:Class
  12. /test/functional/products_controller_test.rb:7
  13.  
  14. 2) Error:
  15. test_should_destroy_product(ProductsControllerTest):
  16. NoMethodError: undefined method `products' for ProductsControllerTest:Class
  17. /test/functional/products_controller_test.rb:7
  18. ...

我确实遇到了其他Rails测试夹具问题Rails unit testing doesn’t load fixtures,但这导致了一个插件问题(与加载灯具的顺序有关).

BTW,我正在Mac OS X 10.6与Rail 2.3.5和Ruby 1.8.7开发,没有额外的插件(超出基本安装).

任何关于如何调试的指针,为什么Rails的魔法似乎在这里失败?是版本问题吗?我可以跟踪代码到库中找到答案吗?有很多“mixin”模块,我找不到fixtures方法真正存在的位置.

解决方法

使用Rails 3.2,我发现运行单个测试文件(指定TEST = / test / unit / foo.rb)时,没有加载灯具.但是运行测试时
  1. ruby -Itest /test/unit/foo.rb

灯具按预期加载.

猜你在找的Ruby相关文章