【问题标题】:How to create unit test for Paperclip::Geometry?如何为 Paperclip::Geometry 创建单元测试?
【发布时间】:2011-01-06 04:57:27
【问题描述】:

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

下面是我的代码

 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”,它指向我本地机器上的标识

提前致谢

【问题讨论】:

    标签: ruby-on-rails unit-testing paperclip shoulda


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 2017-03-10
      • 1970-01-01
      相关资源
      最近更新 更多