Rails回形针宝石测试失败

时间:2013-12-04 14:00:12

标签: ruby-on-rails ruby unit-testing testing model-view-controller

rake test提出了这个问题:

  1) Error:
ProductsControllerTest#test_should_create_product:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "lorem.jpg"
    app/controllers/products_controller.rb:27:in `create'
    test/controllers/products_controller_test.rb:27:in `block (2 levels) in <class:ProductsControllerTest>'
    test/controllers/products_controller_test.rb:26:in `block in <class:ProductsControllerTest>'

  2) Error:
ProductsControllerTest#test_should_update_product:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "lorem.jpg"
    app/controllers/products_controller.rb:46:in `block in update'
    app/controllers/products_controller.rb:45:in `update'
    test/controllers/products_controller_test.rb:44:in `block in <class:ProductsControllerTest>'

,控制器如下所示:

def create
    @product = Product.new(product_params)
    @product.image = params[:product][:image]
    ....
end

,测试控制器如下所示:http://pastebin.com/j3fZwJNA

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

Rack::Test::UploadedFile用于测试文件和真实装置
像这样
Rack::Test::UploadedFile.new 'spec/fixtures/images/test.png', 'image/png'