【问题标题】:Unable test uploading of files in rspec无法在 rspec 中测试上传文件
【发布时间】:2015-04-24 07:27:56
【问题描述】:

我是 Rails 和 Rspec 的新手。我的spec文件有如下场景

scenario "Admin creates a new Specification ", js: true do
  sign_in_with admin_user
  visit "/general_docs/new"
  fill_in "general_doc_name", :with => "Specifications1"
  set_live_search_select_value_for('#general_doc_course_id', Course.first.id)
  select "Specifications", :from=> "general_doc[doc_type]"
  select  "student", :from=> "general_doc[user_role_id]"
  check "general_doc_active"
  path = "/Home/workspace/ums/spec/fixtures/files/demo.png"
  attach_file "multiple_file_uploader_url", path
  click_button "Create General doc"
expect(page).to have_content "Document was successfully created."
  end

我收到以下错误。 失败/错误:attach_file“multiple_file_uploader_url”,路径 水豚::FileNotFound: 无法附加文件,/Home/workspace/ums/spec/fixtures/files/demo.png 不存在

但是我给出的路径是正确的。

提前致谢。

【问题讨论】:

    标签: ruby-on-rails rspec


    【解决方案1】:

    尝试通过以下方式替换您的 path 变量

    path = File.join('spec/fixtures', 'files', 'demo.png')
    

    【讨论】:

    • 您好,感谢您的回答,但问题仍然存在。它给出了同样的错误。我仔细检查了文件路径(即文件存在于指定路径中)。
    • 您好,我将 attach_file 的参数从“multiple_file_uploader_url”更改为“multiplefileuploader”,并将文件的路径从“spec/fixtures”更改为“spec”,但现在我得到一个不同的错误:= > 错误如下Failure/Error: attach_file "multiplefileuploader", File.join('spec', 'demo.png') Capybara::ElementNotFound: Unable to find file field "multiplefileuploader"
    • 回答者错过了文件目录,应该是:path = File.join('spec/fixtures', 'files', 'demo.png')
    • 是的,我错过了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多