How to send XML file request using Capybara, and check response for correct parameters

228 Views Asked by At

I am writing acceptance tests using capybara/rspec. And I want in one of my tests send request using XML file and check that it got correct parameters in response. Do you know how I can write it please?

For now I send my request using curl.

curl -X POST -H 'Content-Type: application/xml' -H 'Authorization: Basic example' http://example/example --data-binary @request.xml

But I want to automate it using Capybara/rspec

1

There are 1 best solutions below

3
Thomas Walpole On BEST ANSWER

You don't do this with Capybara. Capybara is used for tests that replicate what a user would do via a browser. As such it interacts with elements in the browser and the page generates the requests a user would trigger. For what you want to test you should be looking at request specs (they don't use Capybara) which are aimed at testing APIs, etc. and allow for posts of random data to endpoints - https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec