如何用capybara附加文件?

时间:2015-07-16 06:59:13

标签: ruby file rspec tdd capybara

在我看来,我用这个:

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

在我的spec文件中,我尝试过:

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

但它说:

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

1 个答案:

答案 0 :(得分:0)

尝试 -

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