Sha256: 1b80b5ecacfd4b52dad36398ebc4d1f605ac174e1c1d684cee8516572fa90b75

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

require 'sitehub/path_directive'
class SiteHub
  describe PathDirective do

    subject do
      described_class.new(%r{/match}, '/path_template')
    end

    describe '#match?' do

      context 'matcher applies' do
        it 'returns true' do
          expect(subject.match?('/match')).to eq(true)
        end
      end

      context 'matcher does not apply' do
        it 'returns false' do
          expect(subject.match?('/mismatch')).to eq(false)
        end
      end
    end

    describe '#apply' do
      subject do
        described_class.new(Regexp.new('http://www.upstream.com/orders/(.*)'), '/$1')
      end

      let(:url){'http://www.upstream.com/orders/123'}

      it 'uses the url to populate the path template' do
        expect(subject.apply(url)).to eq('/123')
      end

      it 'retains the query string' do
        expect(subject.apply("#{url}?param=value")).to eq('/123?param=value')
      end
    end

    describe '#path_template' do
      it 'returns a duplicate of the path_template every time' do
        version1, version2 = subject.path_template, subject.path_template
        expect(version1).to eq(version2)
        expect(version1).to_not be(version2)
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

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