Sha256: b3b2ea970bc2a452c457dbbb27c7e8c938c3e67ca396d6440cac6413bb45e6e4

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'sitehub/path_directives'
class SiteHub
  describe PathDirectives do
    it 'is an array' do
      expect(subject).to be_kind_of(Array)
    end

    describe '#initialize' do
      context 'hash key is a regexp' do
        it 'leaves the key has a regexp' do
          key = %r{/.*/}
          value = '/'
          expect(described_class.new(key => value)).to eq([PathDirective.new(key, value)])
        end
      end

      context 'hash key is a string' do
        it 'converts the key to a regexp' do
          key = 'string'
          value = '/'
          expect(described_class.new(key => value)).to eq([PathDirective.new(Regexp.new(key), value)])
        end
      end
    end

    describe '#find' do
      let(:matcher) { Regexp.new('/orders/(.*)') }
      let(:path_template) { '/orders/$1' }
      subject do
        described_class.new(matcher => path_template)
      end
      context 'url matches matcher' do
        it 'returns the path directive' do
          expect(subject.find('http://url.com/orders/123')).to eq(PathDirective.new(matcher, path_template))
        end
      end
      context 'url does not matches matcher' do
        it 'returns nil' do
          expect(subject.find('http://url.com/mismatch')).to eq(nil)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sitehub-0.4.3 spec/sitehub/path_directives_spec.rb