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

前端之家收集整理的这篇文章主要介绍了ruby轨道 – 轨道测试箱固定装置未加载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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有灯具:全部在里面,我还添加显示灯具的负载(见上图).是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 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)时,没有加载灯具.但是运行测试时
ruby -Itest /test/unit/foo.rb

灯具按预期加载.

猜你在找的Ruby相关文章