ruby-on-rails – 用Capybara和Rspec测试载波文件上传到s3
像在
this Railscast那样,我已经将载波文件上传到了Amazon S3.
我有麻烦测试这个.我可以附加一个文件与水豚,但当我点击按钮上传它不会重定向到正确的行动.我用save_and_open_page检查,而是显示主页. 当我在浏览器中测试它可以正常工作,但s3上传的信息确实添加到url(screenshot).不知道为什么这在测试中不起作用. 以下是一些相关文件: example_spec.rb – https://gist.github.com/leemcalilly/1e159f1b93005b8113f2 initializers / carrierwave.rb – https://gist.github.com/leemcalilly/924e8755f7c76ecbf5cf models / work.rb – https://gist.github.com/leemcalilly/cfda1a7f15d87dbab731 controllers / works_controller.rb – https://gist.github.com/leemcalilly/7fca5f2c81c6cb4de6bc 我怎么能用capybara和rspec来测试这种形式? 解决方法
好的,我已经弄清楚了.关键是CarrierWaveDirect:
https://github.com/dwilkie/carrierwave_direct#using-capybara 我需要将此行添加到我的spec_helper.rb中: 包括CarrierWaveDirect :: Test :: CapybaraHelpers 然后我的测试需要这些CarrierWaveDirect匹配器: attach_file_for_direct_upload( “#{Rails.root} /spec/support/images/example.jpg”) 所以最后的通过测试看起来像这样: 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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ruby-on-rails – 从S3下载Carrierwave上传
- flutter – 子类化一个扩展StatelessWidget或StatefulWidge
- PostgreSQL服务过程中的那些事二:Pg服务进程处理简单查询六
- 用正则表达式处理字符串中的分组问题
- reactor和proactor模式
- xml – 最好的免费XSLT编辑器为eclipse?
- OpenEIM 第一次接触和使用Sqlite
- cocos2dx3.4 新建项目不能用vs BabeLua调试
- About SWFObject generated by Flash Professional, and th
- 用正则表达式限制文本框只能输入数字,小数点,英文字母,汉字