好的,我已经想通了。关键是 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
我还需要将它添加到我的初始化程序/carrierwave.rb:
if Rails.env.test?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
end
我没有模拟对雾的响应,也没有测试对 s3 的上传,而是在测试环境中关闭了对 s3 的上传。