2009-10-26 84 views
1

为Rails应用程序测试文件上传的最佳方式是什么?我目前使用Paperclip进行上传,但我想这并没有太大的区别。如何在Rails中为文件上传创建集成测试?

我应该甚至创建文件上传测试,还是更好地将它全部存根并且不要创建任何真正的上传测试

说我有一些测试只是为了上传。 我还应该在我的测试中涵盖裁剪吗?

什么是测试图像裁剪的最佳方法?

回答

2

黄瓜Webrat给你的步骤:

When I attach the file at "spec/fixtures/fugu.png" to "file" 

您可以在功能使用。有关the official Cucumber site is very helpful的更多信息。

其次,要测试的裁剪,你可以编写这一个自定义步骤:

Then /^the image "(.*?)" should be (\d+)x(\d+)$/ do |id, width, height| 
    image = Nokogiri::HTML(response.body).css("##{id}") 
    image["width"].should eql(width) 
    image["height"].should eql(height) 
end