mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-04 00:00:47 -04:00
Allow developers to use Stripe test data when stubbing responses locally. This should help mitigate the risk of API drift with stubbed responses. * Move response helpers to their own file
44 lines
957 B
Ruby
44 lines
957 B
Ruby
require 'stripe'
|
|
require 'test/unit'
|
|
require 'mocha/setup'
|
|
require 'stringio'
|
|
require 'shoulda'
|
|
|
|
# response helpers
|
|
require File.expand_path('../helpers', __FILE__)
|
|
|
|
# monkeypatch request methods
|
|
module Stripe
|
|
@mock_rest_client = nil
|
|
|
|
def self.mock_rest_client=(mock_client)
|
|
@mock_rest_client = mock_client
|
|
end
|
|
|
|
def self.execute_request(opts)
|
|
get_params = (opts[:headers] || {})[:params]
|
|
post_params = opts[:payload]
|
|
case opts[:method]
|
|
when :get then @mock_rest_client.get opts[:url], get_params, post_params
|
|
when :post then @mock_rest_client.post opts[:url], get_params, post_params
|
|
when :delete then @mock_rest_client.delete opts[:url], get_params, post_params
|
|
end
|
|
end
|
|
end
|
|
|
|
class Test::Unit::TestCase
|
|
include Helpers
|
|
include Mocha
|
|
|
|
setup do
|
|
@mock = mock
|
|
Stripe.mock_rest_client = @mock
|
|
Stripe.api_key="foo"
|
|
end
|
|
|
|
teardown do
|
|
Stripe.mock_rest_client = nil
|
|
Stripe.api_key=nil
|
|
end
|
|
end
|