|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe Grape::Router::Route do |
| 4 | + let(:instance) { described_class.new(endpoint, :get, pattern, options, forward_match:) } |
| 5 | + let(:endpoint) { instance_double(Grape::Endpoint) } |
| 6 | + let(:options) { {} } |
| 7 | + let(:pattern) do |
| 8 | + Grape::Router::Pattern.new( |
| 9 | + origin: '/mounty', |
| 10 | + suffix: '', |
| 11 | + anchor: true, |
| 12 | + params: {}, |
| 13 | + format: nil, |
| 14 | + version: nil, |
| 15 | + requirements: {} |
| 16 | + ) |
| 17 | + end |
| 18 | + |
| 19 | + describe 'inheritance' do |
| 20 | + subject { described_class.new(endpoint, :get, pattern, options, forward_match: false) } |
| 21 | + |
| 22 | + it { is_expected.to be_a(Grape::Router::BaseRoute) } |
| 23 | + end |
| 24 | + |
| 25 | + describe '#match?' do |
| 26 | + subject { instance.match?(input) } |
| 27 | + |
| 28 | + context 'when forward_match is true' do |
| 29 | + let(:forward_match) { true } |
| 30 | + |
| 31 | + context 'with the exact origin' do |
| 32 | + let(:input) { '/mounty' } |
| 33 | + |
| 34 | + it { is_expected.to be_truthy } |
| 35 | + end |
| 36 | + |
| 37 | + context 'with a subpath under the origin' do |
| 38 | + let(:input) { '/mounty/awesome/deep' } |
| 39 | + |
| 40 | + it 'matches on the origin prefix' do |
| 41 | + expect(subject).to be_truthy |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context 'with a path outside the origin' do |
| 46 | + let(:input) { '/other' } |
| 47 | + |
| 48 | + it { is_expected.to be_falsey } |
| 49 | + end |
| 50 | + |
| 51 | + context 'with a blank input' do |
| 52 | + let(:input) { '' } |
| 53 | + |
| 54 | + it { is_expected.to be(false) } |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context 'when forward_match is false' do |
| 59 | + let(:forward_match) { false } |
| 60 | + |
| 61 | + context 'with the exact origin' do |
| 62 | + let(:input) { '/mounty' } |
| 63 | + |
| 64 | + it { is_expected.to be_truthy } |
| 65 | + end |
| 66 | + |
| 67 | + context 'with a subpath under the origin' do |
| 68 | + let(:input) { '/mounty/awesome/deep' } |
| 69 | + |
| 70 | + it 'does not match beyond the anchored pattern' do |
| 71 | + expect(subject).to be_falsey |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context 'with a blank input' do |
| 76 | + let(:input) { '' } |
| 77 | + |
| 78 | + it { is_expected.to be(false) } |
| 79 | + end |
| 80 | + end |
| 81 | + end |
| 82 | +end |
0 commit comments