Sha256: 57fdca6dc8d7c63670a850ed44503abd3bfd4d69d834f0fbb8291575419115c5

Contents?: true

Size: 1.3 KB

Versions: 38

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module  Rspeckled
module  VcrMatchers
class   UriWithoutTrailingId
  attr_accessor :trailing_id_matcher

  def initialize(trailing_id_matcher)
    self.trailing_id_matcher = trailing_id_matcher
  end

  def call(request, vcr_cassette_request)
    request_uri              = request.uri
    vcr_cassette_request_uri = vcr_cassette_request.uri

    if request_uri.match?(trailing_id_matcher)
      request_uri_without_id              = request_uri.sub              trailing_id_matcher, ''
      vcr_cassette_request_uri_without_id = vcr_cassette_request_uri.sub trailing_id_matcher, ''

      request_uri.match(trailing_id_matcher) &&
      vcr_cassette_request_uri.match(trailing_id_matcher) &&
      request_uri_without_id == vcr_cassette_request_uri_without_id
    else
      request_uri == vcr_cassette_request_uri
    end
  end
end
end
end

VCR.configure do |config|
  config.register_request_matcher :uri_without_trailing_guid do |request, vcr_cassette_request|
    Rspeckled::VcrMatchers::UriWithoutTrailingId.new(%r(/[a-f0-9\-]{32,36}/?\z)).call(request, vcr_cassette_request)
  end

  config.register_request_matcher :uri_without_trailing_id do |request, vcr_cassette_request|
    Rspeckled::VcrMatchers::UriWithoutTrailingId.new(%r{/\d+/?\z}).call(request, vcr_cassette_request)
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
rspeckled-1.0.3 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-1.0.2 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-1.0.1 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-1.0.0 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.64 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.63 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.62 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.61 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.60 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.59 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.58 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.57 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.56 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.55 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.54 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.53 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.52 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.51 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.50 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.49 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb