Skip to content

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

License

Notifications You must be signed in to change notification settings

Quimbee/fake_stripe

This branch is 7 commits ahead of, 4 commits behind thoughtbot/fake_stripe:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

aecd3ab · Dec 7, 2021

History

85 Commits
Oct 2, 2018
Dec 7, 2021
Feb 17, 2020
Oct 2, 2018
Jul 26, 2019
Apr 19, 2013
Oct 2, 2018
Dec 19, 2019
Dec 19, 2013
Oct 25, 2018
Nov 13, 2015
Apr 19, 2013
Aug 8, 2018

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.

Stripe settings

Set the STRIPE_JS_HOST constant in an initializer:

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

unless defined? STRIPE_JS_HOST
  STRIPE_JS_HOST = 'https://js.stripe.com'
end

Include the Stripe JavaScript in your application template.

For Stripe.js v1:

# app/views/layouts/application.html.erb
<%= javascript_include_tag "#{STRIPE_JS_HOST}/v1/" %>

For Stripe.js v2:

# app/views/layouts/application.html.erb
<%= javascript_include_tag "#{STRIPE_JS_HOST}/v2/" %>

For Stripe.js v3:

# app/views/layouts/application.html.erb
<%= javascript_include_tag "#{STRIPE_JS_HOST}/v3/" %>

When the test suite runs fake_stripe will override the address for STRIPE_JS_HOST 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 91.6%
  • JavaScript 8.4%