测试Rails应用程序文件上传的最佳方法是什么?我目前正在使用Paperclip进行上传,但是我想那并没有太大的区别。
我是否应该为文件上传创建测试,还是仅将其全部存根而不创建任何实际的上传测试更好?
说我有一些仅用于上传的测试。我还应该在测试中涵盖种植吗?
测试图像裁剪的最佳方法是什么?
最佳答案
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
关于ruby-on-rails - 如何为Rails中的文件上传创建集成测试?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1627987/