forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
441 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
html/ | ||
pkg/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# stripe-ruby-mock | ||
|
||
* Homepage: https://github.com/mindeavor/stripe-ruby-mock#readme | ||
* Issues: https://github.com/mindeavor/stripe-ruby-mock/issues | ||
|
||
## Install | ||
|
||
$ gem install stripe-ruby-mock | ||
|
||
## Features | ||
|
||
* Easily test against stripe errors | ||
* No stripe server access required | ||
|
||
## Description | ||
|
||
** *WARNING: THIS LIBRARY IS INCOMPLETE* ** | ||
|
||
At its core, this library overrides [stripe-ruby's](https://github.com/stripe/stripe-ruby) | ||
request method to skip all http calls and | ||
instead directly return test data. This allows you to write and run tests | ||
without the need to actually hit stripe's servers. | ||
|
||
You can use stripe-ruby-mock with any ruby testing library. Here's a quick dummy example with RSpec: | ||
|
||
require 'stripe' | ||
require 'stripe_mock' | ||
|
||
describe MyApp do | ||
before { StripeMock.start } | ||
after { StripeMock.stop } | ||
|
||
it "should create a stripe customer" do | ||
|
||
# This doesn't touch stripe's servers nor the internet! | ||
customer = Stripe::Customer.create({ | ||
email: '[email protected]', | ||
card: 'void_card_token' | ||
}) | ||
expect(customer.email).to eq('[email protected]') | ||
end | ||
end | ||
|
||
## TODO | ||
|
||
* Cover all stripe urls/methods | ||
* Mock stripe error responses | ||
* Create hash for storing/retrieving stripe objects in-memory | ||
|
||
## Copyright | ||
|
||
Copyright (c) 2013 Gilbert | ||
|
||
See LICENSE.txt for details. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'stripe_mock/version' | ||
require 'stripe_mock/data' | ||
require 'stripe_mock/methods' | ||
|
||
module StripeMock | ||
|
||
@@init = false | ||
@@enabled = false | ||
|
||
def self.start | ||
if @@init == false | ||
@@request_method = Stripe.method(:request) | ||
@@init = true | ||
end | ||
alias_stripe_method :request, Methods.method(:mock_request) | ||
@@enabled = true | ||
end | ||
|
||
def self.stop | ||
return unless @@enabled == true | ||
alias_stripe_method :request, @@request_method | ||
@@enabled = false | ||
end | ||
|
||
def self.alias_stripe_method(new_name, method_object) | ||
Stripe.define_singleton_method(new_name) {|*args| method_object.call(*args) } | ||
end | ||
|
||
end |
Oops, something went wrong.