stripe-ruby-mock /stripe-ruby-mock

A mocking library for testing stripe ruby

★ 998⑂ 744👁 27⑃ 610● 358▤ 6
RubyMITCreated 2013-04-28
Download: v4.0.0v4.0.0 ↓4.0.02024-08-06
+0
Daily
998
stars
744
forks
27
watchers
610
prs
358
issues
6
releases

README

stripe-ruby-mock 

 Homepage: https://github.com/stripe-ruby-mock/stripe-ruby-mock
 Issues: https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues
 CHAT: https://gitter.im/rebelidealist/stripe-ruby-mock

 REQUEST: Looking for More Core Contributors

This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'm currently looking for more core contributors to help me out. If you're interested, there is only one requirement: submit a significant enough pull request and have it merged into master (many of you have already done this). Afterwards, ping @gilbert in chat and I will add you as a collaborator.

 Install

In your gemfile:

    gem 'stripe-ruby-mock'

 !!! Important

We have changelog. It's first attempt. Feel free to update it and suggest to a new format of it.

version 5.0.0 has breaking changes - we support stripe  5 and  5 and = 3.0.0
 stripe  5 &  'my_plan', :amount = 1500)

     The above line replaces the following:
     plan = Stripe::Plan.create(
       :id = 'my_plan',
       :name = 'StripeMock Default Plan ID',
       :amount = 1500,
       :currency = 'usd',
       :interval = 'month'
     )
    expect(plan.id).to eq('my_plan')
    expect(plan.amount).to eq(1500)
  end
end


The available helpers are:

ruby
stripe_helper.create_plan(my_plan_params)
stripe_helper.delete_plan(my_plan_params)
stripe_helper.generate_card_token(my_card_params)


For everything else, use Stripe as you normally would (i.e. use Stripe as if you were not using StripeMock).

 Live Testing

Every once in a while you want to make sure your tests are actually valid. StripeMock has a switch that allows you to run your test suite (or a subset thereof) against Stripe's live test servers.

Here is an example of setting up your RSpec (2.x) test suite to run live with a command line switch:

ruby
 RSpec 2.x
RSpec.configure do |c|
  if c.filter_manager.inclusions.keys.include?(:live)
    StripeMock.toggle_live(true)
    puts "Running live tests against Stripe..."
  end
end


With this you can run live tests by running rspec -t live

Here is an example of setting up your RSpec (3.x) test suite to run live with the same command line switch:

ruby
 RSpec 3.x
RSpec.configure do |c|
  if c.filter_manager.inclusions.rules.include?(:live)
    StripeMock.toggle_live(true)
    puts "Running live tests against Stripe..."
  end
end


 Mocking Card Errors
 Ensure you start StripeMock in a before filter StripeMock.start
Tired of manually inputting fake credit card numbers to test against errors? Tire no more!

ruby
it "mocks a declined card error" do
   Prepares an error for the next create charge request
  StripeMock.prepare_card_error(:card_declined)

  expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
    expect(e).to be_a Stripe::CardError
    expect(e.http_status).to eq(402)
    expect(e.code).to eq('card_declined')
  }
end


 Built-In Card Errors

ruby
StripeMock.prepare_card_error(:incorrect_number)
StripeMock.prepa

Top issues

Discussions

Latest release

v4.0.0 v4.0.0 2024-08-06
What's Changed
- 905 Allow Stripe SDK v11 by @stevenharman 
- 830 Implement search API by @adamstegman
- 848 Extending runtime dependency on Stripe gem from version 5 through 11 by @smakani
- 893 Adds support for stripe-ruby v10 by @fabianoarruda

Full Changelog: https://github.com/stripe-ruby-mock/stripe-ruby-mock/compare/final-old-3-1-0...v4.0.0

Snapshot: 2026-11-27T22:26:53Z · Data license Apache-2.0 · JSON