rspec 测试载波
我正在制作一个 Rails 3.1 应用程序,使用 Carrierwave 将文件上传到 aws s3。我已按照 Carrierwave GitHub 存储库上的说明进行操作,现在可以将文件上传到我的 aws 存储桶。正是这些测试让我陷入困境。
在过去的两天里,我一直在谷歌上搜索和修改,使用我找到的所有其他问答,但最后我哭了“妈妈”。这是我得到的:
/app/uploaders/image_file_uploader.rb
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
/config/initializers/rierwave.rb
if Rails.env.test? or Rails.env.cucumber?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
end
/spec/uploaders/image_file_uploader_spec.rb
require 'spec_helper'
require 'support/fog_helper'
require 'carrierwave/test/matchers'
describe ImageFileUploader do
include CarrierWave::Test::Matchers
before do
ImageFileUploader.enable_processing = true
@user = Factory(:user, :email => "[email protected]")
@uploader = ImageFileUploader.new(@user, Factory(:image))
@uploader.store!(File.open("#{Rails.root}/tmp/uploads/#{Rails.env}/images/"))
end
after do
@uploader.remove!
ImageFileUploader.enable_processing = false
end
context 'the tiny version' do
it "should scale down a landscape image to be exactly 50 by 50 pixels" do
@uploader.tiny.should have_dimensions(50, 50)
end
end
spec/factories.rb
Factory.define :image do |image|
include ActionDispatch::TestProcess
image.date_taken "Sun, 09 Oct 2011"
image.time_taken "2000-01-01 03:41:00 UTC"
image.image_file fixture_file_upload('spec/support/test_images/audi.png', 'image/png')
image.taken_by "John Doe"
image.collection "N/A"
image.comments "Beautiful day!"
image.association :user
end
当我的 /public/uploads/tmp/ 被填满时我正在测试其生成的图像的“微小”(和其他版本),测试继续失败,并显示以下错误消息:
- ImageFileUploader 微小版本应该将横向图像缩小到恰好 50 x 50 像素
Failure/Error: @uploader = ImageFileUploader.new(@user, Factory(:image))
Excon::Errors::NotFound:
Expected(200) <=> Actual(404 Not Found)
request => {:expects=>200}
response => #<Excon::Response:0x0000010569f928 @body="", @headers={}, @status=404>
# ./spec/uploaders/image_file_uploader_spec.rb:11:in `block (2 levels) in <top (required)>'
我知道上述内容意味着 rspec 找不到我的测试桶。有人对我做错了什么有任何想法吗?
将非常感谢任何新的线索。
更新:2011 年 10 月 11 日 文件上传有效,但我在弄清楚如何通过涉及图像的测试方面陷入停滞。在短期内,我将使用占位符图像来充实我的应用程序的其余部分,并稍后返回到此。一旦我弄清楚这一点,我将发布进一步的更新。 (但是,如果您有任何见解,请留下任何想法。)
I'm making a rails 3.1 app using carrierwave to upload files to aws s3. I've followed the instructions on the carrierwave github repository and am now able to upload files to my aws bucket. It's the testing that got me stuck.
Over the last two days I've been googling and revising, using all the other Q&A's I've found but am finally crying 'mama.' Here's what I've got:
/app/uploaders/image_file_uploader.rb
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
/config/initializers/carrierwave.rb
if Rails.env.test? or Rails.env.cucumber?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
end
/spec/uploaders/image_file_uploader_spec.rb
require 'spec_helper'
require 'support/fog_helper'
require 'carrierwave/test/matchers'
describe ImageFileUploader do
include CarrierWave::Test::Matchers
before do
ImageFileUploader.enable_processing = true
@user = Factory(:user, :email => "[email protected]")
@uploader = ImageFileUploader.new(@user, Factory(:image))
@uploader.store!(File.open("#{Rails.root}/tmp/uploads/#{Rails.env}/images/"))
end
after do
@uploader.remove!
ImageFileUploader.enable_processing = false
end
context 'the tiny version' do
it "should scale down a landscape image to be exactly 50 by 50 pixels" do
@uploader.tiny.should have_dimensions(50, 50)
end
end
spec/factories.rb
Factory.define :image do |image|
include ActionDispatch::TestProcess
image.date_taken "Sun, 09 Oct 2011"
image.time_taken "2000-01-01 03:41:00 UTC"
image.image_file fixture_file_upload('spec/support/test_images/audi.png', 'image/png')
image.taken_by "John Doe"
image.collection "N/A"
image.comments "Beautiful day!"
image.association :user
end
While my /public/uploads/tmp/ is getting filled up with 'tiny' (and other versions) of the images whose generation I am testing, the tests continue to fail with the following error message:
- ImageFileUploader the tiny version should scale down a landscape image to be exactly 50 by 50 pixels
Failure/Error: @uploader = ImageFileUploader.new(@user, Factory(:image))
Excon::Errors::NotFound:
Expected(200) <=> Actual(404 Not Found)
request => {:expects=>200}
response => #<Excon::Response:0x0000010569f928 @body="", @headers={}, @status=404>
# ./spec/uploaders/image_file_uploader_spec.rb:11:in `block (2 levels) in <top (required)>'
I know that the above means that rspec isn't finding my testing bucket. Anyone have any thoughts about what I'm doing wrong?
would be super grateful for any new leads.
UPDATE: 10/11/11
The file upload works but I've stalled in figuring out how to get test involving the images to pass. In the short term, I will use a placeholder image as I flesh out the rest of my app and return to this later. I'll post a further update once I figure this out. (Do leave any thoughts if you have any insights, however.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过这个吗?
在
/app/uploaders/image_file_uploader.rb
中删除storage :fog
在
/config/initializers/rierwave.rb
中添加与测试和测试类似的用于生产的配置块黄瓜,并在那里设置 config.storage = :fog。Have you tried this?
In
/app/uploaders/image_file_uploader.rb
removestorage :fog
In
/config/initializers/carrierwave.rb
add a similar configuration block for production as you have for test and cucumber, and setconfig.storage = :fog
there.