How do you POST to a URL in Capybara?

前端 未结 8 612
无人及你
无人及你 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:29

    As others have said, there’s no direct way of doing a POST with Capybara because it’s all about browser interaction. For API testing, I’d very highly recommend the rspec_api_documentation gem.

    0 讨论(0)
  • 2020-11-28 10:36

    You could do this:

    rack_test_session_wrapper = Capybara.current_session.driver
    rack_test_session_wrapper.submit :post, your_path, nil
    
    • You can replace :post which whatever method you care about e.g. :put or :delete.
    • Replace your_path with the Rails path you want e.g. rack_test_session_wrapper.submit :delete, document_path(Document.last), nil would delete the last Document in my app.
    0 讨论(0)
提交回复
热议问题