在rspec中无法测试上传文件

时间:2015-04-24 07:27:56

标签: ruby-on-rails rspec

我是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不存在

但我所给出的道路是正确的。

先谢谢。

1 个答案:

答案 0 :(得分:1)

尝试按照

替换路径变量
path = File.join('spec/fixtures', 'files', 'demo.png')