Sha256: 43fd56847558319f4a0e725cccdf307225f9add36799f9b4ee0f918f880ef98f

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 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

2 entries across 2 versions & 1 rubygems

Version Path
sitehub-0.4.2 spec/sitehub/path_directives_spec.rb
sitehub-0.4.1 spec/sitehub/path_directives_spec.rb