Sha256: c520e7f350754c7143a733c29bf4667f43eb4dfe5ba4b69185a9567a56a37e08

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'vcr'
require 'webmock'

VCR.configure do |c|
  c.cassette_library_dir = "spec/fixtures/cassettes"
  c.hook_into :webmock
  c.configure_rspec_metadata!
  c.default_cassette_options = {
    match_requests_on: [:method, :uri, :body]
  }
  c.allow_http_connections_when_no_cassette = false
  c.ignore_localhost = true
  c.ignore_hosts 'chromedriver.storage.googleapis.com'

  # client token used for the fronted JS lib cannot be mocked:
  # it contains a cryptographically signed string containing the merchant id
  # that's sent back to braintree's server by the JS lib
  c.ignore_request do |request|
    !(request.uri =~ %r{/merchants/\w+/client_token\z}).nil?
  end

  # match a request to Braintree sandbox APIs by ignoring the merchant ID
  # in the request URI
  c.register_request_matcher :braintree_uri do |request1, request2|
    extract_url_resource = lambda do |uri|
      uri_match_pattern =
        %r{\Ahttps://api\.sandbox\.braintreegateway\.com/merchants/\w+(/.*)\z}

      if match = uri.match(uri_match_pattern)
        match.captures.first
      end
    end
    r1_resource = extract_url_resource.call(request1.uri)
    r2_resource = extract_url_resource.call(request2.uri)

    !r1_resource.nil? && r1_resource == r2_resource
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_braintree-3.3.0 spec/support/solidus_braintree/vcr.rb
solidus_braintree-3.2.0 spec/support/solidus_braintree/vcr.rb
solidus_braintree-3.1.0 spec/support/solidus_braintree/vcr.rb