stripe-ruby/test/test_helper.rb
Brandur 1e166d9be7 Fix Gem builds in CI
CI is failing for a number of Ruby versions because shoulda is pulling
in should-matchers, which then pulls in activesupport. activesupport's
new 5.0.0 version is being picked up, and that requires at least Ruby
2.2.2.

Luckily the solution is easy, we're not using shoulda-matchers, only
shoulda-context, so just tighten up our dependencies a little and the
problem goes away.
2016-07-01 15:44:32 -07:00

46 lines
1018 B
Ruby

require 'stripe'
require 'test/unit'
require 'mocha/setup'
require 'stringio'
require 'shoulda/context'
require File.expand_path('../test_data', __FILE__)
# monkeypatch request methods
module Stripe
@mock_rest_client = nil
def self.mock_rest_client=(mock_client)
@mock_rest_client = mock_client
end
class << self
remove_method :execute_request
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 Stripe::TestData
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