2

我正在为使用回形针的图像上传器编写单元测试。它很颠簸,我慢慢地想着障碍,直到我被困在回形针::几何课上

这是我下面的代码

 require 'test_helper'
 require File.join(File.dirname(__FILE__),"../../config/initializers","paperclip")    

 class PhotoTest < ActiveSupport::TestCase
 #include ActionController::TestProcess

 should_belong_to(:product)
 should_have_attached_file :data

 setup do
   #I had to do this way because the include right below the class line was not working 
   image = Photo.create(:data => ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + "base-production-pack.png",'image/png')) 
   @geo = Paperclip::Geometry.from_file(image)
 end
end

回形针::geometry 给了我错误:

test: Photo should have a paperclip attachment named #data. (PhotoTest):
Paperclip::NotIdentifiedByImageMagickError: #<Photo:0x1054aa6b8> is not recognized by the 'identify' command.
paperclip (2.3.6) lib/paperclip/geometry.rb:24:in `from_file'
/test/unit/photo_test.rb:13

我有一个初始化文件“paperclip.rb”,它指向我本地机器上的标识

提前致谢

4

1 回答 1

2

Paperclip::Geometry.from_file需要一条路径,所以你应该这样做:

Paperclip::Geometry.from_file(image.data.path)

旁注:您正在测试很好,但是测试回形针的几何方法没有什么意义,因为回形针的测试套件涵盖了这一点。您的测试应涵盖您的代码预期执行的操作(例如确认缩略图按预期调整大小)。

于 2011-02-19T08:05:18.437 回答