【问题标题】:How to attach a file with capybara?如何使用水豚附加文件?
【发布时间】:2015-07-16 06:59:13
【问题描述】:

在我看来,我使用这个:

<%= file_field_tag 'my_file' %>
# html will be:
<input type="file" name="my_file" id="my_file" />

在我的规范文件中,我尝试了:

it 'file test' do
  attach_file 'my_file', 'my/file/path'
end

但它说:

Capybara::ElementNotFound:
  Unable to find file field "my_file"

【问题讨论】:

    标签: ruby file rspec tdd capybara


    【解决方案1】:

    试试-

      it 'file test' do
        post :my_file, avatar: fixture_file_upload('my/file/path', 'image/jpg')
        response.should be_success
      end
    

    【讨论】:

    • 谢谢。我想做的是attach_file,然后click_button,最后希望页面在下一页有特殊内容。我正在做一个功能测试:type: :feature,所以我不能使用post
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    相关资源
    最近更新 更多