Testing the JavaScript via Capybara

If you run the tests without making further changes to them, the end-to-end test in spec/features/purchase_cart_spec.rb will fail. By default, our Capybara-driven feature specs don’t use JavaScript, which means the client side of the form can’t request a token. And if we don’t have a token, the form fails.

In order to make the test pass, we need to run the test inside a container that executes JavaScript. We can do that by setting a JavaScript driver for Capybara, which means Capybara runs the test in a headless web browser engine that includes JavaScript. The Capybara driver we’re using is called Poltergeist.[21] Poltergeist connects Capybara to the PhantomJS headless browser, which you also need to install; ...

Get Take My Money now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.