Sha256: 373441524bfa64396799596cef3a168d866af922d4ab3b1f0629208b978dcffd

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

require 'payjp'
require 'test/unit'
require 'mocha/setup'
require 'stringio'
require 'shoulda'
require File.expand_path('../test_data', __FILE__)

# monkeypatch request methods
module Payjp
  @mock_rest_client = nil

  class << self
    attr_writer :mock_rest_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 Payjp::TestData
  include Mocha

  def encode_credentials(user_name)
    "Basic #{Base64.encode64("#{user_name}:")}"
  end

  setup do
    @mock = mock
    Payjp.mock_rest_client = @mock
    Payjp.api_key = "foo"
  end

  teardown do
    Payjp.mock_rest_client = nil
    Payjp.api_key = nil
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
payjp-0.0.3 test/test_helper.rb
payjp-0.0.2 test/test_helper.rb