Sha256: 92cb4a6ea9115ed18e13d3beb89e3d6d1ab10e8f52cdeca82d00b974f89bf369

Contents?: true

Size: 1.91 KB

Versions: 34

Compression:

Stored size: 1.91 KB

Contents

require "securerandom"

unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
  INTEGRATION_SPEC_HELPER_LOADED = true
  SSL_TEST_PORT = ENV['SSL_TEST_PORT'] || 8444

  require File.dirname(__FILE__) + "/../spec_helper"
  require File.dirname(__FILE__) + "/../hacks/tcp_socket"

  def start_ssl_server
    web_server_pid_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "httpsd.pid"))

    FileUtils.rm(web_server_pid_file) if File.exist?(web_server_pid_file)
    command = File.expand_path(File.join(File.dirname(__FILE__), "..", "script", "httpsd.rb"))
    `#{command} #{web_server_pid_file}`
    TCPSocket.wait_for_service :host => "127.0.0.1", :port => SSL_TEST_PORT

    yield

    10.times { unless File.exists?(web_server_pid_file); sleep 1; end }
  ensure
    Process.kill "INT", File.read(web_server_pid_file).to_i
  end

  def create_modification_for_tests(attributes)
    config = Braintree::Configuration.instantiate
    config.http.post("#{config.base_merchant_path}/modifications/create_modification_for_tests", :modification => attributes)
  end

  def with_other_merchant(merchant_id, public_key, private_key, &block)
    old_merchant_id = Braintree::Configuration.merchant_id
    old_public_key = Braintree::Configuration.public_key
    old_private_key = Braintree::Configuration.private_key

    Braintree::Configuration.merchant_id = merchant_id
    Braintree::Configuration.public_key = public_key
    Braintree::Configuration.private_key = private_key

    begin
      yield
    ensure
      Braintree::Configuration.merchant_id = old_merchant_id
      Braintree::Configuration.public_key = old_public_key
      Braintree::Configuration.private_key = old_private_key
    end
  end

  def with_altpay_merchant(&block)
    with_other_merchant("altpay_merchant", "altpay_merchant_public_key", "altpay_merchant_private_key", &block)
  end

  def random_payment_method_token
    "payment-method-token-#{SecureRandom.hex(6)}"
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
braintree-2.89.0 spec/integration/spec_helper.rb
braintree-2.88.0 spec/integration/spec_helper.rb
braintree-2.87.0 spec/integration/spec_helper.rb
braintree-2.86.0 spec/integration/spec_helper.rb
braintree-2.85.0 spec/integration/spec_helper.rb
braintree-2.84.0 spec/integration/spec_helper.rb
braintree-2.83.0 spec/integration/spec_helper.rb
braintree-2.82.0 spec/integration/spec_helper.rb
braintree-2.81.0 spec/integration/spec_helper.rb
braintree-2.80.1 spec/integration/spec_helper.rb
braintree-2.80.0 spec/integration/spec_helper.rb
braintree-2.79.0 spec/integration/spec_helper.rb
braintree-2.78.0 spec/integration/spec_helper.rb
braintree-2.77.0 spec/integration/spec_helper.rb
braintree-2.76.0 spec/integration/spec_helper.rb
braintree-2.75.0 spec/integration/spec_helper.rb
braintree-2.74.0 spec/integration/spec_helper.rb
braintree-2.73.0 spec/integration/spec_helper.rb
braintree-2.72.0 spec/integration/spec_helper.rb
braintree-2.71.0 spec/integration/spec_helper.rb