好的,我已经搞清楚了。关键在于CarrierWaveDirect:
https://github.com/dwilkie/carrierwave_direct#using-capybara
我需要将以下这行代码添加到我的spec_helper.rb中:
include CarrierWaveDirect::Test::CapybaraHelpers
然后我的测试需要使用这些CarrierWaveDirect匹配器:
attach_file_for_direct_upload("#{Rails.root}/spec/support/images/example.jpg")
upload_directly(ImageUploader.new, "Upload Image")
因此,最终通过的测试看起来是这样的:
it "creates a new work with a test image" do
client = FactoryGirl.create(:client)
work = FactoryGirl.build(:work)
visit works_path
attach_file_for_direct_upload("#{Rails.root}/spec/support/images/example.jpg")
upload_directly(ImageUploader.new, "Upload Image")
fill_in "Name", :with => work.name
select("2012", :from => "work_date_1i")
select("December", :from => "work_date_2i")
select("25", :from => "work_date_3i")
select(client.name, :from => "work_client_ids")
fill_in "Description", :with => work.description
fill_in "Service", :with => work.service
save_and_open_page
check "Featured"
click_button "Create Work"
page.should have_content("Work was successfully created.")
end
我还需要将这个代码添加到我的 initializers/carrierwave.rb 文件中:
if Rails.env.test?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
end
与其嘲笑对雾的反应或测试上传至s3,我只是在测试环境中关闭了上传至s3。