How do you POST to a URL in Capybara?

前端 未结 8 646
无人及你
无人及你 2020-11-28 09:51

Just switched from Cucumber+Webrat to Cucumber+Capybara and I am wondering how you can POST content to a URL in Capybara.

In Cucumber+Webrat I was able to have a ste

8条回答
  •  温柔的废话
    2020-11-28 10:11

    Capybara's visit only does GET requests. This is by design.

    For a user to perform a POST, he must click a button or submit a form. There is no other way of doing this with a browser.

    The correct way to test this behaviour would be:

    visit "project/:id/edit" # This will only GET
    attach_file "photo", File.open('cute_photo.jpg')
    click_button 'Upload' # This will POST
    

    If you want to test an API, I recommend using spec/request instead of cucumber, but that's just me.

提交回复
热议问题