For my projects, I usually end up creating at least three separate Stripe sub-accounts: one for development (for testing by hand), one for testing (automated tests), and one for production.

Once you go ahead and create these sub-accounts, save their API credentials to your environment (.bashrc for Linux and .bash_profile for Mac).

I set up my Stripe initializer in Rails like this (config/initializers/stripe.rb):

The two methods defined under spec/support/clear_stripe.rb will run between and after test suites to ensure that each test run will be in isolation and against a clean slate on Stripe’s end.

They will clear Stripe’s customer, pricing, and product data, so make sure they cannot be invoked in production!


Mock Stripe Where It Makes Sense to Do So

Making live requests to Stripe in the test suite can give you greater confidence in your application, but it can be very time-consuming as your application grows. To avoid this, I use a gem called stripe-ruby-mock:

#programming #rspec #ruby #stripe #ruby-on-rails

Test-Driven Development With Stripe and Ruby on Rails
5.50 GEEK