<commit_before>require 'spec_helper'

module Pacto
  describe UriPattern do
    context 'with non-strict matchers' do
      before(:each) do
        Pacto.configuration.strict_matchers = false
      end

      it 'returns a regex containing the host and path' do
        request = double(host: 'myhost.com', path: '/stuff')
        expect(UriPattern.for(request).to_s).to include('myhost\.com')
        expect(UriPattern.for(request).to_s).to include('\/stuff')
      end

      it 'turns segments preceded by : into wildcards' do
        request = double(host: 'myhost.com', path: '/:id')
        wildcard = '[^\/\?#]+'
        expect(UriPattern.for(request).to_s).to include(wildcard)
        expect(UriPattern.for(request).to_s).to_not include(':id')
      end

      it 'creates a regex that does not allow additional path elements' do
        request = double(host: 'myhost.com', path: '/:id')
        pattern = UriPattern.for(request)
        expect(pattern).to match('myhost.com/foo')
        expect(pattern).to_not match('myhost.com/foo/bar')
      end

      it 'creates a regex that does allow query parameters' do
        request = double(host: 'myhost.com', path: '/:id')
        pattern = UriPattern.for(request)
        expect(pattern).to match('myhost.com/foo?a')
        expect(pattern).to match('myhost.com/foo?a=b')
        expect(pattern).to match('myhost.com/foo?a=b&c=d')<commit_msg>Start of full support for uri templates<commit_after>require 'spec_helper'

module Pacto
  describe UriPattern do
    context 'with non-strict matchers' do
      before(:each) do
        Pacto.configuration.strict_matchers = false
      end

      it 'appends host if path is an Addressable::Template' do
        path_pattern = '/{account}/data{.format}{?page,per_page}'
        path = Addressable::Template.new path_pattern
        request = double(host: 'https://www.example.com', path: path)
        expect(UriPattern.for(request).pattern).to eq(Addressable::Template.new("https://www.example.com#{path_pattern}").pattern)
      end

      it 'returns a regex containing the host and path' do
        request = double(host: 'myhost.com', path: '/stuff')
        expect(UriPattern.for(request).to_s).to include('myhost\.com')
        expect(UriPattern.for(request).to_s).to include('\/stuff')
      end

      it 'turns segments preceded by : into wildcards' do
        request = double(host: 'myhost.com', path: '/:id')
        wildcard = '[^\/\?#]+'
        expect(UriPattern.for(request).to_s).to include(wildcard)
        expect(UriPattern.for(request).to_s).to_not include(':id')
      end

      it 'creates a regex that does not allow additional path elements' do
        request = double(host: 'myhost.com', path: '/:id')
        pattern = UriPattern.for(request)
        expect(pattern).to match('myhost.com/foo')
        expect(pattern).to_not match('myhost.com/foo/bar')
      end

      it 'creates a regex that does allow query parameters' do
        request = double(host: 'myhost.com', path: '/:id')
        pattern = UriPattern.for(request)
        expect(pattern).to match('myhost.com/foo?a')
        expect(pattern).to match('myhost.com/foo?a=b')
        expect(pattern).to match('myhost.com/foo?a=b&c=d')
{'fraction_non_alphanumeric': 0.13874264478166615, 'fraction_numerical': 0.0, 'mean_word_length': 2.9583333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7308407', 'n_tokens_mistral': 1008, 'n_tokens_neox': 982, 'n_words': 233}