Sha256: 2aa46fdae6d28523a2be0de75fc2e7b088cd7ba5aa24c09ac8b41237b6b72a31

Contents?: true

Size: 1.93 KB

Versions: 8

Compression:

Stored size: 1.93 KB

Contents

require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

describe "symbol_matchers plugin" do 
  it "allows symbol specific regexps" do
    app(:bare) do
      plugin :symbol_matchers
      symbol_matcher(:f, /(f+)/)

      route do |r|
        r.is :d do |d|
          "d#{d}"
        end

        r.is "foo:optd" do |o|
          "foo#{o.inspect}"
        end

        r.is "bar:opt" do |o|
          "bar#{o.inspect}"
        end

        r.is "format:format" do |f|
          "format#{f.inspect}"
        end

        r.is "thing/:thing" do |d|
          "thing#{d}"
        end

        r.is "thing2", :thing do |d|
          "thing2#{d}"
        end

        r.is :f do |f|
          "f#{f}"
        end

        r.is 'q:rest' do |rest|
          "rest#{rest}"
        end

        r.is :w do |w|
          "w#{w}"
        end

        r.is ':d/:w/:f' do |d, w, f|
          "dwf#{d}#{w}#{f}"
        end
      end
    end

    status.must_equal 404
    body("/1").must_equal 'd1'
    body("/11232135").must_equal 'd11232135'
    body("/a").must_equal 'wa'
    body("/1az0").must_equal 'w1az0'
    body("/f").must_equal 'ff'
    body("/foo").must_equal 'foonil'
    body("/foo/123").must_equal 'foo"123"'
    status("/foo/bar").must_equal 404
    status("/foo/123/a").must_equal 404
    body("/bar").must_equal 'barnil'
    body("/bar/foo").must_equal 'bar"foo"'
    status("/bar/foo/baz").must_equal 404
    body("/format").must_equal 'formatnil'
    body("/format.json").must_equal 'format"json"'
    status("/format.").must_equal 404
    body("/ffffffffffffffff").must_equal 'fffffffffffffffff'
    status("/-").must_equal 404
    body("/1/1a/f").must_equal 'dwf11af'
    body("/12/1azy/fffff").must_equal 'dwf121azyfffff'
    status("/1/f/a").must_equal 404
    body("/qa/b/c/d//f/g").must_equal 'resta/b/c/d//f/g'
    body('/q').must_equal 'rest'
    body('/thing/q').must_equal 'thingq'
    body('/thing2/q').must_equal 'thing2q'
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
roda-2.21.0 spec/plugin/symbol_matchers_spec.rb
roda-2.20.0 spec/plugin/symbol_matchers_spec.rb
roda-2.19.0 spec/plugin/symbol_matchers_spec.rb
roda-2.18.0 spec/plugin/symbol_matchers_spec.rb
roda-2.17.0 spec/plugin/symbol_matchers_spec.rb
roda-2.16.0 spec/plugin/symbol_matchers_spec.rb
roda-2.15.0 spec/plugin/symbol_matchers_spec.rb
roda-2.14.0 spec/plugin/symbol_matchers_spec.rb