Question

I've written a successful cucumber and capybara test, which executes a purchase using paypal sandbox. However, I want stub paypal sandbox request so that my test isn't dependent on the paypal sandbox being up.

I'm not 100% familiar with Webmock and its documentation isn't very clear. When I added the Webmock gem, created the necessary webmock.rb with

require 'webmock/cucumber' WebMock.disable_net_connect!(:allow_localhost => true)

When I run my old cucumber test, it proceeds as normal opening paypal sandbox window and completing the transaction.

Is this normal? I though WebMock was supposed to shut out attempts to connecting to third party sites.

Was it helpful?

Solution

WebMock can intercept any http call made from the ruby code, but it can't control external web browser process doing redirects. You can use WebMock to intercept calls to Paypal API (Paypal Pro). If you use Paypal Website Payment Standard, then WebMock won't help.

You can create fake TestPaypalController in your application instead and configure your app in test environment to redirect to a local fake paypal url instead of real paypal url. Then you can assert the content of the fake page and parameters used to request that page.

The last step would be invoking a request to your application by simulating paypal payment notification from inside test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top