Post via Capybara and Poltergiest for API testing

721 Views Asked by At

What's the best way to generate a post request to test an API. Sadly, this won't work since there is no form to submit: create a post request using poltergeist and capybara

2

There are 2 best solutions below

0
On

Never mind, just added a post method to the poltergiest driver:

https://github.com/nathantsoi/poltergeist

use it with:

Gemfile:

gem 'capybara', '~> 2.4.4'
gem 'poltergeist', github: 'nathantsoi/poltergeist'

Tests:

page.driver.browser.post 'https://vertile.com/api/client/v1/stuff.json', { email: '[email protected]', awesomeness: '1000%' }
0
On

If you're testing an API there's no need for Poltergeist.

Poltergeist is useful for testing web pages with Javascript on them without a browser so it can run headless.

We use the Faraday gem to generate all the RESTful calls, GET, POST and etc to an API. But Httparty is just as good, or even bare net/http