Skip to content

Commit

Permalink
Basic request mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert committed Apr 29, 2013
1 parent 1595101 commit c613deb
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 64 deletions.
4 changes: 0 additions & 4 deletions .document

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
html/
pkg/
.DS_Store
2 changes: 2 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(The MIT License)

Copyright (c) 2013 Gilbert

Permission is hereby granted, free of charge, to any person obtaining
Expand Down
54 changes: 54 additions & 0 deletions README.md
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.
28 changes: 0 additions & 28 deletions README.rdoc

This file was deleted.

13 changes: 0 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ rescue LoadError => e
warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
end

begin
gem 'rdoc', '~> 3.0'
require 'rdoc/task'

RDoc::Task.new do |rdoc|
rdoc.title = "stripe-ruby-mock"
end
rescue LoadError => e
warn e.message
warn "Run `gem install rdoc` to install 'rdoc/task'."
end
task :doc => :rdoc

begin
gem 'rspec', '~> 2.4'
require 'rspec/core/rake_task'
Expand Down
1 change: 0 additions & 1 deletion lib/stripe/mock.rb

This file was deleted.

6 changes: 0 additions & 6 deletions lib/stripe/mock/version.rb

This file was deleted.

29 changes: 29 additions & 0 deletions lib/stripe_mock.rb
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
Loading

0 comments on commit c613deb

Please sign in to comment.