Greg Hauptmann
2007-Feb-05 01:58 UTC
[mocha-developer] Mock objects for stubbing out Paypal - anyone have any???
Hi, Just wondering if anyone has already developed a mocking approach to stub out the Paypal interface so that one can test on an internal PC which doesn''t provide a means for PayPal to callback to your webserver? (i.e. once the app is deployed to the hosting provider it would then work as PayPal could then hit the application with the specified URL). Anyone already solved this? Would mocca be a good way to achieve this? (basically the rails app has to receive a URL request from PayPal, send a confirmation back to PayPal and receive a response - i.e. overall the app therefore has to respond to a URL request, make HTTP requests back to Paypal and process the response) Tks Greg
James Mead
2007-Feb-05 11:06 UTC
[mocha-developer] Mock objects for stubbing out Paypal - anyone have any???
On 05/02/07, Greg Hauptmann <greg.hauptmann.ruby at gmail.com> wrote:> > Just wondering if anyone has already developed a mocking approach to stub > out the Paypal interface so that one can test on an internal PC which > doesn''t provide a means for PayPal to callback to your webserver? (i.e. > once the app is deployed to the hosting provider it would then work as > PayPal could then hit the application with the specified URL). > > Anyone already solved this? Would mocca be a good way to achieve this? > (basically the rails app has to receive a URL request from PayPal, send a > confirmation back to PayPal and receive a response - i.e. overall the app > therefore has to respond to a URL request, make HTTP requests back to > Paypal > and process the response). >Hi Greg, Although we haven''t specifically done this with the PayPal interface, we have done it with other external services e.g. Amazon ECS. I''ve found the best approach is to build an adapter object or layer that presents the external service as a simple interface for the rest of your application to use. Then you can use a mock library such as Mocha to set up expectations for tests where you expect calls to the PayPal interface to be made. In other tests you can simply stub the interface. You may also want to have unit tests for the internals of your PayPal adapter and Mocha can also be used to stub significant methods within your adapter layer to e.g. inject an expected http response. Also I''m sure there are already PayPal ruby libraries out there - just try googling for "paypal ruby". -- James. http://blog.floehopper.org