test/test_helper.rb in stripe-1.58.0 vs test/test_helper.rb in stripe-2.0.0

- old
+ new

@@ -1,45 +1,41 @@ +require 'committee' +require 'sinatra' require 'stripe' require 'test/unit' require 'mocha/setup' require 'stringio' require 'shoulda/context' -require File.expand_path('../test_data', __FILE__) +require 'webmock/test_unit' -# monkeypatch request methods -module Stripe - @mock_rest_client = nil +PROJECT_ROOT = File.expand_path("../../", __FILE__) - def self.mock_rest_client=(mock_client) - @mock_rest_client = mock_client - end +require File.expand_path('../api_fixtures', __FILE__) +require File.expand_path('../api_stub_helpers', __FILE__) +require File.expand_path('../test_data', __FILE__) - 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 APIStubHelpers include Stripe::TestData include Mocha + # Fixtures are available in tests using something like: + # + # API_FIXTURES[:charge][:id] + # + API_FIXTURES = APIFixtures.new + setup do - @mock = mock - Stripe.mock_rest_client = @mock Stripe.api_key = "foo" + + # Stub the Stripe API with a default stub. Note that this method can be + # called again in test bodies in order to override responses on particular + # endpoints. + stub_api + + stub_connect end teardown do - Stripe.mock_rest_client = nil Stripe.api_key = nil end end