Skip to content

tyler-rand/fake_stripe

 
 

Repository files navigation

fake_stripe, a Stripe fake

This library is a way to test Stripe code without hitting Stripe's servers. It uses Capybara::Server and Webmock to intercept all of the calls from Stripe's Ruby library and returns JSON that the Stripe library can parse.

Installation

Gemfile

Add the fake_stripe Gem to the :test group in your Gemfile:

# Gemfile
group :test do
  gem 'fake_stripe'
end

Remember to run bundle install.

Rails 5 Compatibility

fake_stripe depends on Sinatra, which is currently in the process of being upgraded to use Rack 2.0, a requirement for compatibility with Rails 5. This should be resolved once Sinatra 2.0 is officially released; in the meantime, you can add gem 'sinatra', '2.0.0.beta2' to the :test group in your Gemfile.

Stripe settings

# config/initializers/stripe.rb
Stripe.api_key = ENV['STRIPE_API_KEY']

Include the Stripe JavaScript in your application template.

If you're using Stripe.js v1:

# app/views/layouts/application.html.erb
<%= javascript_include_tag "https://js.stripe.com/v1/" %>

Or if you're using Stripe.js v2:

# app/views/layouts/application.html.erb
<%= javascript_include_tag "https://js.stripe.com/v2/" %>

When the test suite runs fake_stripe will intercept requests to the Stripe address and serve up a local version of Stripe.js.

In Tests

Require the library in your spec support:

# spec/support/fake_stripe.rb
require 'fake_stripe'

RSpec.configure do |config|
  config.before(:each) do
    FakeStripe.stub_stripe
  end
end

Contributing

Please see CONTRIBUTING.md for more details.

About

A Stripe fake so that you can avoid hitting Stripe servers in tests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 94.6%
  • JavaScript 5.4%