Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use fake_braintree for testing a rails app given that non-test code hits the actual Braintree API

I'm having some trouble testing a Braintree rails app using fake_braintree. I'm not using rspec, and maybe that is part of the problem.

In my tests, I interact with FakeBraintree---adding customers there, etc... But in the non-test code, I pull data from the Braintree API itself. Thus, when my tests hits the non-tests code, the code connects to the Braintree Sandbox, but (of course) the customer created via FakeBraintree is not there. It doesn't seem to me that I want to do anything atypical, and I'm unclear how I should be using fake_braintree, and having trouble finding clear documentation. Maybe the problem is trying to do this without using rspec?

thanks!

like image 388
bissej Avatar asked Jan 27 '26 19:01

bissej


1 Answers

I came back to this after some time, and the solution was surprising (or to me at least). If the test environment has access to the Braintree sandbox, then it connects there rather than fake_braintree. So in order to get the tests with fake_braintree to work, I had to reconfigure my configurations so that the braintree configuration variables were not set for the test environment.

like image 142
bissej Avatar answered Jan 30 '26 13:01

bissej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!