Sha256: 3c8fe107a070fa573e37a16a418dfc07c43511ae135e3bf52196634ca7ade091

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

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

16 entries across 16 versions & 1 rubygems

Version Path
rspeckled-0.0.16 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.15 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.14 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.13 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.12 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.11 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.10 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.9 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.8 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.7 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.6 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.5 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.4 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.3 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.2 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
rspeckled-0.0.1 lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb